Project

General

Profile

Debian init script for Redmine ยป redmine.txt

Jared S, 2011-01-01 20:50

 
1

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

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

    
22
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
23
DESC="Redmine Daemon"
24
NAME1="redmine"
25
NAME2="mongrel"
26
RUBY=/usr/bin/ruby
27
LOC=/var/www/redmine
28
RUBY="/usr/bin/ruby"
29
DAEMON1="mongrel_rails start"
30
DAEMON1_ARGS="-d -e production"
31
PIDFILE1=$LOC/log/$NAME2.pid
32
LOG1=/var/log/redmine.log
33

    
34

    
35
#[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
36
# Load the VERBOSE setting and other rcS variables
37
#[ -f /etc/default/rcS ] && . /etc/default/rcS
38
# Define LSB log_* functions. Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
39
. /lib/lsb/init-functions
40
# Start Redmine in daemon mode
41
start(){
42
 REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
43
        if [ "x$REDMINEPID" = "x" ] && [ -f $PIDFILE1 ]; then
44
                echo "" >> $LOG1
45
                echo `date` " * No $NAME1 process found... but PID file left in $PIDFILE1" | tee -a $LOG1
46
                echo "Deleting PID!" | tee -a $LOG1
47
                echo "" >> $LOG1
48
                rm $PIDFILE1
49
        elif [ "x$REDMINEPID" != "x" ]; then
50
                echo `date` " * $NAME1 appears to be already running!" | tee -a $LOG1
51
                exit
52
        fi
53
        su - redmine -c "cd $LOC; $DAEMON1 $DAEMON1_ARGS"
54
        echo `date` " * Starting $NAME1..." | tee -a $LOG1
55
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
56
        if [ "x$REDMINEPID" = "x" ]; then
57
                echo `date` " * $NAME1 failed to start!" | tee -a $LOG1
58
                exit
59
        fi
60
}
61
# Stop Redmine daemon
62
stop(){
63
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
64
        if [ "x$REDMINEPID" != "x" ]; then
65
                kill -2 $REDMINEPID
66
                echo `date` " * Stopping $NAME1..." | tee -a $LOG1
67
                REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
68
                if [ "x$REDMINEPID" != "x" ]; then
69
                        echo `date` " * $NAME1 stopped..." | tee -a $LOG1
70
                elif [ "x$REDMINEPID" = "x" ]; then
71
                        echo `date` " * $NAME1 failed to stop!" | tee -a $LOG1
72
                fi
73
        elif [ "x$REDMINEPID" = "x" ]; then
74
                echo `date` >> $LOG1
75
                echo "" >> $LOG1
76
                echo " * $NAME1 does not appear to be running!" | tee -a $LOG1
77
                exit
78
        fi
79
}
80
# Check if Redmine is running
81
status(){
82
        REDMINEPID=`ps aux | grep "$DAEMON1 " | grep -v grep | awk '{print $2}'`
83
        if [ "x$REDMINEPID" = "x" ]; then
84
                echo " * $NAME1 is not running"
85
        else
86
                echo " * $NAME1 is running"
87
        fi
88
}
89
case "$1" in
90
        start)
91
                start
92
                ;;
93
        stop)
94
                stop
95
                ;;
96
        status)
97
                status
98
                ;;
99
        restart|force-reload)
100
                stop
101
                start
102
                ;;
103
        *)
104
                echo "Usage: $0 {start|stop|restart|force-reload|status}"
105
                exit 1
106
esac
    (1-1/1)