[systemd-devel] Problems trying to convert a System-V-Init script to systemd

Mantas Mikulėnas grawity at gmail.com
Fri Jul 15 10:51:59 UTC 2016


On Thu, Jul 14, 2016 at 3:34 PM, Holger Kiehl <Holger.Kiehl at dwd.de> wrote:

> Hello,
>
> I am new to systemd and the maintainer of the file distribution software
> AFD (http://www.dwd.de/AFD) and I am trying to adapt this application
> to systemd. The problem I am unable to solve is that doing a reboot,
> poweroff or halt, all process get a SIGTERM before systemd calls the
> command supplied by ExecStop. If I do a 'systemctl stop afd.service'
> everything works as expected. I have searched the web for a solution
> and have tried all the different service Type=, unit After=/Before=
> combination, but failed so far. I must be doing something obviously
> wrong, but unable to see what and need help please.
>
> The service/unit file looks as follows:
>
>    [Unit]
>    Description=Automatic File Distributor
>    After=basic.target
>
>    [Service]
>    RemainAfterExit=yes
>    Type=oneshot
>    ExecStart=-/etc/init.d/afd start
>    ExecStop=-/etc/init.d/afd stop
>    KillMode=none
>    StandardOutput=syslog+console
>    StandardError=syslog+console
>
>    [Install]
>    WantedBy=multi-user.target
>
> /etc/init.d/afd is a shell script that starts one or more instances of
> the AFD under different users. The users are configured in
> /etc/sysconfig/afd
> and are started via the following command: su - $afduser -c "<cmd
> start/sop AFD>"
> To speed things up a bit the script forks for each user to start/stop the
> AFD instances. The script /etc/init.d/afd is just initiating thinks, but
> always waits for the command to complete. AFD itself has an init process
> (init_afd) that then starts several other process and monitors them.
>

It's possible that `su` moves its children to a different cgroup, making
them no longer technically part of the service, but rather part of a user
session.

Check whether `systemctl status afd` actually shows your sub-daemons while
they're running... (Other useful tools are `systemd-cgls` or `ps axfo
pid,user,unit,cmd`.) If that's the problem, try using `runuser -u $afduser
…` instead.

Better yet, forget init.d and create a native afd at .service, with one
instance per user (afd at user1, afd at user2, etc.), each instance running
*exactly one* daemon.

-- 
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160715/68a653fd/attachment-0001.html>


More information about the systemd-devel mailing list