| 1 |
#!/bin/sh |
| 2 |
### BEGIN INIT INFO |
| 3 |
# Provides: errbot |
| 4 |
# Required-Start: $local_fs $network $remote_fs $syslog |
| 5 |
# Required-Stop: $local_fs $network $remote_fs $syslog |
| 6 |
# Default-Start: 2 3 4 5 |
| 7 |
# Default-Stop: 0 1 6 |
| 8 |
# Short-Description: Chatbot designed to be simple to extend with plugins written in Python |
| 9 |
# Description: Errbot is a chatbot. It allows you to start scripts interactively from your |
| 10 |
# chatrooms for any reason: random humour, chatops, starting a build, monitoring |
| 11 |
# commits, triggering alerts... |
| 12 |
### END INIT INFO |
| 13 |
|
| 14 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 15 |
|
| 16 |
NAME=errbot |
| 17 |
DAEMON=/usr/bin/errbot |
| 18 |
DESC="Errbot chat bot" |
| 19 |
PIDFILE=/var/lib/$NAME/data/err.pid |
| 20 |
SCRIPTNAME=/etc/init.d/$NAME |
| 21 |
CONFIGFILE=/etc/$NAME/config-template.py |
| 22 |
|
| 23 |
if test -f /etc/default/$NAME; then |
| 24 |
. /etc/default/$NAME |
| 25 |
fi |
| 26 |
|
| 27 |
# Exit if the package is not installed |
| 28 |
[ -x "$DAEMON" ] || exit 0 |
| 29 |
|
| 30 |
. /lib/init/vars.sh |
| 31 |
|
| 32 |
. /lib/lsb/init-functions |
| 33 |
|
| 34 |
errbot_start() |
| 35 |
{ |
| 36 |
if [ -f "$PIDFILE" ]; then |
| 37 |
log_failure_msg "$DESC is running already." |
| 38 |
exit 1 |
| 39 |
fi |
| 40 |
|
| 41 |
if ! id $USER >/dev/null 2>&1; then |
| 42 |
log_failure_msg "USER $USER does not exist." |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
start-stop-daemon --start --exec $DAEMON --chuid $NAME -- -c $CONFIGFILE -d -p $PIDFILE |
| 47 |
} |
| 48 |
|
| 49 |
errbot_stop() |
| 50 |
{ |
| 51 |
if [ -f "$PIDFILE" ]; then |
| 52 |
start-stop-daemon --stop --signal INT --user $NAME --pidfile $PIDFILE |
| 53 |
rm -f $PIDFILE |
| 54 |
fi |
| 55 |
} |
| 56 |
|
| 57 |
errbot_status() { |
| 58 |
if [ ! -e $PIDFILE ]; then |
| 59 |
status_of_proc "${DAEMON}" "${DESC}" |
| 60 |
else |
| 61 |
status_of_proc -p "${PIDFILE}" "${DAEMON}" "${DESC}" |
| 62 |
fi |
| 63 |
} |
| 64 |
|
| 65 |
case "$1" in |
| 66 |
start) |
| 67 |
log_begin_msg "Starting ${DESC}" |
| 68 |
errbot_start |
| 69 |
log_end_msg $? |
| 70 |
;; |
| 71 |
stop) |
| 72 |
log_begin_msg "Stopping ${DESC}" |
| 73 |
errbot_stop |
| 74 |
log_end_msg $? |
| 75 |
;; |
| 76 |
status) |
| 77 |
erbot_status |
| 78 |
;; |
| 79 |
restart|reload|force-reload) |
| 80 |
log_begin_msg "Restarting ${DESC}" |
| 81 |
errbot_stop |
| 82 |
errbot_start |
| 83 |
log_end_msg $? |
| 84 |
;; |
| 85 |
*) |
| 86 |
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" |
| 87 |
exit 1 |
| 88 |
;; |
| 89 |
esac |