#!/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