add 'systemctl' command and use it in postinstall

The 'systemctl' command can be used to enable, disable, or mask systemd
units inside the runtime being modified. Modify runtime-postinstall.tmpl
to use the 'systemctl' command.

We also no longer remove quota*.service or kexec*.service, since
these aren't enabled by default. And systemd-remount-api-vfs.service
should work correctly now, so we can leave it alone as well.
This commit is contained in:
Will Woods 2012-06-19 15:14:27 -04:00
parent 8d49fcdc24
commit 3a75b2e07d
2 changed files with 39 additions and 11 deletions

View File

@ -20,18 +20,24 @@ move etc/yum.repos.d etc/anaconda.repos.d
## Configure systemd to start anaconda
remove etc/systemd/system/default.target
remove etc/systemd/system/default.target.wants/*
symlink /lib/systemd/system/anaconda.target etc/systemd/system/default.target
## remove/disable unwanted systemd services
removefrom systemd /usr/lib/systemd/system/kexec*
removefrom systemd /usr/lib/systemd/system/local-fs.target.wants/media.mount
removefrom systemd /usr/lib/systemd/system/media.mount
removefrom systemd /usr/lib/systemd/system/*plymouth*
removefrom systemd /usr/lib/systemd/system/quota*.service
removefrom systemd /usr/lib/systemd/system/systemd-remount-api-vfs.service
removefrom initscripts */lib/systemd/system/local-fs.target.wants/fedora-storage*.service */lib/systemd/system/basic.target.wants/*.service
removefrom lvm2 */lib/systemd/system/*
removefrom mdadm */lib/systemd/system/*
## Disable unwanted systemd services
systemctl disable systemd-readahead-collect.service \
systemd-readahead-replay.service \
mdmonitor.service \
mdmonitor-takeover.service \
lvm2-monitor.service
## These services can't be disabled normally (they're linked into place in
## /usr/lib/systemd rather than /etc/systemd), so we have to mask them.
systemctl mask fedora-configure.service fedora-loadmodules.service \
fedora-storage-init.service fedora-storage-init-late.service \
fedora-autorelabel.service fedora-autorelabel-mark.service \
fedora-wait-storage.service media.mount \
plymouth-quit.service plymouth-quit-wait.service \
plymouth-kexec.service plymouth-halt.service \
plymouth-poweroff.service plymouth-reboot.service \
plymouth-read-write.service plymouth-start.service
## install some basic configuration files
append etc/resolv.conf ""

View File

@ -531,3 +531,25 @@ class LoraxTemplateRunner(object):
addrsize_data = struct.pack(">iiii", 0, int(addr, 16), 0, os.stat(src).st_size)
addrsize.write(addrsize_data)
addrsize.close()
def systemctl(self, cmd, *units):
'''
systemctl [enable|disable|mask] UNIT [UNIT...]
Enable, disable, or mask the given systemd units.
Examples:
systemctl disable lvm2-monitor.service
systemctl mask fedora-storage-init.service fedora-configure.service
'''
if cmd not in ('enable', 'disable', 'mask'):
raise ValueError('unsupported systemctl cmd: %s' % cmd)
if not units:
logger.debug("systemctl: no units given for %s, ignoring", cmd)
return
self.mkdir("/run/systemd/system") # XXX workaround for systemctl bug
systemctl = ('systemctl', '--root', self.outroot, '--no-reload',
'--quiet', cmd)
# XXX for some reason 'systemctl enable/disable' always returns 1
try:
check_call(systemctl + units)
except CalledProcessError:
pass