1

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!

3 Answers 3

1

Maybe you can switch to php-fpm from spawn-fcgi?

1
  • Thank you for your suggestion. I already planned to do the shift to php-fpm when the package will be at least mantained in someone's PPA. There was a proposal to include this package into Karmic, but it was declined, so at the moment there is only a testing PPA or you have to compile your own patched version of the source... and it sounds like I might risk to simply find myself in bigger problems...
    – mac
    Nov 25, 2009 at 13:18
1

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.

#!/bin/sh
#
# /etc/pm/sleep.d/10spawnfcgi

case "$1" in

   hibernate|suspend)
      # example -- replace this with what works on your system
      killall spawn-fcgi
      # or better yet:
      # /etc/init.d/myFcgiServer stop
      ;;
   thaw|resume)
      # restart -- tweak to your liking, rerun your startup script, etc
      /usr/bin/spawn-fcgi -a 127.0.0.1 other-options-here
      # or better yet:
      # /etc/init.d/myFcgiServer start
      ;;

   *) exit $NA
      ;;
esac
2
  • Thank you very much for your answer. I'm about to add more info in the question itself, however unluckily (or luckily) yesterday a new kernel came out amongst the updates, and today it does seems the problem has solved by itself (although other problems came into the scene).
    – mac
    Nov 25, 2009 at 13:59
  • glad to hear the new kernel is helping. this scenario is fairly common, unfortunately, so keep this solution in mind if you decide to use the old kernel, or in case the next kernel update breaks suspend again. Nov 25, 2009 at 16:34
0

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:

  • Kernel: 2.6.31-15-generic
  • PHP: 5.2.10-2ubuntu6.3 with Suhosin-Patch 0.9.7 (cli)
  • Nginx: 0.8.19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .