Reputation: 293
I have a Play framework web application that works when deployed to my ubuntu (14.04) server following the below steps:
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?
Upvotes: 1
Views: 460
Reputation: 3641
The playframework enables the JavaServerAppPlugin from sbt-native-packager, which provides systemloaders managing your application lifecycle. However you need to build a debian file to use this feature.
sbt debian:packageBin
sudo dpkg -i your-app.deb
@nnmat is right you should add -Dpidfile.path=/dev/null
. You can do that in your build.sbt
( see the documentation )
javaOptions in Universal ++= Seq("-Dpidfile.path=/dev/null")
Also make sure you configure the correct systemloader. By default it's Upstart
for debian packages. You might want to use Systemd
.
If you use sbt-native-packager 1.2.x
take a look at the latest documentation.
cheers, Muki
Upvotes: 1
Reputation: 7591
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.
Upvotes: 2