#!/bin/bash

# Modify it to your configuration
DIR=/srv/redmine

# Start Redmine in daemon mode.
start(){
	cd $DIR
	ruby script/server -d -e production
}

# Stop Redmine daemon
stop(){
	RUBYPID=`ps aux | grep "ruby script/server -d -e production" | grep -v grep | awk '{print $2}'`
	if [ "x$RUBYPID" != "x" ]; then
	kill -2 $RUBYPID
fi	
}

# Check if Redmine is running
status(){
	RUBYPID=`ps aux | grep "ruby script/server -d -e production" | grep -v grep | awk '{print $2}'`
	if [ "x$RUBYPID" = "x" ]; then
		echo "* Redmine is not running"
	else
		echo "* Redmine is running"
fi
}


case "$1" in
	start)
		start
	;;

	stop)
		stop
	;;

	status)
		status
	;;

	restart|force-reload)
		stop
		start
	;;
			
	*)
		echo "Usage: $0 {start|stop|restart|force-reload|status}"
		exit 1
			
esac
