summaryrefslogtreecommitdiff
path: root/share/init.d/plinth
blob: 8cf88a93c851b01c94c6919af75bd6c63d44c14e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
### BEGIN INIT INFO
# Provides:          plinth
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: plinth web frontend
# Description:
#
### END INIT INFO

# This file is /etc/init.d/plinth
DAEMON=/usr/local/bin/plinth.py
EXMACHINA_DAEMON=/usr/local/bin/exmachina.py
PID_FILE=/var/run/plinth.pid
EXMACHINA_PID_FILE=/var/run/exmachina.pid

PLINTH_USER=www-data
PLINTH_GROUP=www-data

test -x $DAEMON || exit 0
test -x $EXMACHINA_DAEMON || exit 0

set -e

. /lib/lsb/init-functions

start_plinth (){
    if [ -f $PID_FILE ]; then
      echo Already running with a pid of `cat $PID_FILE`.
    else
        if [ -f $EXMACHINA_PID_FILE ]; then
        echo exmachina was already running with a pid of `cat $EXMACHINA_PID_FILE`.
        kill -15 `cat $EXMACHINA_PID_FILE`
        rm -rf $EXMACHINA_PID_FILE
        fi
        SHAREDKEY=`$EXMACHINA_DAEMON --random-key`
        touch $PID_FILE
        chown $PLINTH_USER:$PLINTH_GROUP $PID_FILE
        echo $SHAREDKEY | $EXMACHINA_DAEMON --pidfile=$EXMACHINA_PID_FILE || rm $PID_FILE
        sleep 0.5
        echo $SHAREDKEY | sudo -u $PLINTH_USER -g $PLINTH_GROUP $DAEMON --pidfile=$PID_FILE
    fi
}

stop_plinth () {
    if [ -f $PID_FILE ]; then
	kill -15 `cat $PID_FILE` || true
	rm -rf $PID_FILE
    echo "killed plinth"
    else
	echo "No pid file at $PID_FILE suggests plinth is not running."
    fi
    if [ -f $EXMACHINA_PID_FILE ]; then
	kill -15 `cat $EXMACHINA_PID_FILE` || true
	rm -rf $EXMACHINA_PID_FILE
    echo "killed exmachina"
    else
	echo "No pid file at $EXMACHINA_PID_FILE suggests exmachina is not running."
    fi
}

test -x $DAEMON || exit 0
case "$1" in 
    start)
        echo "Starting Plinth."
        start_plinth
        ;;
    stop)
        echo "Stoping Plinth."
        stop_plinth
        ;;
    restart)
        $0 stop
        $0 start
        ;;
	status)
		status_of_proc -p $PID_FILE "$DAEMON" plinth && exit 0 || exit $?
		;;
	*)
		echo "Usage: $NAME {start|stop|restart|status}" >&2
		exit 1
		;;
        
esac