[systemd-devel] option to wait for pid file to appear
Mantas Mikulėnas
grawity at gmail.com
Thu May 17 09:58:01 UTC 2018
On Thu, May 17, 2018, 12:26 Igor Bukanov <igor at mir2.org> wrote:
> Hi,
>
> I have a service unit for nginx that uses Type=forking and PIDFile.
> That works, but occasionally I see in the log a message like
>
> nginx.service: PID file /run/nginx/nginx.pid not readable (yet?) after
> start: No such file or directory
>
> After investigating this father I see the reason for this is that
> nginx creates the pid file in a child process, not in the parent (at
> least this is how I interpret their code). As the parent may exit and
> systemd may respond to it before the child writes the pid, that leads
> to the above message.
>
> I can workaround that via replacing ExecStart=/usr/sbin/nginx with
> something like:
>
> ExecStart=/bin/sh -c "set -e; /usr/sbin/nginx; while ! test -s
> /run/nginx/nginx.pid; do sleep 0.1; done'
>
> but that busy waits. Is there any option to replace this hack via a
> native systemd solution, like explicitly waiting for the pid file to
> appear before considering the unit ready?
>
A "native systemd solution" would be to get rid of pidfiles completely.
Have you tried without the PIDFile= setting at all?
Maybe socket-activation would work for you? (With Nginx it's also a hack
though.)
> --
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180517/49ebbd0c/attachment.html>
More information about the systemd-devel
mailing list