Gentoo init.d script for a Rails mongrel cluster
Posted by Mike
Here is my Gentoo init.d script for a mongrel cluster running a Rails app.
/etc/init.d/mongrel
#!/sbin/runscript
depend() {
need net
use apache2 mysql
after apache2 mysql
}
start() {
ebegin "Starting mongrels"
start-stop-daemon --start --chuid $USER --exec $MONGREL \
-- cluster::start -C $MONGREL_CONF
eend $?
}
stop() {
ebegin "Stopping mongrels"
start-stop-daemon --start --chuid $USER --exec $MONGREL \
-- cluster::stop -C $MONGREL_CONF
eend $?
}
status() {
ebegin "mongrel status"
start-stop-daemon --start --chuid $USER --exec $MONGREL \
-- cluster::status -C $MONGREL_CONF
eend $?
}
/etc/conf.d/mongrel
Gentoo will load script variables for an init.d script from the /etc/conf.d directory where the conf file is the same name is the init.d file. Thus in /etc/conf.d/mongrel
USER=deployer:deployer MONGREL=/usr/bin/mongrel_rails MONGREL_CONF=/var/www/mysite/rails_app/shared/mongrel_cluster.conf
Some things to point out:
- this integrates perfectly with Gentoo’s rc-status command
- the mongrel cluster will be running as the user/group defined in USER (i.e. safer non-root)
- mongrel_cluster.conf is a standard mongrel cluster configuration that you would have generated with Capistrano, Vlad or written by hand
- start-stop-daemon command is executed in —start mode because all of the commands ‘start’ ‘stop’ ‘restart’ ‘status’ are delegated to the mongrel_rails executable
- because you are running the commands as a non-root user your Capistrano or Vlad tasks (rake vlad:start_app) will still work from your remote shell (you’re not running as root through ssh right!?)





