Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] Help me write init script for php fast cgi spawning
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
aisbaa
n00b
n00b


Joined: 26 Aug 2007
Posts: 13
Location: Vilnius, Lithuania

PostPosted: Thu Jan 28, 2010 4:17 pm    Post subject: [solved] Help me write init script for php fast cgi spawning Reply with quote

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 :oops: .

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 :x

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 :roll:

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
View user's profile Send private message
aisbaa
n00b
n00b


Joined: 26 Aug 2007
Posts: 13
Location: Vilnius, Lithuania

PostPosted: Fri Jan 29, 2010 8:42 pm    Post subject: Reply with quote

:twisted: moveing on :twisted:

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 :lol: .. 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
View user's profile Send private message
Naib
Advocate
Advocate


Joined: 21 May 2004
Posts: 3930
Location: UK - Birmingham

PostPosted: Fri Jan 29, 2010 9:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
aisbaa
n00b
n00b


Joined: 26 Aug 2007
Posts: 13
Location: Vilnius, Lithuania

PostPosted: Sat Jan 30, 2010 8:41 am    Post subject: Reply with quote

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 :P ..

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
View user's profile Send private message
Naib
Advocate
Advocate


Joined: 21 May 2004
Posts: 3930
Location: UK - Birmingham

PostPosted: Sat Jan 30, 2010 10:55 am    Post subject: Reply with quote

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 :P ..

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
View user's profile Send private message
aisbaa
n00b
n00b


Joined: 26 Aug 2007
Posts: 13
Location: Vilnius, Lithuania

PostPosted: Sat Jan 30, 2010 1:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum