Skip to content

Instantly share code, notes, and snippets.

@rohansingh
Last active August 29, 2015 14:04
Show Gist options
  • Save rohansingh/d1264d48393522672430 to your computer and use it in GitHub Desktop.
Save rohansingh/d1264d48393522672430 to your computer and use it in GitHub Desktop.
Debian/Upstart files for a Java service

This is an example for adding native Upstart support to the Debian package for a Java service.

The default and upstart files should both be placed in your debian packaging directory, giving you a final tree that looks something like:

+ debian/
  - control
  - default
  - upstart
  ...

Note that you will have to replace some tokens in the upstart file with your actual service name and JAR path.

ENABLED=yes
# options to pass the JVM (-Xms, -Xmx, etc)
JAVA_OPTS=
# options to pass the service
OPTS=
description "my java service"
start on runlevel [2345]
stop on runlevel [!2345]
# never stop trying to respawn
respawn
respawn limit unlimited
env DEFAULTFILE=/etc/default/myservice
pre-start script
[ -f $DEFAULTFILE ] && . $DEFAULTFILE
# don't start unless explicitly enabled in config
if [ -z "$ENABLED" ] ; then
stop; exit 0;
fi
end script
script
[ -f $DEFAULTFILE ] && . $DEFAULTFILE
exec java $JAVA_OPTS -jar /path/to/myservice.jar $OPTS
end script
# prevent respawning more than once every second
post-stop exec sleep 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment