Discussion:
type=notify not working as intended
(too old to reply)
Kalpa Gunarathna
2017-08-15 03:59:54 UTC
Permalink
Raw Message
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
Reindl Harald
2017-08-15 13:46:08 UTC
Permalink
Raw Message
Post by Kalpa Gunarathna
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
MAINPID is supposed to send the notify
Type=notify needs to be explicit supported by the daemon
Jouke Witteveen
2017-08-17 09:36:03 UTC
Permalink
Raw Message
Post by Kalpa Gunarathna
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
Lennart Poettering
2017-08-31 14:29:45 UTC
Permalink
Raw Message
Post by Kalpa Gunarathna
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.
When you use Type=notify, then the main process of the daemon defines
the runtime of your service. That means you probably want to use the
shell's "exec" command to replace the shell script with your erlang
daemon. if you instead just fork it off, and exit in the shell script,
then systemd will notice that it exited and will consider the service
dead.
Post by Kalpa Gunarathna
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 needs to come from any process that is witelisted using
NotifyAccess=. Note though that there's a bit of a race: if you send
READY=1 and immediately exit from the process doing that, then systemd
can't properly relate the message to the service (that's a race we
can#t fix without kernel support), except if the process is actually
the one systemd forked off. Hence, sd_notify(READY=1) works reliably only if either:

1. it is invoked by the immediate process systemd forked off

or

2. the process is long-running and stays around for longer after
sending READY=1

Lennart
--
Lennart Poettering, Red Hat
Loading...