Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
init script for unicorn on RHEL, Cent OS, Scientific Linux way
#!/bin/sh
#
# unicorn_redmine Startup script for unicorn for redmine
#
# chkconfig: - 86 14
# processname: unicorn_rails
# pidfile: /opt/redmine/tmp/pids/unicorn.pid
# description: Rails application server for Redmine
#
### BEGIN INIT INFO
# Provides: unicorn_redmine
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 3
# Default-Stop: 0 1 2 4 5 6
# Short-Description: start and stop unicorn
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
prog=unicorn
#ruby_home=/opt/ruby-enterprise-1.8.7-2012.02
RAILS_ROOT=/opt/redmine
UNICORN_CONF=$RAILS_ROOT/config/unicorn.rb
lockfile=${LOCKFILE-/var/lock/subsys/unicorn}
pidfile=$RAILS_ROOT/tmp/pids/unicorn.pid
SLEEPMSEC=100000
RETVAL=0
ENV=production
SUB_PATH=/redmine
start() {
echo -n $"Starting $prog: "
cd $RAILS_ROOT
# $ruby_home/bin/unicorn_rails -c $UNICORN_CONF -E production -D --path /redmine
/usr/bin/bundle exec unicorn_rails -c $UNICORN_CONF -E $ENV -D --path $SUB_PATH
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} ${prog} -QUIT
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
restart() {
echo -n $"Restarting $prog: "
killproc -p ${pidfile} ${prog} -USR2
RETVAL=$?
echo
}
reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} ${prog} -HUP
RETVAL=$?
echo
}
rh_status() {
status -p ${pidfile} ${prog}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
restart
;;
upgrade)
upgrade
;;
condrestart|try-restart)
if rh_status >/dev/null 2>&1; then
stop
start
fi
;;
force-reload|reload)
reload
;;
configtest)
configtest
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
RETVAL=2
esac
exit $RETVAL
@mochadwi

This comment has been minimized.

Copy link

commented Jan 25, 2015

before do this, we should consider add a wrappers first for ruby. Here's the detail:

http://rvm.io/integration/init-d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.