Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upstart Script for the PlayFramework 1.x
# Upstart script for a play application that binds to an unprivileged user.
# put this into a file like /etc/init/playframework
# you can then start/stop it using either initctl or start/stop/restart
# e.g.
# start playframework
# http://dominikdorn.com
description "Description of your app"
author "Dominik Dorn <dominik@studyguru.eu>"
version "1.0"
env PLAY_BINARY=/opt/play/current/play
env HOME=/home/sgwebsite/apps/playapp/
env USER=sgwebsite
env GROUP=sgwebsite
env PROFILE=hyper
start on (filesystem and net-device-up IFACE=lo) or runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
umask 022
expect fork
pre-start script
test -x $PLAY_BINARY || { stop; exit 0; }
test -c /dev/null || { stop; exit 0; }
chdir ${HOME}
rm ${HOME}/server.pid || true
$PLAY_BINARY dependencies $HOME
end script
pre-stop script
exec $PLAY_BINARY stop $HOME
end script
post-stop script
rm ${HOME}/server.pid || true
end script
script
exec start-stop-daemon --start --exec $PLAY_BINARY --chuid $USER:$GROUP --chdir $HOME -- start $HOME --%$PROFILE
end script
@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Mar 13, 2012

@domdorn

This comment has been minimized.

Copy link
Owner Author

@domdorn domdorn commented Mar 13, 2012

@ripper234: Thanks, I've merged you're changes.

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Apr 2, 2012

BTW, if one wants to stop play ... what's the correct way to do this with upstart?
Running play stop will just make upstart spawn another process.

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Apr 2, 2012

Sorry, found in already (once before as well): sudo service playframework stop.
AND, now that I scroll up I see you have documented this above!!! Silly me.

@domdorn

This comment has been minimized.

Copy link
Owner Author

@domdorn domdorn commented Apr 2, 2012

@jurajmasar

This comment has been minimized.

Copy link

@jurajmasar jurajmasar commented Jun 28, 2012

Just a couple of details that might save somebody some time. In order to get this to work on ubuntu 12.04 I had to:

  • put this script to /etc/init/playframework.conf instead of /etc/init/playframework
  • use commands sudo service playframework start/stop/restart/status to control the script.

Great work, btw!

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Aug 26, 2012

If I wanted to specify extra JVM flags (e.g. -Xmx1G) using this script ... what would be a good way to do it?

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Aug 26, 2012

It seems the answer is simply adding the flags after the script command. E.g.

exec start-stop-daemon --start --exec $PLAY_BINARY --chuid $USER:$GROUP --chdir $HOME -- start $HOME --%$PROFILE -Xmx1G

@jtammen

This comment has been minimized.

Copy link

@jtammen jtammen commented Oct 25, 2012

I'm trying to get that upstart script work for a play1-2.5 app on a Ubuntu 12.04.1 LTS box (free Amazon EC2 micro instance). The app gets started and stopped as expected, but sudo start/stop myapp never returns and keeps waiting for ever with no output. Ultimately, I have to restart the machine in order to be able to start the service again. I' wondering if this might be related to this bug report...

Anyone managed to get this working under this environment?

@mcmug8

This comment has been minimized.

Copy link

@mcmug8 mcmug8 commented Feb 27, 2013

Quick question is, which location should I save this script to in my ubuntu env?

Thanks,
Tim

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Mar 5, 2013

@mcmug8 - in /etc/init/ - this is where upstart saves its service scripts.
@jtammen - I'm seeing the same issue on ubuntu 12.10, dunno why. It worked well for us on 11.04 for some time.

@ripper234

This comment has been minimized.

Copy link

@ripper234 ripper234 commented Mar 5, 2013

@jtammen - this indeed was the problem for me.
The fix was:

  1. Change 'expect fork' to 'expect daemon'
  2. sudo initctl reload-configuration
  3. Restart the machine (this step is mandatory for some reason)
@stenlylee

This comment has been minimized.

Copy link

@stenlylee stenlylee commented Aug 19, 2013

What's the meaning of profile=hyper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment