Created
July 24, 2015 13:50
-
-
Save efarem/7dfbfba1a8b43199f23b to your computer and use it in GitHub Desktop.
Git Auto Deploy init script for CentOS 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# /etc/init.d/gitautodeploy | |
# | |
# Service manager for GitAutoDeploy | |
# | |
# chkconfig: 345 70 30 | |
# description: Git Auto Deploy is a simple HTTP server for accepting push notifications from GitLab | |
# processname: gitautodeploy | |
# Source function library. | |
. /etc/init.d/functions | |
SERVICENAME="gitautodeploy" | |
SERVICEPATH="/root/GitDeploy" | |
LOCKFILE="/var/lock/subsys/$SERVICENAME" | |
PROGRAM="GitAutoDeploy.py" | |
PROGRAMOPTIONS="--daemon-mode" | |
USER="root" | |
start() { | |
cd $SERVICEPATH || exit 1 | |
if [ ! -f $LOCKFILE ]; then | |
daemon --user $USER ./$PROGRAM $PROGRAMOPTIONS | |
RETVAL=$? | |
echo -n "Starting $SERVICENAME: " | |
[ $RETVAL -eq 0 ] && touch $LOCKFILE | |
else | |
echo "Service is already running" | |
RETVAL=0 | |
fi | |
echo | |
return $RETVAL | |
} | |
stop() { | |
echo -n "Shutting down $SERVICENAME: " | |
if [ -f $LOCKFILE ]; then | |
kill -9 $(ps aux | grep -m 1 $PROGRAM | awk {'print $2'}) && success || failure | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE | |
else | |
echo "Service is not running" | |
RETVAL=0 | |
fi | |
echo | |
return $RETVAL | |
} | |
status() { | |
if [ -f $LOCKFILE ]; then | |
echo "Status: Running" | |
else | |
echo "Status: Not Running" | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo "Usage: $SERVICENAME {start|stop|status|restart}" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment