[systemd-devel] Special targets - should they Want or be WantedBy?

Andrey Borzenkov arvidjaar at mail.ru
Sat Mar 12 03:12:21 PST 2011


On Sat, Mar 12, 2011 at 1:00 PM, Andrey Borzenkov <arvidjaar at mail.ru> wrote:
> On Sat, Mar 12, 2011 at 3:14 AM, Michael Biebl <mbiebl at gmail.com> wrote:
>> 2011/3/12 Michael Biebl <mbiebl at gmail.com>:
>>> 2011/3/11 Andrey Borzenkov <arvidjaar at mail.ru>:
>>>> On Fri, Mar 11, 2011 at 9:10 PM, Mike Kazantsev <mk.fraggod at gmail.com> wrote:
>>>
>>>>
>>>>> Btw, rsyslog.service seem to be installed into multi-user.target.wants,
>>>>> why not syslog.target, which seem to indicate the point where proper
>>>>> syslog daemon is running (according to systemd.special(7))?
>>>>>
>>>>
>>>> Actually good question (same as for portmap) - who should pull in
>>>> syslog.target then?
>>>
>>> Yeah, I noticed this myself already. Quite a bit of syslog output
>>> ended up in /proc/kmsg during boot because rsyslog was started rather
>>> late (via multi-user.target).
>>> Afaics, there is not explicit symlink pulling in syslog.target, so I
>>> assume it is handled internally by systemd. Lennart?
>>
>> Turns out, that indeed syslog.target is not automatically started.
>> I symlinked syslog.target into multi-user.target.wants and
>> rsyslog.service into syslog.target.wants.
>>
>> Now all services with After=syslog.target are correctly started after
>> rsyslog.service.
>>
>> Lennart, I think we should add those changes to systemd and rsyslog.service.
>>
>
> The problem is not limited to syslog and applies to all special
> targets that serve as "virtual provides"
>
> Actually I think design should be reversed. The service that
> implements this virtual provide (syslog, network, rpcbind, smtp, ...)
> should pull in special target. This way you ensure
>
> - when service that provides functionality is started, corresponding
> virtual target is started as indication, that functionality is
> available
>
> - if there is no service with requested functionality, target is not
> available. In other words - target is not faked to be started unless
> functionality is available. This allows easy and logical check,
> whether syslog (rpcbind, network, ...) was really provided by any
> service - if unit is not started, it was not. To round this off,
> specials should also refuse manual activation.
>
> That does not apply to all specials; some of them do serve as "virtual
> requires" and pull in other services on demand. Think about
> bluetooth.target. Although (as Lennart replied regarding network) it
> should probably in reality be hci.tagret (or more generically -
> bt-device.target) rather than bluetooth.service, as it is exactly what
> we want to *pull* - specific driver for BT device. Which - in turn
> should pull in bluetooth.target as indication that BT is now
> available.
>
> Specials should really be generic statement "this functionality is now
> available". Not means to achieve this functionality.
>

Here is proof of concept patch. Notice that nfs fails utterly because
it is started before rpc is ready without this patch (and yes, I know
about socket activation for rpcbind, It is not the point here).
rpcbind part is fixed by src/service.c patch. syslog part is fixed by
addin Wants=syslog.target to rsyslog.service.

Before

[root at localhost ~]# systemctl --no-pager -p After -p Before -p Wants
-p WantedBy -p Id show syslog.target rsyslog.service rpcbind.service
rpcbind.target
Id=syslog.target
Wants=
WantedBy=
Before=dbus.service prefdm.service networkmanager.service
acpid.service crond.service shorewall.service
console-kit-daemon.service
After=syslog.socket rsyslog.service

Id=rsyslog.service
Wants=
WantedBy=multi-user.target
Before=syslog.target shutdown.target
After=local-fs.target basic.target

Id=rpcbind.service
Wants=
WantedBy=rpcbind.target multi-user.target graphical.target
Before=rpcbind.target shutdown.target multi-user.target graphical.target
After=network.target basic.target

Id=rpcbind.target
Wants=rpcbind.service
WantedBy=
Before=netfs.service nfs-common.service
After=rpcbind.service
[root at localhost ~]# systemctl status syslog.target rsyslog.service
rpcbind.service rpcbind.target
syslog.target - Syslog
          Loaded: loaded (/lib/systemd/system/syslog.target)
          Active: inactive (dead)

rsyslog.service - System Logging Service
          Loaded: loaded (/lib/systemd/system/rsyslog.service)
          Active: active (running) since Sat, 12 Mar 2011 13:59:24
+0300; 1min 14s ago
         Process: 797 ExecStartPre=/bin/systemctl stop
systemd-kmsg-syslogd.service (code=exited, status=0/SUCCESS)
        Main PID: 856 (rsyslogd)
          CGroup: name=systemd:/system/rsyslog.service
                  └ 856 /sbin/rsyslogd -n -c 4

rpcbind.service - LSB: Start the rpcbind daemon
          Loaded: loaded (/etc/rc.d/init.d/rpcbind)
          Active: active (running) since Sat, 12 Mar 2011 13:59:30
+0300; 1min 8s ago
         Process: 1474 ExecStart=/etc/rc.d/init.d/rpcbind start
(code=exited, status=0/SUCCESS)
        Main PID: 1499 (rpcbind)
          CGroup: name=systemd:/system/rpcbind.service
                  └ 1499 rpcbind -i

rpcbind.target - RPC Port Mapper
          Loaded: loaded (/lib/systemd/system/rpcbind.target)
          Active: inactive (dead)
[root at localhost ~]# systemd-cgls /system/nfs-common.service
/system/nfs-common.service:
Failed to list cgroup tree: No such file or directory
[root at localhost ~]# systemd-cgls /system/nfs-server.service
/system/nfs-server.service:
Failed to list cgroup tree: No such file or directory
[root at localhost ~]# systemd-cgls /system/nfs-common.service rpcbind.target^C
[root at localhost ~]# systemctl status nfs-server.service
nfs-common.servicenfs-server.service - LSB: Kernel NFS server support
          Loaded: loaded (/etc/rc.d/init.d/nfs-server)
          Active: active (exited) since Sat, 12 Mar 2011 13:59:26
+0300; 2min 12s ago
         Process: 920 ExecStart=/etc/rc.d/init.d/nfs-server start
(code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/nfs-server.service

nfs-common.service - LSB: NFS support files common to client and server
          Loaded: loaded (/etc/rc.d/init.d/nfs-common)
          Active: active (exited) since Sat, 12 Mar 2011 13:59:24
+0300; 2min 13s ago
         Process: 794 ExecStart=/etc/rc.d/init.d/nfs-common start
(code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/nfs-common.service


After:

[root at localhost ~]# systemctl --no-pager -p After -p Before -p Wants
-p WantedBy -p Id show syslog.target rsyslog.service rpcbind.service
rpcbind.target
Id=syslog.target
Wants=
WantedBy=rsyslog.service
Before=dbus.service prefdm.service networkmanager.service
acpid.service crond.service shorewall.service
console-kit-daemon.service
After=syslog.socket rsyslog.service

Id=rsyslog.service
Wants=syslog.target
WantedBy=multi-user.target
Before=syslog.target shutdown.target
After=local-fs.target basic.target

Id=rpcbind.service
Wants=rpcbind.target
WantedBy=rpcbind.target multi-user.target graphical.target
Before=rpcbind.target shutdown.target multi-user.target graphical.target
After=network.target basic.target

Id=rpcbind.target
Wants=rpcbind.service
WantedBy=rpcbind.service
Before=netfs.service nfs-common.service
After=rpcbind.service
root at localhost ~]# systemctl status syslog.target rsyslog.service
rpcbind.service rpcbind.target
syslog.target - Syslog
          Loaded: loaded (/lib/systemd/system/syslog.target)
          Active: active since Sat, 12 Mar 2011 13:48:53 +0300; 4min 33s ago

rsyslog.service - System Logging Service
          Loaded: loaded (/etc/systemd/system/rsyslog.service)
          Active: active (running) since Sat, 12 Mar 2011 13:48:53
+0300; 4min 33s ago
         Process: 795 ExecStartPre=/bin/systemctl stop
systemd-kmsg-syslogd.service (code=exited, status=0/SUCCESS)
        Main PID: 834 (rsyslogd)
          CGroup: name=systemd:/system/rsyslog.service
                  └ 834 /sbin/rsyslogd -n -c 4

rpcbind.service - LSB: Start the rpcbind daemon
          Loaded: loaded (/etc/rc.d/init.d/rpcbind)
          Active: active (running) since Sat, 12 Mar 2011 13:48:59
+0300; 4min 28s ago
         Process: 1430 ExecStart=/etc/rc.d/init.d/rpcbind start
(code=exited, status=0/SUCCESS)
        Main PID: 1441 (rpcbind)
          CGroup: name=systemd:/system/rpcbind.service
                  └ 1441 rpcbind -i

rpcbind.target - RPC Port Mapper
          Loaded: loaded (/lib/systemd/system/rpcbind.target)
          Active: active since Sat, 12 Mar 2011 13:48:59 +0300; 4min 28s ago

[root at localhost ~]# systemd-cgls /system/nfs-common.service
/system/nfs-common.service:
├ 1463 rpc.statd
└ 1479 rpc.idmapd
[root at localhost ~]# systemd-cgls /system/nfs-server.service
/system/nfs-server.service:
└ 1577 rpc.mountd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: special-targets.patch
Type: text/x-patch
Size: 5429 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20110312/5e2e9671/attachment-0001.bin>


More information about the systemd-devel mailing list