I set up a very small local network for web development. The webserver is a stack of
- MySql 5.1.37
- NGINX 0.8.19
- PHP 5.2.10 with w/ Suhosin-Patch 0.9.7 and Xdebug v2.0.4
The server itself runs ubuntu karmic 9.10.
In order to provide PHP to NGINX I use the following command:
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
My problem is that every morning, when the machine resumes from a suspend state PHP has stopped working (in the browser NGINX display a "bad gateway" message after a few seconds of trying to load the requested page). If I try to relaunch the command for respawning PHP, it gives me error, saying that the address is already in use.
EDIT: more information
After having spawned, if I run ps ax | grep php
I get a php-cgi
process running, while if I re-issue the command after resuming from suspend, I do not get anything, although the address would still result to be "in use" if I try to re-spawn. The idea that is crossing my mind is that php-cgi registers its presence with some other process, that does not detect the sudden death php-cgi with the suspend, keeping the address busy. Can it be?!
Any idea on how to fix this? An elegant solution is most welcome, but even a dirty workaround that makes possible for the server to self-recovery without human intervention is ok. This is just an internal production server used by a couple of people.
Thank you in advance for your time!
Maybe you can switch to php-fpm from spawn-fcgi?
Karmic still uses pm-utils, right? You need a script in
/etc/pm/sleep.d
that will stop your server on suspend, and restart it on resume.An example script might be the following (tweak the suspend/resume options as needed, but this should give you the correct script structure). If you've already scripted an
/etc/init.d/foo
script to start your server at boot, you probably want to use that to stop/start the server below.Ok, after a few days of testing I can confirm that the problem solved by itself with regular upgrades.
Should you incur in the same problem, if you are able to find out what process(es) need to be killed in order to "reset" the fcgi servervice, then the solution provided by ~quack seems a sensible one.
Software version with which the problem does not show anymore: