Running a Play app as a service on Linux - Add to documentation

configuration

(Gui Becker) #1

I don’t see any specific configuration for different OS deployments such as typical deployment modes for Windows and Linux with examples.

As an example configuring it to run on Linux as a SystemD service, my configuration looks like:

[Unit]
Description=My Service
After=network.target

[Service]
EnvironmentFile=/home/my-service/env
PIDFile=/home/my-service/app/RUNNING_PID
WorkingDirectory=/home/my-service/app/
ExecStart=/home/my-service/bin/my-service -Dplay.http.secret.key=$SCALA_MY_SERVICE_APP_SECRET
Restart=on-failure
User=my-service
Group=my-service

# See http://serverfault.com/a/695863
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Are there any standard and recommended ways for deploying a Play app in a Linux env ?
Are there official configuration examples or recommended best-practices for deploying it as a service?

Why not include specific documentation for each OS (Linux, Windows) and have each one its own page in a separate section in the website under deployment?


#2

I agree.
I used your configuration and it working on a Debian 9. Thanks


(Andy Czerwonka) #3

The sbt-native-packager does exactly that.


(Gui Becker) #4

@andyczerwonka I did check the link from sbt native packager regarding linux packaging, from what I understand it defines packaging options for Linux distributions such as generating deb or rpm files, the configuration I’m suggesting in this post is somewhat different as it’s basically taking a Play app binary distribution from the result of sbt dist and configuring it as a SystemD service on linux which would run the binary and would benefit from things such as automatic restart in case of failures, etc.


(Andy Czerwonka) #5

The packaging, whether .deb or .rpm, that’s just the package manager target. I deploy to ubuntu, and the distribution does exactly that and more… it packages it as a systemd service, creates the appropriate user and group, etc.


(Gui Becker) #6

Good to know thanks for clarifying


(Amedeo Mantica) #7

Can anyone provide a build.sbt example working on CentOS 7 that generates rpm with service autostart ?
Thank you


(Marcos Pereira) #8

Hey @amedeomantica,

I don’t have a full example, but sbt-native-packager docs should have all the information that you need:

https://sbt-native-packager.readthedocs.io/en/stable/formats/rpm.html

Best.


(Amedeo Mantica) #9

Hi Marco,
I followed the docs, everything works, I get the rpm package, but I have no luck to get the systemd scripts


(Amedeo Mantica) #10

Do you have a working example ?


#11

I use something like that:


[Unit]
Description=CermAdmin 
After=network.target

[Service]
PIDFile=/web_resources/cermadmin-3.0/RUNNING_PID
WorkingDirectory=/web_resources/cermadmin-3.0/
ExecStart=/web_resources/cermadmin-3.0/bin/cermadmin -Dconfig.file=conf/application.conf -Dhttp.port=8081 -Dhttps.port=8002 -Dhttps.keyStore=keystore.jks -D
https.keyStorePassword=importkey
Restart=on-failure
User=morelli
Group=users

# See http://serverfault.com/a/695863
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

(Amedeo Mantica) #12

Thank yopu. Btw, I solved the issue, there was an error in my build.sbt