Forum

Init scripts

Anton Lukas Fors Hur
6 January 2009, 18:06
Hello.

I'm currently running Gentoo on one of my servers and I'm having trouble with php-fcgi's init script, I rewrote Hiawatha's to make it work and it worked as i should but when I rewrote php-fcgi's it just gave me trouble, here comes the spartan script:

#!/sbin/runscript

PHP_FCGI="/usr/sbin/php-fcgi"
PIDFILE="/var/run/php-fcgi.pid"

start() {
ebegin "Starting php-fcgi"
start-stop-daemon --start --exec ${PHP_FCGI} --pidfile ${PIDFILE}
eend $?
}

stop() {
ebegin "Stopping php-fcgi"
start-stop-daemon --stop --exec ${PHP_FCGI} --pidfile ${PIDFILE}
eend $?
}
Hugo Leisink
6 January 2009, 19:58
That last time I used Gentoo is more then 5 years ago, so I don't know all the details of what your script does.

php-fcgi is started by just running it. It forks and starts the PHP binary as a FastCGI daemon. To stop those PHP daemons, run php-fcgi with the -k option. php-fcgi itself isn't a daemon. The started PHP binaries are.

If I'm to help you with your problem, I need a little more information then only "it gave me trouble".
Anton Lukas Fors Hur
6 January 2009, 20:05
Alright, so php-fcgi is the daemon starter. The start-stop-daemon does what it's name indicates. I made a script wich just started php by the "php-fcgi" command and stopped it by simply running "php-fcgi -k" but it didn't work if the computer didn't shut down correctly, ie. the power goes.
Hugo Leisink
6 January 2009, 23:36
When you run php-fcgi, it creates a file /var/run/php-fcgi.pid, which contains the PID of the running PHP FastCGI daemons. Is that file created correctly? It is required by php-fcgi in order to stop the running PHP daemons: it sends a kill signal to the processes with a PID equal to those in /var/run/php-fcgi.pid.
Anton Lukas Fors Hur
7 January 2009, 00:52
It is created correctly, the problem seems to be that the PID still exists when the computer starts up after a crash ie., the PHP daemon won't start.
Hugo Leisink
7 January 2009, 11:13
My init scripts indeed don't handle a system crash correctly. Since Unix (at least Linux and BSD) is stable enough, a system crash will probably never occur.

What you can do on a system start is to delete an existing /var/run/php-fcgi.pid.
Anton Lukas Fors Hur
7 January 2009, 16:52
Well, I'll try a few different things later today. The start-stop-daemon is meant to handle crashes and such but as I said it don't work, I think I'll write an own php-fcgi script/application that can run PHP fastcgi as a daemon via start-stop-daemon.
This topic has been closed.