Skip to content

Instantly share code, notes, and snippets.

@gre
Last active October 8, 2021 00:33
Show Gist options
  • Save gre/5528826 to your computer and use it in GitHub Desktop.
Save gre/5528826 to your computer and use it in GitHub Desktop.
Super-small scripts for easy PlayFramework deployment
#!/bin/bash
REMOTE=play@SERVER_IP
REMOTE_APP=/home/play/PROJECT_NAME/
sbt stage || exit 1;
rsync -va target/ $REMOTE:$REMOTE_APP/target;
ssh $REMOTE "cd $REMOTE_APP; ./stop.sh";
ssh $REMOTE "cd $REMOTE_APP; ./start.sh";
nohup ./target/universal/stage/bin/APPLICATION_SBT_NAME -Dhttp.port=9090 &
# You can provide all the -Dsettings you need to set for your application here :-)
test -f RUNNING_PID && kill `cat RUNNING_PID` && sleep 5;
rm RUNNING_PID;

How to use

  • Put deploy.sh in the root of your (playframework) project
  • edit deploy.sh and set up the ssh access (REMOTE) and the remote app directory (REMOTE_APP).
  • On the server, create an empty directory at $REMOTE_APP and put start.sh and stop.sh in it.
  • Optionally, edit the http port for convenience in ./start.sh
  • run ./deploy.sh and enjoy your deployment loop

Benefits

  • It does incremental upload (only upload what have change) with rsync.
  • It uses sbt stage which compile the application locally on your machine so you only need java on your server.
  • It kills the server before uploading and restarts it.
  • It displays server log in your console at the end of the deploy.sh, you can Ctrl-C and it keep the server up.

Notes

  • ssh authorized_keys is your friend.
  • It uses nohup to keep the application running which is not perfect but works: Of-course there must be better tools, for maintaining play applications as UNIX daemons, this one was just fine for me :)

Now, Fork me if you want & DWTFYW

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