Search code examples
playframeworkserversbtubuntu-14.04sbt-native-packager

Play framework app stops working when server exited


I have a Play framework web application that works when deployed to my ubuntu (14.04) server following the below steps:

  • ran 'dist' in sbt
  • transferred resulting .zip file to server
  • ssh'd into server and ran the app using "/bin/ -Dplay.crypto.secret=abcxyz"

This runs the application in the foreground fine but kills it immediately when I lose internet connection (breaking the ssh connection to the server).

I need my application to be up and running continuously (until I decide to stop it) from the point I run it and I would like it to run in the background (daemon).

Will running the app as a daemon service on the server prevent the app from stopping when I exit the server through terminal? If so, how do I go about doing this? Is there a simple way to make sure the application runs regardless of me logging out of the server it's running on/losing connection to it?


Solution

  • There are plenty of ways to do that. Here is a quick way with nohup:

    nohup ./bin/$NAME -Dplay.crypto.secret=abcxyz -Dpidfile.path=/dev/null > /dev/null 2>&1 &
    

    I usually send the pid file to /dev/null so I don't have lock problems when play restarts. Note that, since this will run a background process, you should configure a file logger to see the server output.