Last active
November 15, 2018 08:21
-
-
Save sato11/6ffd9bfa8338dd5b2e9d7b43904140f6 to your computer and use it in GitHub Desktop.
init script to daemonize digdag server.
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 | |
# digdag daemon | |
# chkconfig: 345 20 80 | |
# description: digdag daemon | |
# processname: digdag | |
# Credit: https://werxltd.com/wp/2012/01/05/simple-init-d-script-template/ | |
source /home/user_name/.bashrc | |
source /home/user_name/.bash_profile | |
CMD="/home/user_name/bin/digdag server" | |
DIGDAG_DIR="/path/to/repo" | |
LOG_DIR="${APP_DIR}/logs" | |
OPTS="-c ${DIGDAG_DIR}/digdag.properties -A ${LOG_DIR}/accesslogs -O ${LOG_DIR}/tasklogs -L ${LOG_DIR}/server.log" | |
NAME=digdag | |
PIDFILE="${APP_DIR}/tmp/pids/$NAME.pid" | |
case "$1" in | |
start) | |
printf "%-50s" "Starting $NAME..." | |
cd $DIGDAG_DIR | |
PID=`$CMD $OPTS > /dev/null 2>&1 & echo $!` | |
if [ -z $PID ]; then | |
printf "%s\n" "Fail" | |
else | |
echo $PID > $PIDFILE | |
printf "%s\n" "Ok" | |
fi | |
;; | |
status) | |
printf "%-50s" "Checking $NAME..." | |
if [ -f $PIDFILE ]; then | |
PID=`cat $PIDFILE` | |
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then | |
printf "%s\n" "Process dead but pidfile exists" | |
else | |
echo "Running" | |
fi | |
else | |
printf "%s\n" "Service not running" | |
fi | |
;; | |
stop) | |
printf "%-50s" "Stopping $NAME" | |
PID=`cat $PIDFILE` | |
cd $DIGDAG_DIR | |
if [ -f $PIDFILE ]; then | |
kill -HUP $PID | |
printf "%s\n" "Ok" | |
rm -f $PIDFILE | |
else | |
printf "%s\n" "pidfile not found" | |
fi | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
*) | |
echo "Usage: $0 {status|start|stop|restart}" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment