Skip to content

Instantly share code, notes, and snippets.

@lesstif
Last active August 29, 2015 14:06
Show Gist options
  • Save lesstif/dfaf6ea79aacaefcb273 to your computer and use it in GitHub Desktop.
Save lesstif/dfaf6ea79aacaefcb273 to your computer and use it in GitHub Desktop.
redmine start/stop/status using unicorn web server
#!/bin/sh
export RAILS_ENV=production
USER=`whoami`
PIDS=""
getpids() {
local procname=$1
if [ "$#" = 0 ] ; then
echo $"Usage: getpids {procname} "
return
fi
PIDS=`ps -eaf|grep unicorn|grep ${procname}|grep -v grep|grep ${USER}|awk '{print $2}'|paste -d" " -s`
}
start() {
bundle exec unicorn_rails -D -c config/unicorn.rb
RETVAL=$?
if [ $RETVAL != 0 ];then
tail log/unicorn.stderr.log
fi
}
stop() {
getpids "master"
if [ ! -z ${PIDS} ];then
echo "sending TERM signal to unicorn master ${PIDS}"
kill -TERM ${PIDS}
fi
}
status() {
getpids "master"
if [ "x"${PIDS} = "x" ];then
echo "unicorn redmine not running.."
exit 0
fi
MASTER=${PIDS}
getpids "worker"
WORKER=${PIDS}
echo "Unicorn master $MASTER and worker ($WORKER) is running..."
}
case "$1" in
start)
start
status
;;
stop)
stop
;;
about)
ruby script/about
;;
status)
status
;;
restart)
stop
start
status
;;
*)
echo $"Usage: $0 {start|stop|restart|about|status|restart}"
RETVAL=2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment