<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 14, 2016 at 3:34 PM, Holger Kiehl <span dir="ltr"><<a href="mailto:Holger.Kiehl@dwd.de" target="_blank">Holger.Kiehl@dwd.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am new to systemd and the maintainer of the file distribution software<br>
AFD (<a href="http://www.dwd.de/AFD" rel="noreferrer" target="_blank">http://www.dwd.de/AFD</a>) and I am trying to adapt this application<br>
to systemd. The problem I am unable to solve is that doing a reboot,<br>
poweroff or halt, all process get a SIGTERM before systemd calls the<br>
command supplied by ExecStop. If I do a 'systemctl stop afd.service'<br>
everything works as expected. I have searched the web for a solution<br>
and have tried all the different service Type=, unit After=/Before=<br>
combination, but failed so far. I must be doing something obviously<br>
wrong, but unable to see what and need help please.<br>
<br>
The service/unit file looks as follows:<br>
<br>
   [Unit]<br>
   Description=Automatic File Distributor<br>
   After=basic.target<br>
<br>
   [Service]<br>
   RemainAfterExit=yes<br>
   Type=oneshot<br>
   ExecStart=-/etc/init.d/afd start<br>
   ExecStop=-/etc/init.d/afd stop<br>
   KillMode=none<br>
   StandardOutput=syslog+console<br>
   StandardError=syslog+console<br>
<br>
   [Install]<br>
   WantedBy=multi-user.target<br>
<br>
/etc/init.d/afd is a shell script that starts one or more instances of<br>
the AFD under different users. The users are configured in /etc/sysconfig/afd<br>
and are started via the following command: su - $afduser -c "<cmd start/sop AFD>"<br>
To speed things up a bit the script forks for each user to start/stop the<br>
AFD instances. The script /etc/init.d/afd is just initiating thinks, but<br>
always waits for the command to complete. AFD itself has an init process<br>
(init_afd) that then starts several other process and monitors them.<br></blockquote><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Better yet, forget init.d and create a native afd@.service, with one instance per user (afd@user1, afd@user2, etc.), each instance running *exactly one* daemon.</div></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Mantas Mikulėnas <<a href="mailto:grawity@gmail.com" target="_blank">grawity@gmail.com</a>></div></div>
</div></div>