Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upstart script for Play Framework 2.0
# Upstart script for a play application that binds to an unprivileged user.
# put this into a file like /etc/init/play.conf
#
# This could be the foundation for pushing play apps to the server using something like git-deploy
# By calling service play stop in the restart command and play-start in the restart command.
#
# Usage:
# start play
# stop play
# restart play
#
# WARNING: This is still beta, I have not tested the respawning functionality, but it should work.
#
# http://leon.radley.se
description "PlayFramework 2"
author "Leon Radley <leon@radley.se>"
version "1.0"
env USER=myuser
env GROUP=www-data
env HOME=/home/myuser/app
env PORT=9000
env ADDRESS=127.0.0.1
env CONFIG=production.conf
env SBTMEM=256
env EXTRA="-Xms128M -Xmx512m -server"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
umask 022
expect daemon
# If you want the upstart script to build play with sbt
pre-start script
chdir $HOME
sbt clean compile stage -mem $SBTMEM
end script
exec start-stop-daemon --pidfile ${HOME}/RUNNING_PID --chuid $USER:$GROUP --exec ${HOME}/target/start --background --start -- -Dconfig.resource=$CONFIG -Dhttp.port=$PORT -Dhttp.address=$ADDRESS $EXTRA
@tszming

This comment has been minimized.

Copy link

tszming commented Aug 7, 2012

Work as expected, thanks.

@ejain

This comment has been minimized.

Copy link

ejain commented Oct 3, 2013

Won't work for Play 2.2 :-(

@angeloh

This comment has been minimized.

Copy link

angeloh commented Oct 7, 2013

@ejain Could you explain why Play 2.2 won't work?

@morhook

This comment has been minimized.

Copy link

morhook commented Oct 8, 2013

play clean stage has stopped generated a script in ${HOME}/target/start . Now it generates target/universal/stage/bin/$APP

You can read in the migration notes that start has changed

http://www.playframework.com/documentation/2.2.0/Migration22

@morhook

This comment has been minimized.

Copy link

morhook commented Oct 15, 2013

I cannot fork this gist :(. That's why I will make my modifications as comments.

You should pass the JVM params like this:

env EXTRA="-J-Xms128M -J-Xmx512m -J-server"

specify the APP variable
env APP=my_app_name

And the exec line
exec start-stop-daemon --pidfile ${HOME}/RUNNING_PID --chuid $USER:$GROUP --exec ${HOME}/target/universal/stage/bin/${APP} --background --start -- -Dconfig.resource=$CONFIG -Dhttp.port=$PORT -Dhttp.address=$ADDRESS $EXTRA

@scaryroy

This comment has been minimized.

Copy link

scaryroy commented Mar 20, 2014

Love it, this script it awesome. Thank you.

@max-l

This comment has been minimized.

Copy link

max-l commented Apr 6, 2014

I tried to adapt this script for play 2.2.1, and I'll I'm getting is a hang,
i.e. "service play start " and "service play stop" both hang ... on ubuntu 12.04 ...

`env HOME=/play
env PORT=9000
env ADDRESS=127.0.0.1
env CONFIG=/play/application.conf

start on runlevel [2345]
stop on runlevel [06]

respawn
respawn limit 10 5
umask 022
expect daemon

expect fork

exec start-stop-daemon --pidfile ${HOME}/cogo-1.0/RUNNING_PID --exec ${HOME}/corgol-1.0/bin/corgol -- -mem 256 -Dconfig.file=$CONFIG -Dhttp.port=$PORT
`

@droidlabour

This comment has been minimized.

Copy link

droidlabour commented Jul 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.