[systemd-devel] type=notify not working as intended

Jouke Witteveen j.witteveen at gmail.com
Thu Aug 17 09:36:03 UTC 2017


On Tue, Aug 15, 2017 at 5:59 AM, Kalpa Gunarathna <kalpa at sigscale.com> wrote:
> Hello all,
>
> I have scripted a service unit as follow.
>
> [Unit]
> Description="A test service"
> After=epmd.service epmd.socket
>
> [Service]
> ExecStart=/home/otpuser/bin/start
> Type=notify
> NotifyAccess=all
> WorkingDirectory=~
> User=otpuser
> Group=otp
> Restart=always
> RestartSec=3
>
> [Install]
> WantedBy=multi-user.target
>
>
> ExecStart directs to a shell script which starts a Erlang run_erl daemon.
> This daemon is forking a process which is the BEAM virtual machine. In the
> forked process Im sending "READY=1\nSTATUS=Initialized\nMAINPID="
> <<Forked-Process-Pid>> "\n to systemd via sd_notify. The problem is service
> is getting restarted constantly.
>
> journalctl give this
>
> abc.service: Service hold-off time over, scheduling restart.
> Stopped "A test service.".
>
>
> Is it required to send READY=1 from the daemon it self ? or can systemd
> allow forked process of the daemon to send REDAY=1 notification?
>
> It works when Type=forking and PIDFile is specified, but can we have
> Type=forking and without PIDFIle, notify READY=1 via forked process ?
>
> My systemd version
>
> $ systemd --version
> systemd 229
>

The service fails when the main process terminates before a READY=1
notification is received. Contrary to Reindl Haralds claim, this
notification is allowed to come from whatever process that is allowed
to send notifications, as controlled by NotifyAccess=. In order to not
give up on the service when the main process terminates, but wait for
the remaining processes in the cgroup, you should add
RemainAfterExit=yes to your unit.

Regards,
- Jouke


More information about the systemd-devel mailing list