Xenial changes

This commit is contained in:
Ian Gulliver
2016-07-18 18:40:07 +00:00
parent e65035d230
commit 95315dfa77
3 changed files with 41 additions and 43 deletions

View File

@@ -73,3 +73,10 @@ class IconModule(object):
with open(os.path.join(self._chroot_path, 'etc', 'modules'), 'a') as fh: with open(os.path.join(self._chroot_path, 'etc', 'modules'), 'a') as fh:
for module in modules: for module in modules:
fh.write('%s\n' % module) fh.write('%s\n' % module)
def ServiceFile(self, service):
path = os.path.join(self._chroot_path, 'lib', 'systemd', 'system', service)
return open(path, 'w')
def EnableService(self, service):
self.ExecChroot('systemctl', 'enable', service)

View File

@@ -3,6 +3,8 @@
import argparse import argparse
import os import os
import icon_lib
parser = argparse.ArgumentParser(description='iconograph persistent') parser = argparse.ArgumentParser(description='iconograph persistent')
parser.add_argument( parser.add_argument(
@@ -14,24 +16,40 @@ FLAGS = parser.parse_args()
def main(): def main():
module = icon_lib.IconModule(FLAGS.chroot_path)
os.mkdir(os.path.join(FLAGS.chroot_path, 'persistent')) os.mkdir(os.path.join(FLAGS.chroot_path, 'persistent'))
init = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'persistent.conf') tool_path = os.path.join(FLAGS.chroot_path, 'icon', 'persistent')
with open(init, 'w') as fh: os.makedirs(tool_path, exist_ok=True)
fh.write("""
description "Mount /persistent"
start on filesystem script = os.path.join(tool_path, 'startup.sh')
task with open(script, 'w') as fh:
os.chmod(fh.fileno(), 0o755)
emits persistent-ready fh.write("""\
#!/bin/bash
script mount -o data=journal,noatime,sync LABEL=PERSISTENT /persistent
mount -o data=journal,noatime,sync LABEL=PERSISTENT /persistent
initctl emit --no-wait persistent-ready
end script
""") """)
with module.ServiceFile('persistent.service') as fh:
fh.write("""
[Unit]
Description=Mount /persistent
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=sysinit.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/icon/persistent/startup.sh
[Install]
WantedBy=sysinit.target
""")
module.EnableService('persistent.service')
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -35,24 +35,7 @@ hostname --file /etc/hostname
grep ${SYSTEMID} /etc/hosts >/dev/null || echo "127.0.2.1 ${SYSTEMID}" >> /etc/hosts grep ${SYSTEMID} /etc/hosts >/dev/null || echo "127.0.2.1 ${SYSTEMID}" >> /etc/hosts
""") """)
upstart = os.path.join(FLAGS.chroot_path, 'etc', 'init', 'systemid.conf') with module.ServiceFile('systemid.service') as fh:
with open(upstart, 'w') as fh:
fh.write("""
description "Mount /systemid"
start on filesystem
task
emits systemid-ready
script
/icon/systemid/startup.sh
initctl emit --no-wait systemid-ready
end script
""")
systemd = os.path.join(FLAGS.chroot_path, 'lib', 'systemd', 'system', 'systemid.service')
with open(systemd, 'w') as fh:
fh.write(""" fh.write("""
[Unit] [Unit]
Description=Mount /systemid and configure from it Description=Mount /systemid and configure from it
@@ -69,18 +52,8 @@ ExecStart=/icon/systemid/startup.sh
[Install] [Install]
WantedBy=sysinit.target WantedBy=sysinit.target
""") """)
try: module.EnableService('systemid.service')
module.ExecChroot(
'systemctl',
'unmask',
'systemid.service')
module.ExecChroot(
'systemctl',
'enable',
'systemid.service')
except icon_lib.SubprocessFailure:
# trusty backwards-compat
pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()