[systemd-devel] Problems trying to convert a System-V-Init script to systemd
Lennart Poettering
lennart at poettering.net
Mon Jul 25 17:48:49 UTC 2016
On Thu, 14.07.16 12:34, 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
If you write a unit file like this then you might as well just use the
sysv compat logic we provide.
>
> /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>"
"su" opens user sessions, it does substantially more than just change
UIDs. Consider using "runuser" at least.
The fact that a user session is created means that systemd will track
the code invoked like that independently of the service unit, in a new
session scope unit. This means its lifecycle is detach from the
service have, and it's on you to ensure everything is stopped again
when the service is terminated.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list