Debian init script for Redmine

Added by Jared S almost 7 years ago

This might help someone and I'm not sure where I can put this so here is an init script for Redmine on debian/ubuntu systems:

#!/bin/sh
### BEGIN INIT INFO
# Provides:             redmine
# Required-Start:       $local_fs $remote_fs
# Required-Stop:        $local_fs $remote_fs
# Should-Start:         $network
# Should-Stop:          $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Daemonized version of redmine
# Description:          Starts the redmine daemon
#                       /etc/default/redmine.
### END INIT INFO
# Author: Jared Swets

#The complete default command that is being run is:
#su - redmine -c "cd /var/www/redmine; mongrel_rails start -d -e production" 
#obviously this will change with your variables,
#but the entire command is here for testing

#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Redmine Daemon" 
NAME1="redmine" 
NAME2="mongrel" 
RUBY=/usr/bin/ruby
LOC=/var/www/redmine
RUBY="/usr/bin/ruby" 
DAEMON1="mongrel_rails start" 
DAEMON1_ARGS="-d -e production" 
PIDFILE1=$LOC/log/$NAME2.pid
LOG1=/var/log/redmine.log

#[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
# Load the VERBOSE setting and other rcS variables
#[ -f /etc/default/rcS ] && . /etc/default/rcS
# Define LSB log_* functions. Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Start Redmine in daemon mode
start(){
 REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
        if [ "x$REDMINEPID" = "x" ] && [ -f $PIDFILE1 ]; then
                echo "" >> $LOG1
                echo `date` " * No $NAME1 process found... but PID file left in $PIDFILE1" | tee -a $LOG1
                echo "Deleting PID!" | tee -a $LOG1
                echo "" >> $LOG1
                rm $PIDFILE1
        elif [ "x$REDMINEPID" != "x" ]; then
                echo `date` " * $NAME1 appears to be already running!" | tee -a $LOG1
                exit
        fi
        su - redmine -c "cd $LOC; $DAEMON1 $DAEMON1_ARGS" 
        echo `date` " * Starting $NAME1..." | tee -a $LOG1
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
        if [ "x$REDMINEPID" = "x" ]; then
                echo `date` " * $NAME1 failed to start!" | tee -a $LOG1
                exit
        fi
}
# Stop Redmine daemon
stop(){
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
        if [ "x$REDMINEPID" != "x" ]; then
                kill -2 $REDMINEPID
                echo `date` " * Stopping $NAME1..." | tee -a $LOG1
                REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
                if [ "x$REDMINEPID" != "x" ]; then
                        echo `date` " * $NAME1 stopped..." | tee -a $LOG1
                elif [ "x$REDMINEPID" = "x" ]; then
                        echo `date` " * $NAME1 failed to stop!" | tee -a $LOG1
                fi
        elif [ "x$REDMINEPID" = "x" ]; then
                echo `date` >> $LOG1
                echo "" >> $LOG1
                echo " * $NAME1 does not appear to be running!" | tee -a $LOG1
                exit
        fi
}
# Check if Redmine is running
status(){
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
        if [ "x$REDMINEPID" = "x" ]; then
                echo " * $NAME1 is not running" 
        else
                echo " * $NAME1 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

I did my best to test it, but if you notice a flaw please let me know...

redmine.txt Magnifier (3.74 KB)

Replies (5)

RE: Debian init script for Redmine - Added by Felix Schäfer almost 7 years ago

There's a redmine package for debian, you might want to contact the maintainer if your script does more/better than the existing one :-)

RE: Debian init script for Redmine - Added by Felix Schäfer almost 7 years ago

Oh, and even though it's of no use to me, thanks for sharing!

RE: Debian init script for Redmine - Added by Jared S almost 7 years ago

Wow... didn't even realize there was a debian package, did mine from source, ill check with the package maintainer...thanks!

RE: Debian init script for Redmine - Added by Jérémy Lal almost 7 years ago

The debian package can only provide this init script as an example,
since there are many other legitimate ways (like mod_passenger, spawn-fcgi + runit) to start
redmine.
Comment about your script : you source /lib/lsb/init-functions, but do not use it ?

RE: Debian init script for Redmine - Added by Jared S almost 7 years ago

Comment about your script : you source /lib/lsb/init-functions, but do not use it ?

Yes, I've never written an init script (or done any linux scripting) before so this is pieced together from several other example scripts so there may be unnecessary material in there. I will remove those lines if they are not needed.... not really sure what init-functions does, will have to study that further :D...

Was not aware of these other ways to start it, I may want to look into those for myself as well...

Thank you for your feedback..

(1-5/5)