Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/sh
# /etc/init.d/dropwizard-gradle
#
# Some things that run always
touch /var/lock/dropwizard-gradle
user="andric87"
DROPWIZARD_DIR=/home/andric87/dropwizard-gradle
JAR="$DROPWIZARD_DIR/dropwizard-gradle-standalone.jar"
CONFIG="$DROPWIZARD_DIR/helloworld.yml"
CMD="java -jar $JAR server $CONFIG"
name=`basename $0`
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
pid_file="/var/run/$name.pid"
isRunning() {
[ -f "$pid_file" ] && ps `cat $pid_file` > /dev/null 2>&1
}
# Carry out specific functions when asked to by the system
case $1 in
start)
if isRunning; then
echo "Already started"
else
echo "Starting $name"
sudo -u "$user" $CMD > "$stdout_log" 2> "$stderr_log" & echo $! > "$pid_file"
if ! isRunning; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if isRunning; then
echo "Stopping $name"
kill `cat $pid_file`
rm "$pid_file"
else
echo "Not running"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $name {start|stop|restart}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment