~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/gozerbot

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
### BEGIN INIT INFO
4
 
# Provides:          gozerbot
5
 
# Required-Start:    $local_fs $remote_fs $network $named
6
 
# Required-Stop:     $local_fs $remote_fs
7
 
# Default-Start:     2 3 4 5
8
 
# Default-Stop:      0 1 6
9
 
# Short-Description: Gozerbot IRC and Jabber bot
10
 
# Description:       Gozerbot is an IRC and Jabber bot written in Python.
11
 
### END INIT INFO
12
 
 
13
 
NAME=gozerbot
14
 
DESC="Gozerbot IRC robot"
15
 
DATADIR=/var/lib/gozerbot
16
 
PIDFILE=$DATADIR/gozerbot.pid
17
 
LOGFILE=/var/log/gozerbot.log
18
 
 
19
 
PID=`cat $PIDFILE` 2>/dev/null
20
 
 
21
 
# Include gozerbot defaults if available
22
 
if [ -f /etc/default/gozerbot ] ; then
23
 
    . /etc/default/gozerbot
24
 
fi
25
 
 
26
 
if [ "$RUN" != "yes" ] ; then
27
 
    echo "$NAME disabled; edit /etc/default/gozerbot"
28
 
    exit 0
29
 
fi
30
 
 
31
 
if [ -z "$RUNUSER" ] ; then
32
 
    RUNUSER=gozerbot
33
 
fi
34
 
 
35
 
status()
36
 
{
37
 
        test -n "$PID" && ps auxw | grep -v grep | grep gozerbot | grep -q -s " $PID " && return 0
38
 
        return 1
39
 
}
40
 
 
41
 
stop()
42
 
{
43
 
        if status
44
 
        then
45
 
                kill -KILL $PID
46
 
        fi
47
 
}
48
 
 
49
 
start()
50
 
{
51
 
        status && exit 1 # already running
52
 
        if [ -e $DATADIR ]
53
 
        then
54
 
          cd $DATADIR
55
 
        else
56
 
          mkdir -p $DATADIR
57
 
          cd $DATADIR
58
 
        fi
59
 
        if [ -e gozerdata/mainconfig ]
60
 
        then
61
 
           su $RUNUSER -c "$NAME >> /var/log/gozerbot.log 2>&1 &"
62
 
        else
63
 
           su $RUNUSER -c gozerbot-init
64
 
           rm -rf /etc/gozerbot
65
 
           ln -s /var/lib/gozerbot/gozerdata /etc/gozerbot
66
 
           echo ""
67
 
           echo "A default config file /etc/gozerbot/mainconfig has been created."
68
 
           echo "irc and jabber bot example files are installed in /etc/gozerbot/fleet."
69
 
           echo "Please edit those files and then run this script again to start gozerbot."
70
 
        fi
71
 
}
72
 
 
73
 
case "$1" in
74
 
start)
75
 
        echo -n "Starting $DESC: $NAME"
76
 
        start
77
 
        case "$?" in
78
 
                0) echo "." ; exit 0 ;;
79
 
                1) echo " (already running)." ; exit 0 ;;
80
 
                *) echo " (failed)." ; exit 1 ;;
81
 
        esac
82
 
        ;;
83
 
stop)
84
 
        echo -n "Stopping $DESC: $NAME"
85
 
        stop
86
 
        case "$?" in
87
 
                0) echo "." ; exit 0 ;;
88
 
                1) echo " (not running)." ; exit 0 ;;
89
 
                *) echo " (failed)." ; exit 1 ;;
90
 
        esac
91
 
        ;;
92
 
restart|force-reload|reload)
93
 
        echo -n "Restarting $DESC: $NAME"
94
 
        stop
95
 
        start
96
 
        ;;
97
 
status)
98
 
        echo -n "Status of $DESC service: "
99
 
        status
100
 
        case "$?" in
101
 
                0) echo "running." ; exit 0 ;;
102
 
                1) echo "not running." ; exit 3 ;;
103
 
        esac
104
 
        ;;
105
 
*)
106
 
        echo "Usage: /etc/init.d/gozerbot {start|stop|reload|force-reload|restart|status}" >&2
107
 
        exit 1
108
 
        ;;
109
 
esac
110
 
 
111
 
*t