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

Gena Makhomed gmm at csdoc.com
Wed Nov 22 23:22:21 UTC 2017


On 23.11.2017 0:35, Clemens Gruber wrote:

>>>> I am use nginx web server (http://nginx.org/) with systemd.
>>>> But I see errors in /var/log/messages when running nginx:
>>>>
>>>> systemd: Starting nginx - high performance web server...
>>>> systemd: Failed to read PID from file /var/run/nginx.pid: Invalid
>>>> argument
>>>> systemd: Started 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
>>
>>> either the daemon needs to be fixed
>>
>> Ok, but can you tell, what is wrong with daemon?
> 
> There is nothing wrong with nginx per se. I am using a nginx.service
> file similar to the following one:
> https://git.pengutronix.de/cgit/ptxdist/plain/projectroot/usr/lib/systemd/system/nginx.service

BTW, in you nginx.service file line

ExecStartPre=/usr/sbin/nginx -t

is useless. It does not work as restart guard.

ExecRestartPre= in TODO but not released yet in systemd.

https://lists.freedesktop.org/archives/systemd-devel/2014-July/021642.html

> If nginx was not built with --pid-path=/var/run/nginx.pid you have to
> override it in your nginx.conf with the correct pid path, e.g.
> pid /var/run/nginx.pid;

nginx is build with "--pid-path=/var/run/nginx.pid"
and "PIDFile=/var/run/nginx.pid" is in nginx.service file.

> (Your error looks like nginx did create the pid file somewhere else and
> systemd can't find it)

All ok with pid file, it located at /var/run/nginx.pid
and no directive pid defined in nginx.conf file.

> Buildroot has a different approach. They add that pid config line, etc.
> to the nginx command, so you do not have to add it to your nginx.conf:
> https://github.com/buildroot/buildroot/blob/master/package/nginx/nginx.service

I use official nginx builds from nginx site:
http://nginx.org/en/linux_packages.html#mainline
OS CentOS 7.4, nginx 1.13.7

I restart nginx service and see the same error:

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.

# cat /var/run/nginx.pid
12488

# systemctl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP 
+LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS 
+KMOD +IDN

-- 
Best regards,
  Gena


More information about the systemd-devel mailing list