-
Notifications
You must be signed in to change notification settings - Fork 9
/
hubot.init.d.centos.sh
executable file
·73 lines (65 loc) · 1.82 KB
/
hubot.init.d.centos.sh
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: hubot
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: hubot init script
# Description: hubot is a friendly chatbot
### END INIT INFO
# Author: Tomas Varaneckas <tomas.varaneckas@gmail.com>
# Source function library.
. /etc/rc.d/init.d/functions
DESC="Hubot ${NAME} bot"
NAME=hubot
USER=hubot
GROUP=hubot
BOT_PATH=/home/hubot/campfire
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:$BOT_PATH/node_modules:$BOT_PATH/node_modules/hubot/node_modules
DAEMON=$BOT_PATH/bin/$NAME
DAEMON_ARGS="--adapter campfire --name hubot"
PIDFILE=$BOT_PATH/$NAME.pid
LOGFILE=$BOT_PATH/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present
[ -r $BOT_PATH/hubot.conf ] && . $BOT_PATH/hubot.conf
case "$1" in
start)
status="0"
status -p ${PIDFILE} ${NAME} > /dev/null || status="$?"
if [ "$status" = 0 ]; then
status -p ${PIDFILE} ${NAME}
exit 2
fi
touch $PIDFILE && chown $USER:$GROUP $PIDFILE
if [ "$(whoami)" != "$USER" ]; then
runuser -c "[ -r $BOT_PATH/hubot.conf ] && . $BOT_PATH/hubot.conf && \
cd $BOT_PATH && $DAEMON $DAEMON_ARGS" - $USER >> \
${LOGFILE} 2>&1 &
sleep 2
PID=`pgrep -u $USER node`
echo $PID > $PIDFILE
else
(cd $BOT_PATH; $DAEMON $DAEMON_ARGS >> ${LOGFILE} 2>&1 & echo $! > $PIDFILE)
fi
status -p ${PIDFILE} ${NAME}
;;
stop)
killproc -p ${PIDFILE} ${NAME} -INT
rm -f ${PIDFILE}
status -p ${PIDFILE} ${NAME}
;;
status)
status -p ${PIDFILE} ${NAME}
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
# vim:ft=sh