Skip to content

Instantly share code, notes, and snippets.

@andrericardo
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrericardo/0b0e793f65e379e30072 to your computer and use it in GitHub Desktop.
Save andrericardo/0b0e793f65e379e30072 to your computer and use it in GitHub Desktop.
#!/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