init.d scripts

soma edited this page Sep 14, 2010 · 1 revision
Clone this wiki locally

Init-d scripts with start-stop-daemon for debian-like linux systems

To manage trinidad with start-stop-daemon you need to have an executable in your path. I put this in /usr/bin/trinidad. In future releases a binfile in your gems bin might be better. Path to your jruby installation might vary.

#!/bin/sh
/usr/local/jruby/bin/jruby -S trinidad $@ > /dev/null 2>&1

Then the following init.d script (/etc/init.d/trinidad)

#!/bin/sh

set -e

# Must be a valid filename
NAME=trinidad
#/var/run/app must be writable by your user
PIDFILE=/var/run/app/trinidad.pid
#This is the command to be run, give the full pathname
DAEMON="/usr/bin/trinidad"
#create a config yml with daemonization options in it - and the same PIDFILE path as above
DAEMON_OPTS="--config=/etc/trinidad/config.yml"
USER=www-data

APPDIR=/apps/yourapp/current

# below is our java opts, for a 8 gig ram, xeon quadcore machine, you might want to change this
export JAVA_OPTS="-server -Xmx2500m -Xms2500m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:NewRatio=2 -XX:+DisableExplicitGC -Dhk2.file.directory.changeIntervalTimer=6000 -Xss2048k -XX:ParallelGCThreads=4 -XX:+AggressiveHeap"

export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"

case "$1" in
  start)
        echo -n "Starting daemon: "$NAME
	start-stop-daemon --start --chdir $APPDIR --quiet --chuid $USER --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
        echo "."
	;;
  stop)
        echo -n "Stopping daemon: "$NAME
	start-stop-daemon --stop --chdir $APPDIR --quiet --chuid $USER --oknodo --pidfile $PIDFILE
        echo "."
	;;
  restart)
        echo -n "Restarting daemon: "$NAME
	start-stop-daemon --stop --chdir $APPDIR --quiet --chuid $USER --oknodo --retry 30 --pidfile $PIDFILE
	start-stop-daemon --start --chdir $APPDIR --quiet --chuid $USER --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
	echo "."
	;;

  *)
	echo "Usage: "$1" {start|stop|restart}"
	exit 1
esac

exit 0

A trinidad config file is needed, modify for your app:

---
  environment: production
  jruby_max_runtimes: 1
  jruby_min_runtimes: 1
  port: 8080
  extensions:
    daemon:
      pid_file: /var/run/app/trinidad.pid