Gentoo init.d script for a Rails mongrel cluster

Posted by Mike Sun, 23 Dec 2007 22:45:00 GMT

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!?)

Posted in , ,  | Tags , ,  | 3 comments | no trackbacks

RV2 Camping on Gentoo

Posted by Mike Thu, 05 Jul 2007 22:57:00 GMT

Evan Weaver wrote a SysV init.d setup for daemonizing Camping apps on a *Nix system and documents it in rv, a tool for luxurious camping

I used that blog entry as a reference to build one called RV2 that is a little bit more Gentoo specific. Here are my scripts and directory layout

Read more...

Posted in , , ,  | Tags , , ,  | 1 comment | no trackbacks

Web Statistics