Running php with runit service supervisor

php-fcgi has given up on me a few times in the past. I decided to explore how to make sure it stays running.

# mkdir /etc/sv/php-fcgi

Then fire up your favourite editor to create /etc/sv/php-fcgi/run

#!/bin/bash

PHP_FCGI_CHILDREN=8
PHP_FCGI_MAX_REQUESTS=1000
FCGI_WEB_SERVER_ADDRS="127.0.0.1"
USER=www-data
GROUP=www-data
PHP=/usr/bin/php4-cgi
PORT=1026

export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS USER GROUP PHP PORT

exec /usr/bin/spawn-fcgi -n -p $PORT -C $PHP_FCGI_CHILDREN -u $USER -g $GROUP -f $PHP 2>&1

When this is done, create /etc/sv/php-fcgi/log. Then create another script named "run" there too:

#!/bin/bash
exec chpst -u nobody svlogd -tt /var/log/sv/php-fcgi

Make sure the folder /var/log/sv/php-fcgi exists and is writeable by the user nobody (in this case).

Afterwards tell runit about it:

# ln -s /etc/sv/php-fcgi /var/services

You still need to do the configuration on lighty's side.