[systemd-devel] Problems trying to convert a System-V-Init script to systemd
Holger Kiehl
Holger.Kiehl at dwd.de
Mon Jul 18 13:32:19 UTC 2016
On Fri, 15 Jul 2016, Mantas Mikulėnas wrote:
> 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.
>
You are right. See my other mail I just send. systemd-cgls shows that it
is part of the user session. I did try running it with runuser, but that
does not work because AFD needs the user environment, that whats in
~/.profile (or .bash_profile, .cshrc, .login, etc).
> 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.
>
But I have users that run multiple AFD's under one user, each in their on
working directory. Can this be done, without having to manually write a
unit file for each AFD instance?
Regards,
Holger
More information about the systemd-devel
mailing list