| View previous topic :: View next topic |
| Author |
Message |
aisbaa n00b


Joined: 26 Aug 2007 Posts: 13 Location: Vilnius, Lithuania
|
Posted: Thu Jan 28, 2010 4:17 pm Post subject: [solved] Help me write init script for php fast cgi spawning |
|
|
Intro
Hi.. I've been using ngnix with PHP FAST CGI spawning script (as init script in default runlevel), it ran as expected. So time passed and other day I've read this guide, unfortunately decided that I'll be able to write my own init script , turns out I was wrong .
Result
stuff in /etc/init.d/php-fcgi
| Code: |
[color=darkred]#!/sbin/runscript[/color]
depend() {
need net
}
start() {
ebegin "Starting PHP FastCGI"
start-stop-daemon --start --background --chuid $USER \
--pidfile $PHP_CGI_PID_FILE --make-pidfile \
--exec /usr/bin/env -- $PHP_CGI_ARGS
eend $? "Failed"
}
stop() {
ebegin "Stopping PHP FastCGI"
for rip in `ps -u $USER | cut -d" " -f2 | egrep "^[0-9]+"`; do
kill $rip;
done
eend $? "Failed"
rm -f /var/run/php-fcgi.pid
}
|
Stuff in /etc/conf.d/php-fcgi
| Code: |
BIND=127.0.0.1:9000
USER=host
PHP_FCGI_CHILDREN=1
PHP_FCGI_MAX_REQUESTS=20
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
PHP_CGI_PID_FILE=/var/run/php-fcgi.pid
|
Problem
It doesn't start
| Code: |
# ./php-fcgi start
* Starting PHP FastCGI ...
* Failed [ !! ]
|
but if I enter stuff directly to shell, it works
| Code: |
start-stop-daemon --start --background --chuid host --pidfile /var/run/php-fcgi.pid --make-pidfile --exec /usr/bin/env -- - USER=host PATH=/usr/bin PHP_FCGI_CHILDREN=1 PHP_FCGI_MAX_REQUESTS=20 /usr/bin/php-cgi -b 127.0.0.1:9000
|
it spawns two processes under host user
| Code: |
# ps -u host
PID TTY TIME CMD
7965 ? 00:00:00 php-cgi
7966 ? 00:00:00 php-cgi
|
Any kind of help is accepted/appreciated
P.S. is there any tool that would show me what actions are preformed then I try to launch the script? _________________ I live here Unseen Lithuania|Youtube
Last edited by aisbaa on Sat Jan 30, 2010 1:40 pm; edited 1 time in total |
|
| Back to top |
|
 |
aisbaa n00b


Joined: 26 Aug 2007 Posts: 13 Location: Vilnius, Lithuania
|
Posted: Fri Jan 29, 2010 8:42 pm Post subject: |
|
|
moveing on
| Code: |
#!/sbin/runscript
depend() {
need net
}
start() {
ebegin "Starting PHP FastCGI"
start-stop-daemon --start --background --chuid $USER \
--pidfile $PHP_CGI_PID_FILE --make-pidfile \
--exec /usr/bin/php-cgi -- -b $BIND
eend $? "Failed to start php-fcgi"
}
stop() {
ebegin "Stopping PHP FastCGI"
start-stop-daemon --stop --pidfile $PHP_CGI_PID_FILE
rm -f /var/run/php-fcgi.pid
eend $? "Failed"
}
|
Yes, I'm happy because of this small progress .. It starts and stops..
Unfortunately it doesn't spawn any children
* for having children, I need to set few variables to be in programs environment or global (me think first option would be better)
** if I use env program for setting those values - arcane magic fails my plans. (+)
** if I export values - runscript reports that I cant do that
*** so I found --env option in start-stop-daemon manual, but it allows only one value to be set and I need two
And I'm out of options...
Question: is there other way I could set few variables to be visible for php-cgi at start-up?
P.S. I'd like to read more about init scripts, could some one guide me to the source? thanks in advance. _________________ I live here Unseen Lithuania|Youtube |
|
| Back to top |
|
 |
Naib Advocate


Joined: 21 May 2004 Posts: 3930 Location: UK - Birmingham
|
Posted: Fri Jan 29, 2010 9:58 pm Post subject: |
|
|
ummm isn't this the whole point of the /etc/init.d/spawn-fcgi init script?
I use nginx and I need php for zenphoto so I link spawn-fcgi.zenphoto to spawn-fcgi as well as create a /etc/conf.d/spawn-fcgi.zenphoto and populate it _________________ A free press is the unsleeping guardian of every other right that free men prize; it is the most dangerous foe of tyranny. Where men have the habit of liberty, the Press will continue to be the vigilant guardian of the rights of the ordinary citizen. |
|
| Back to top |
|
 |
aisbaa n00b


Joined: 26 Aug 2007 Posts: 13 Location: Vilnius, Lithuania
|
Posted: Sat Jan 30, 2010 8:41 am Post subject: |
|
|
| Quote: | | I use nginx and I need php for zenphoto so I link spawn-fcgi.zenphoto to spawn-fcgi as well as create a /etc/conf.d/spawn-fcgi.zenphoto and populate it |
I've created /etc/conf.d/php-fcgi with variables, but I need some variables to be set as environment variables for php-cgi. That would make me happy ..
Question: How can I set few environment variables in other way than using env?
P.S. method in first post doesn't work, or I'm doing something wrong  _________________ I live here Unseen Lithuania|Youtube |
|
| Back to top |
|
 |
Naib Advocate


Joined: 21 May 2004 Posts: 3930 Location: UK - Birmingham
|
Posted: Sat Jan 30, 2010 10:55 am Post subject: |
|
|
| aisbaa wrote: | | Quote: | | I use nginx and I need php for zenphoto so I link spawn-fcgi.zenphoto to spawn-fcgi as well as create a /etc/conf.d/spawn-fcgi.zenphoto and populate it |
I've created /etc/conf.d/php-fcgi with variables, but I need some variables to be set as environment variables for php-cgi. That would make me happy ..
Question: How can I set few environment variables in other way than using env?
P.S. method in first post doesn't work, or I'm doing something wrong  |
spawn-fcgi can do that.
*IF* you want to call it "php-fcgi" then do this:
#1
ln -s /etc/init.d/spawn-fcgi /etc/init.d/php-fcgi
#2
cp /etc/conf.d/spawn-fcgi /etc/conf.d/php-fcgi #NOTE the name is the same is the link
#3
vim /etc/conf.d/php-fcgi # and set your info noting: FCGI_EXTRA_OPTIONS, ALLOWED_ENV
#4
/etc/init.d/php-fcgi start _________________ A free press is the unsleeping guardian of every other right that free men prize; it is the most dangerous foe of tyranny. Where men have the habit of liberty, the Press will continue to be the vigilant guardian of the rights of the ordinary citizen. |
|
| Back to top |
|
 |
aisbaa n00b


Joined: 26 Aug 2007 Posts: 13 Location: Vilnius, Lithuania
|
Posted: Sat Jan 30, 2010 1:12 pm Post subject: |
|
|
Thousand thanks.. at first I didn't realized that spawn-fcgi is a program - thought that its a script that you wrote.. _________________ I live here Unseen Lithuania|Youtube |
|
| Back to top |
|
 |
|