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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#!/bin/bash
#
# github-webhook-ofiwg This starts and stops the ofiwg github webhook Ruby Sinatra server
#
# chkconfig: 345 56 50
# description: Simple Ruby Sinatra server to answer Github webhook \
# pings to check for Signed-off-by lines in Github \
# pull request commit messages.
#
# processname: /usr/bin/ruby
# pidfile: /var/run/github-webhook-ofiwg.pid
### BEGIN INIT INFO
# Provides:
# Required-Start: $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop github-webhook-ofiwg
# Description: Simple Ruby Sinatra server to answer Github webhook \
# pings to check for Signed-off-by lines in Github \
# pull request commit messages.
### END INIT INFO
PATH=/sbin:/bin:/usr/bin:/usr/sbin
# Source function library.
. /etc/init.d/functions
# Get config.
test -f /etc/sysconfig/network && . /etc/sysconfig/network
# Need to export GITHUB_AUTH_TOKEN in this file. This token should be
# obtained from https://github.com/settings/tokens for a user who is
# authorized to set status messages on the target repo(s).
test -f /etc/sysconfig/github-webhook-ofiwg && . /etc/sysconfig/github-webhook-ofiwg
RETVAL=0
prog="/var/www/github-webhooks/ofiwg/verify-signed-off.rb"
desc="Github webhook listener for ofiwg"
pidfile="/var/run/github-webhook-ofiwg.pid"
start(){
[ -x $prog ] || exit 5
# this is suitable way considering SELinux is guarding write
# access to PID file
[ $EUID -eq 0 ] || exit 4
echo -n $"Starting $desc: "
pid=`ps -eadf | grep "ruby $prog" | grep -v grep | awk '{ print $2 }'`
if test -z "$pid"; then
$prog > /dev/null 2>&1 &
RETVAL=$?
else
RETVAL=1
fi
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
echo
return $RETVAL
}
stop(){
[ -x $prog ] || exit 5
# this is suitable way considering SELinux is guarding write
# access to PID file
[ $EUID -eq 0 ] || exit 4
echo -n $"Stopping $desc: "
pid=`ps -eadf | grep "ruby $prog" | grep -v grep | awk '{ print $2 }'`
if test -n "$pid"; then
kill $pid > /dev/null 2>&1
RETVAL=$?
else
RETVAL=1
fi
[ $RETVAL -eq 0 ] && echo_success
[ $RETVAL -ne 0 ] && echo_failure
echo
return $RETVAL
}
restart(){
stop
sleep 1
start
}
# See how we were called.
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
restart)
restart
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
RETVAL=2
esac
exit $RETVAL
|