Skip to content

Instantly share code, notes, and snippets.

@gunlock
Last active August 29, 2015 14:05
Show Gist options
  • Save gunlock/a7c0cf36221d71f8792b to your computer and use it in GitHub Desktop.
Save gunlock/a7c0cf36221d71f8792b to your computer and use it in GitHub Desktop.
dcm4chee daemon script for unbuntu
#!/bin/sh
# Author: Michael Gunlock 2014
### BEGIN INIT INFO
# Provides: dcm4chee
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: dcm4chee daemon
# Description:
### END INIT INFO
DAEMON_NAME="dcm4chee"
DAEMON=/home/pacs/run.sh
USER=pacs
UUID="f5c87eec67494f338a1f544a2595b790"
# Get lsb functions
. /lib/lsb/init-functions
getpid() {
echo `ps aux | grep $UUID | grep -v grep | awk {'print$2'}`
}
case "$1" in
start)
log_begin_msg "Starting $DAEMON_NAME service..."
pid=$(getpid)
if [ -z "$pid" ]; then
su - $USER -c "${DAEMON} ${UUID}"
fi
sleep 2
pid=$(getpid)
if [ -z "$pid" ]; then
log_end_msg 1
else
log_end_msg 0
fi
;;
stop)
log_begin_msg "Stopping $DAEMON_NAME..."
pid=$(getpid)
if [ ! -z "$pid" ]; then
kill $pid 2>/dev/null
timeout=20 #seconds
stopped=false
while [ $timeout -gt 0 ]; do
pid=$(getpid)
if [ -z "$pid" ]; then
stopped=true
break
fi
timeout=$(($timeout -1))
sleep 1
done
if $stopped; then
log_end_msg 0
else
log_end_msg 1
exit 1
fi
else
log_end_msg 0
fi
;;
restart)
$0 stop
if [ $? -eq 0 ]; then
$0 start
fi
;;
status)
pid=$(getpid)
if [ -z "$pid" ]; then
echo "$DAEMON_NAME is not running"
else
echo "$DAEMON_NAME is running"
fi
;;
*)
echo "Usage $DAEMON_NAME {start|stop|restart|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment