Ubuntu Pastebin

Paste from moloney at Thu, 8 Oct 2015 23:00:08 +0000

Download as text
 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
#!/bin/bash
### BEGIN INIT INFO
# Provides:          haroute
# Required-Start:    $all
# Required-Stop:     $local_fs
# Default-Start:     3
# Default-Stop:      0 6
# Short-Description: Control haroute daemon for high availability routing
### END INIT INFO
NAME="haroute"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
PID_FILE=/var/run/haroute.pid
LOG_FILE=/var/log/haroute.log

get_pid() {
    cat "$PID_FILE"
}

is_running() {
    [ -f "$PID_FILE" ] && ps `get_pid` > /dev/null 2>&1
}

start_haroute() {
    sleep 5
    haroute -p $PID_FILE --log-file $LOG_FILE & disown
}

stop_haroute() {
    kill `get_pid`
}

case "$1" in
    start)
        if is_running; then
            echo "Already started"
        else
            echo "Starting $NAME"
            start_haroute
        fi
        ;;
    stop)
        if is_running; then
            echo "Stopping $NAME"
            stop_haroute
        else
            echo "Not Running"
        fi
        ;;
    restart)
        stop_haroute
        start_haroute
        ;;
    status)
        if is_running; then
            echo "Running"
        else
            echo "Stopped"
            exit 1
        fi
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac

exit 0
Download as text