[systemd-devel] How to run forking daemon with systemd in correct way, without errors?

Reindl Harald h.reindl at thelounge.net
Thu Nov 23 00:30:04 UTC 2017



Am 23.11.2017 um 00:38 schrieb Gena Makhomed:
> On 23.11.2017 0:29, Reindl Harald wrote:
> 
>>>> or just remove the pid-file stuff from the systemd-unit, systemd 
>>>> don't need it really
> 
>>> pid-file need for service reload and service stop
> 
>> nonsense
> 
> You are talking about GuessMainPID= option?
> 
> https://www.freedesktop.org/software/systemd/man/systemd.service.html#GuessMainPID= 

no i talk about nearly 6 years systemd expierience in production and 
that i yet need to see a real world case where systemd don't work in 
case of missing PID file

> You can read from documentation of this directive:
> "The guessing algorithm might come to incorrect conclusions if a daemon 
> consists of more than one process."
> 
> nginx daemon consists of more than one process,
> so directive MainPID= should be defined in unit file.

i know that all, httpd and postfix are typically forking services and 
are working fine without any PID file since 2011

> BTW, nginx has ability to change executable on the fly:
> http://nginx.org/en/docs/control.html#upgrade
> 
> In any case, you are talking about something like workaround of the bug,
> but I am asking in systemd-devel mail list about root cause of this bug,
> how to fix this bug, and where bug is located - in nginx or in systemd?

in nginx which obviously creates the pid file too late

>> please read how systemd works
> 
> I read even sources of systemd and nginx.

why do you then pretend the pid-file is needed for *service stop* when 
systemd monitors every process of the cgroup and other then sysvinit can 
guarantee that *every* single process which is still alive after send 
SIGTERM to the MAINPID and don't exit get it's own SIGTERM and finally 
SIGKILL to leftover processes no matter how they get started (shell_exec 
from a php srcipt as example) - the CGROUP stuff and how systemd stops 
services is basic knowledge

> But I still can't find *root cause* of this bug:
> 
> systemd: Stopping nginx - high performance web server...
> systemd: Starting nginx - high performance web server...
> systemd: PID file /var/run/nginx.pid not readable (yet?) after start.
> systemd: Started nginx - high performance web server

likely the pid-file don't exist at the moment of forking


More information about the systemd-devel mailing list