[systemd-devel] How to run forking daemon with systemd in correct way, without errors?
Reindl Harald
h.reindl at thelounge.net
Thu Nov 23 10:08:55 UTC 2017
Am 23.11.2017 um 10:32 schrieb Gena Makhomed:
> On 23.11.2017 7:45, Mantas Mikulėnas wrote:
>
>>> This is bug in nginx code? And this bug should be fixed in nginx?
>>>
>>> But "daemon(); write_pidfile();" is common pattern
>>> used by many services and even in library functions.
>
>> It may be common, but not necessarily correct. The parent process should
>> only exit *after* finishing all the preparations (i.e. something like
>> "fork(); write_pidfile(); exit()"), since systemd uses the exit as a
>> signal
>> that the daemon is now "ready".
>
> You are joking? Why you think that this pattern is not correct?
common sense
> Is any systemd documentations exists, which requires from daemons
> write pidfile of daemon process before exiting the parent process?
>
> Does you see daemon() function from The GNU C Library (glibc)?
> It exits from parent process immediately, without writing pid file.
> Probably you should first fix function daemon() from glibc to meet
> systemd requirements? And after this - rewrite all existing daemons?
well, if you want to tell the main-pid to systemd it's logical that
there must be a defined point when that file exists, in most cases you
don't need the PID stuff at all as i have explained multiple times
if you want so the daemon needs to write the pid file before telling
systemd "i am ready"
More information about the systemd-devel
mailing list