Tags:
create new tag
view all tags

LCFG systemd - a first stab

Thoughts

* Do we maintain /etc/systemd or just /etc/systemd/system?

    • Initially the latter, but ultimately both

  • /etc/systemd/system/*.* - unit files. Files may be links to /lib/systemd
  • /etc/systemd/system/{unit}.wants - directory of unit files wanted by {unit}. Files may be links to /lib/systemd/
  • /etc/systemd/system/{unit}.d - directory of .conf override config files

  • can have both an nfs.service and an nfs.socket
  • might have a .wants directory, but no unit file
  • a unit file can be a conf file (which we wish to generate) or a link to /usr/lib/systemd/system
  • a unit can be under multiple .wants directories (but presumably must link to same file?)
  • we have a bunch of links and config files
  • each can be either at top or within multiple wants directories
  • Note that following scheme won't allow a unit to be both in toplevel and in a wants - would you want this? Haven't seen this in practice in F19 nor F20.
  • Adding a new unit config file and triggering a systemd reload does not result in the new unit being started
  • For triggering reboots
    • can't see a way to say "I'm the last unit for a specific target"
    • we could have our own local "lcfg-multi-user.target" and "lcfg-graphical.target" which depend on the stock "multi-user.target" and "graphical.target" respectively. The default.target would be set to one of these local targets. The local targets will be provided by a OneStop unit which checks for any requested reboots (from earlier units) and reboots if necessary.
  • Rather than having two structures - one for units at top level and one for units within *.wants directory -  have all units in one systemd.units list. An attribute of a unit is whether it should be in 0 or more *.wants directories (default would be top dir). 
  • How display component start up success/failure at boot time?

Some example resources

systemd.libdir  /usr/lib/systemd/system

systemd.units dbusbluez dbusfw dbusavahi dbusmodem dbusnetworkmgr dbusnmdispat default displaymanager syslog


systemd.type_dbusbluez    link  
systemd.realname_dbusbluez   dbus-org.bluez.service
systemd.link_dbusbluez       bluetooth.service
systemd.wantedby_dbusbluez  

creates a softlink /etc/systemd/system/dbus-org.bluez.service -> /usr/lib/systemd/system/bluetooth.service

Note that an empty value for systemd.wantedby_{tag} indicates that the link should be created in the top-level directory.


systemd.realname_dbusfw      dbus-org.fedoraproject.FirewallD1.service
systemd.link_dbusfw          firewalld.service

creates a softlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service

(Note that systemd.type_{tag} defaults to link, so not defined above)


systemd.realname_default      default.target
systemd.link_default          graphical.target

Creates softlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target


!systemd.units mADD(sshd)
systemd.realname_sshd         sshd.service
systemd.wantedby_sshd         multi-user.target

Creates a softlink /etc/systemd/system/multi-user.target.wants/sshd.service -> /usr/lib/systemd/system/sshd.service

Note that systemd.link_{tag} defaults to systemd.realname_{tag} if not defined.


!systemd.units                 mADD(sshdconfig)
systemd.type_sshdconfig     file
systemd.realname_sshdconfig    sshd-local-config.service
systemd.wantedby_sshdconfig    sshd.service

systemd.description_sshdconfig   OpenSSH localconfig
systemd.unittype_sshdconfig      service
systemd.before_sshdconfig        sshd.service
systemd.execstart_sshdconfig     /usr/local/bin/sshd-local-config
systemd.servicetype_sshdconfig   oneshot

Creates a file /etc/systemd/system/sshd.service.wants/sshd-local-config.service with the content :-

[Unit]
Description=OpenSSH localconfig
Before=sshd.service

[Service]
ExecStart=/usr/local/bin/sshd-local-config
Type=oneshot


There are far too many unit options to support, so propose adding resources for most commonly used options and allowing additional lines using something like the following.

!systemd.units                 mADD(sshdconfig)
systemd.type_sshdconfig         file
systemd.realname_sshdconfig    sshd-local-config.service
systemd.wantedby_sshdconfig    sshd.service

systemd.description_sshdconfig   OpenSSH localconfig
systemd.unittype_sshdconfig      service  
systemd.before_sshdconfig        sshd.service  
systemd.conflicts_sshdconfig     sshd-nextgen    
systemd.genopts_sshdconfig       unneeded
systemd.genopt_sshdconfig_unneeded  StopWhenUnneeded=0
systemd.execstart_sshdconfig     /usr/local/bin/sshd-local-config
systemd.servicetype_sshdconfig   oneshot
systemd.specopts_sshdconfig         restart
systemd.specopt_sshdconfig_restart  Restart=on-failure

Creates a file /etc/systemd/system/sshd.service.wants/sshd-local-config with the following content :-

[Unit]
Description=OpenSSH localconfig
Before=sshd.service
Conflicts=sshd-nextgen
StopWhenUnneeded=0

[Service]
Type=oneshot
ExecStart=/usr/local/bin/sshd-local-config
Restart=on-failure

Note that the taglist systemd.genopts_{tag} is used for defining additional resources for the general [Unit] section, and the taglist systemd.specopts_{tag} is used for defining additional resources for the unit specific section (in this case [Service] as defined by systemd.unittype_{tag}).


.conf override files

systemd.overrides            sshdexec
systemd.configunit_sshdexec  sshd.service
systemd.lines_sshdexec       1 2 3 
systemd.line_sshdexec_1      [Service]
systemd.line_sshdexec_2      Execstart=
systemd.line_sshdexec_3      Execstart=/usr/local/bin/sshd -d

Would create /etc/systemd/system/sshd.service.d/sshdexec.conf with contents :-

[Service]
Execstart=
Execstart=/usr/local/bin/sshd -d


LCFG CPP macros

The macro below wraps up some of the above :-

#define LCFG_SYSTEMD_UNIT(TAG,RN,LINK,WANT) \
!systemd.units  mADD(TAG)˘\
systemd.realname_/**/TAG        RN˘\
systemd.link_/**/TAG    LINK˘\
!systemd.wantedby_/**/TAG       mADD(WANT)

eg :- LCFG_SYSTEMD_UNIT(default,default.target,multi-user.target,)

LCFG schema

@units type_$ realname_$ link_$ wantedby_$ requiredby_$ description_$ unittype_$ before_$ after_$ \
       conflicts_$ requires_$ execstart_$ execrestart_$ execreload_$ execstop_$ servicetype_$ \
       environmentfile_$ standardout_$ standarderr_$ busname_$ genopts_$ specopts_$
units
@type_$ %string(type): vENUM(link file)
type_$ link
realname_$
link_$
wantedby_$
requiredby_$
description_$
unittype_$
before_$
after_$
conflicts_$
requires_$
execstart_$
execrestart_$
execreload_$
execstop_$
servicetype_$
environmentfile_$
standardout_$
standarderr_$
busname_$

@genopts_$  genopt_$_$
genopts_$
genopt_$_$

@specopts_$ specopt_$_$
specopts_$
specopt_$_$

@extraconfigs extraunit_$ extralines_$
extraconfigs
extraunit_$
@extralines_$ extraline_$_$
extralines_$
extraline_$_$

-- Main.ascobie - 2014-02-18

Topic revision: r9 - 2014-08-19 - ascobie
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback