| 1 |
#! /bin/sh |
| 2 |
### BEGIN INIT INFO |
| 3 |
# Provides: github-webhook-ofiwg |
| 4 |
# Required-Start: |
| 5 |
# Required-Stop: |
| 6 |
# Default-Start: |
| 7 |
# Default-Stop: 0 |
| 8 |
# Short-Description: Run the Github webhook for ofiwg |
| 9 |
# Description: |
| 10 |
### END INIT INFO |
| 11 |
|
| 12 |
PATH=/sbin:/usr/sbin:/bin:/usr/bin |
| 13 |
[ -f /etc/default/github-webhook-ofiwg ] && . /etc/default/github-webhook-ofiwg |
| 14 |
|
| 15 |
. /lib/lsb/init-functions |
| 16 |
|
| 17 |
RETVAL=0 |
| 18 |
prog="/var/www/html/github-webhooks/ofiwg/verify-signed-off.rb" |
| 19 |
desc="Github webhook listener for ofiwg" |
| 20 |
pidfile="/var/run/github-webhook-ofiwg.pid" |
| 21 |
|
| 22 |
do_start() { |
| 23 |
[ -x $prog ] || exit 5 |
| 24 |
|
| 25 |
log_action_msg "Starting $desc" |
| 26 |
|
| 27 |
pid=`ps -eadf | grep "ruby $prog" | grep -v grep | awk '{ print $2 }'` |
| 28 |
if test -z "$pid"; then |
| 29 |
$prog > /dev/null 2>&1 & |
| 30 |
RETVAL=$? |
| 31 |
else |
| 32 |
RETVAL=1 |
| 33 |
fi |
| 34 |
[ $RETVAL -eq 0 ] && log_success_msg |
| 35 |
[ $RETVAL -ne 0 ] && log_failure_msg |
| 36 |
log_end_msg $RETVAL |
| 37 |
return $RETVAL |
| 38 |
} |
| 39 |
|
| 40 |
do_stop() { |
| 41 |
[ -x $prog ] || exit 5 |
| 42 |
|
| 43 |
log_action_msg "Stopping $desc" |
| 44 |
pid=`ps -eadf | grep "ruby $prog" | grep -v grep | awk '{ print $2 }'` |
| 45 |
if test -n "$pid"; then |
| 46 |
kill $pid > /dev/null 2>&1 |
| 47 |
RETVAL=$? |
| 48 |
else |
| 49 |
RETVAL=1 |
| 50 |
fi |
| 51 |
[ $RETVAL -eq 0 ] && log_success_msg |
| 52 |
[ $RETVAL -ne 0 ] && log_failure_msg |
| 53 |
log_end_msg $RETVAL |
| 54 |
return $RETVAL |
| 55 |
} |
| 56 |
|
| 57 |
do_restart() { |
| 58 |
do_stop |
| 59 |
sleep 1 |
| 60 |
do_start |
| 61 |
} |
| 62 |
|
| 63 |
case "$1" in |
| 64 |
start) |
| 65 |
do_start |
| 66 |
;; |
| 67 |
restart) |
| 68 |
do_restart |
| 69 |
;; |
| 70 |
reload|force-reload) |
| 71 |
log_action_msg "Error: argument '$1' not supported" |
| 72 |
log_action_end_msg 7 |
| 73 |
exit 7 |
| 74 |
;; |
| 75 |
stop) |
| 76 |
do_stop |
| 77 |
;; |
| 78 |
*) |
| 79 |
log_action_msg "Usage: $0 start|stop|restart" |
| 80 |
log_action_end_msg 3 |
| 81 |
exit 3 |
| 82 |
;; |
| 83 |
esac |
| 84 |
|
| 85 |
exit $RETVAL |