How do I shorten the inittab process entry, aka where to specify the environment variables that init will see?

I am setting up an Etch server to host ruby ​​and php applications using nginx. I have successfully configured inittab to start php-cgi process on boot with respawn action. After serving 1000 requests, php-cgi worker processes die and init gets updated. The inittab entry looks like this:

50:23:respawn:/usr/local/bin/spawn-fcgi -n -a 127.0.0.1 -p 8000 -C 3 -u someuser -- /usr/bin/php-cgi

      

I originally wrote the process entry (everything after the third colon) in a separate script (simply because it was long) and put that script name in the inittab entry, but since the script would run its single line and die, the syslog was filled with errors like this:

May  7 20:20:50 sb init: Id "50" respawning too fast: disabled for 5 minutes

      

So I got rid of the script file and just put the whole line in inittab. No further errors are found in syslog.

Now I am trying to do the same with thin to serve a rails application. I can successfully start the thin server by running the following command:

sudo thin -a 127.0.0.1 -e production -l /var/log/thin/thin.log -P /var/run/thin/thin.pid -c /path/to/rails/app -p 8010 -u someuser -g somegroup -s 2 -d start

      

It obviously works the same way whether I use the -d (daemonize) flag or not. Command line control returns immediately (processes have been dismounted) anyway. If I put the entire command (minus sudo and with absolute paths) in inittab, init complains (in syslog) that the process record is too long, so I put these options in the exported environment variable in / etc / profile. Now I can successfully start the server with:

sudo thin $THIN_OPTIONS start

      

But when I put this in inittab entry with respawn action

51:23:respawn:/usr/local/bin/thin $THIN_OPTIONS start

      

the logs clearly state that the environment variable is not visible to init; it's like the command was just a "fine start".

How can I shorten the inittab process entry? Is there a file other than / etc / profile where I can set the THIN_OPTIONS environment variable? My previous experience with php-cgi tells me that I can't just put the whole command in a separate script.

0


a source to share


2 answers


init.d script

Use the script in

/etc/rc.d/init.d

      

and set the runlevel

Here are some examples: thin, ruby, apache

http://articles.slicehost.com/2009/4/17/centos-apache-rails-and-thin



http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost

http://elwoodicious.com/2008/07/15/nginx-haproxy-thin-fastcgi-php5-load-balanced-rails-with-php-support/

What examples use scripts to use.

edit : Asker noted that this would prevent igniting. I suggested unrolling in the init script and canceling the process so that init doesn't hang (maybe it will fork () the script itself, will check). And then create an infinite loop that waits on the server for the process to die and restarts it.

edit2 : It seems init is initializing the script. The loop just has to do it.

0


a source


And why don't you name the wrapper that starts subtle your options?

<i> start_thin.sh:
#! / Bin / bash
/ usr / local / bin / thin -a 127.0.0.1 -e production -l / var / log / thin / thin.log -P / var / run / thin / thin.pid -c / path / to / rails / app -p 8010 -u someuser -g somegroup -s 2 -d start



and then:
51: 23: respawn: / usr / local / bin / start_thin

+1


a source







All Articles