php-fcgi bug: Executable path is not absolute

There is a bug on systemd script Virtualmin creates for domains. After setting up server with Virtualmin and nginx, all sites go down with error 502 Bad Gateway after a reboot. Everything works fine until the reboot.

After researching I found that it is an error with startup scripts Virtualmin creates inside /lib/systemd/system/ directory. The error is in the line 6 of each file.

ExecStop=su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\` ; sleep 1

This needs to be changed to

ExecStop=/bin/sh -c 'su user -c kill\ \`cat\ \/var\/php\-nginx\/160827070023515\.php\.pid\` ; sleep 1'

for sites to work again. I think this is something that need to be corrected on the next release. I've posted detailed information and temporary workaround for this on my blog post https://vpsfix.com/13883/nginx-executable-path-is-not-absolute/

Thanks!

Status: 
Active
Virtualmin version: 
6.14
Webmin version: 
1.962

Comments

Instead, would it work to use the absolute path to the su command instead of putting it inside /bin/sh ?

I can confirm this bug on my Ubuntu 18.04.5 Virtuozzo VPS instance with PHP7.4

JamieCameron: Instead, would it work to use the absolute path to the su command instead of putting it inside /bin/sh ?

Yes JamieCameron, if you try it this way:

ExecStop=/bin/su username -c 'kill\ \`cat\ \/var\/php\-nginx\/160858513327523\.php\.pid\` ; sleep 1'

** You just have to remember to encapsulate the entire kill command + sleep 'in single quotes'

The alternate method that works is to make it similar to the ExecStart as Freddy63 which is ALREADY using /bin/sh

ExecStart=/bin/sh -c 'su username -c PHPRC\=\/home\/username\/etc\/php7\.4\ PHP_FCGI_CHILDREN\=4\ \/usr\/bin\/php\-loop\.pl\ \/usr\/bin\/php\-cgi7\.4\ \-b\ \/var\/php\-nginx\/160858513327523\.sock\/socket\ \>\>\/home\/username\/logs\/php\.log\ 2\>\&1\ \<\/dev\/null & echo $! >/var/php-nginx/160858513327523.php.pid && chmod +r /var/php-nginx/160858513327523.php.pid'
ExecStop=/bin/sh -c 'su username -c kill\ \`cat\ \/var\/php\-nginx\/160858513327523\.php\.pid\` ; sleep 1'

This bug seems to have been introduced sometime on the last update by virtualmin or ubuntu.

ISSUE SHOULD BE CHANGED TO CRITICAL -- As soon as anyone reboots their server, all their websites will not come back up with PHP daemons until it is fixed.

By the way, the troubling thing also, is when setting up a new virtualmin virtual server, it shows:

Starting PHP FastCGI server ..
.. done

...after an extra long pause. (it must be exiting status 0??) Even if systemctl status shows this:

# systemctl status php-fcgi-somesite.somedomain.service
● php-fcgi-somesite.somedomain.service - Starts Nginx PHP FastCGI server for somesite.somedomain.com (Virtualmin)
   Loaded: error (Reason: Exec format error)
   Active: inactive (dead)
Dec 22 05:30:53 host systemd[1]: /lib/systemd/system/php-fcgi-somesite.somedomain.service:5: Ignoring unknown escape sequences: "su somesite -c PHP_FCGI_CHILDREN\=4
Dec 22 05:30:53 host systemd[1]: /lib/systemd/system/php-fcgi-somesite.somedomain:6: Executable path is not absolute: su somesite -c kill\ \`cat\ \/var\/php

This is enough to drive a system administrator crazy not knowing why php-fcgi isn't starting an daemon for the site and why virtualmin isn't complaining either.

In the next release, we'll use the absolute path to the su command.

It's odd that on some Linux distros, just using "su" does work fine though. Normally I'd expect that command to be in the regular $PATH