Skip to content

Instantly share code, notes, and snippets.

@kyleparisi
Last active January 2, 2018 15:01
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 kyleparisi/45f0046ab70f5cb776c44420a862a19e to your computer and use it in GitHub Desktop.
Save kyleparisi/45f0046ab70f5cb776c44420a862a19e to your computer and use it in GitHub Desktop.
init.d script for java jar
vi /etc/init.d/java-app
chmod +x /etc/init.d/java-app
/etc/init.d/java-app start
# reminder:
# chown -R www-data: /needed/paths
#!/bin/sh
### BEGIN INIT INFO
# Provides: java-app
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the java jar app
# Description: starts the java jar app
### END INIT INFO
PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME="java-app"
APP_HOME="/var/www/default"
LOGFILE="/var/log/java-app.log"
PIDFILE="/var/run/java-app.pid"
DAEMON="/usr/bin/java"
ARGUMENTS="-jar /var/www/default/app.jar"
USER="www-data"
GROUP="www-data"
set -e
case "$1" in
start)
echo -n "Starting $NAME: "
export $(grep -v '^#' /etc/environment | xargs)
start-stop-daemon --start --quiet --chdir $APP_HOME --pidfile $PIDFILE -c $USER:$GROUP --make-pidfile --background --exec $DAEMON -- $ARGUMENTS
echo "."
;;
stop)
echo -n "Stopping $NAME: "
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
echo -n "Restarting $NAME: "
export $(grep -v '^#' /etc/environment | xargs)
start-stop-daemon --stop --quiet --pidfile $PIDFILE
start-stop-daemon --start --quiet --chdir $HUBOT_HOME --pidfile $PIDFILE -c $USER:$GROUP --make-pidfile --background --exec $DAEMON -- $ARGUMENTS
echo "."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}" >&2
exit 1
;;
esac
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment