systemd: apcupsd daemon parent exits before the child creates the pid file
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
apcupsd (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
The apcupsd.service file in Ubuntu 20.04 LTS (amd64) includes the following lines:
Type=forking
PIDFile=
The systemd documentation (https:/
[...]
... if the process decides to write a traditional PID file, systemd will be able to read the main PID from there. Please set PIDFile= accordingly. Note that the daemon should write that file before finishing with its initialization. Otherwise, systemd might try to read the file before it exists.
[...]
The issue is that, although the daemon is started and works correctly, the "systemctl status apcupsd.service" call always reports the following:
systemd[1]: apcupsd.service: Can't open PID file /run/apcupsd.pid (yet?) after start: Operation not permitted
This glitch is due to the fact that the parent process of the daemon exits before the child has written the PID file.
I proved this statement by recompiling apcupsd from source and inserting a "sleep(1)" before the "exit(0) /* parent exits */" call in the daemon_start() function (of apcupsd.c).
It fixed the issue by keeping the parent alive for a while, giving the child enough time to call make_pid_file().
I know that sleep(1) is not a bugfix rather a test for verifying the root cause of the issue.
I reported the issue to the apcupsd developers before filling this bug. Anyway although their mailing list is alive and kicking, they do not release a new version since 2016 so I am not so confident that they will fix their source (at least not soon).
So could you please implement and apply a patch to the source that delays the exit of the parent (i.e. waiting for the PID file of the child to be created) in order to make apcupsd 100% compliant to what systemd expects?
description: | updated |
description: | updated |
Status changed to 'Confirmed' because the bug affects multiple users.