Scala start Play server in production

2019-01-11 11:51发布

问题:

I have a Play 2.0 app deployed on EC2 and I start the app with play start and it runs in the background, I can hit Ctrl-D and the process will continue to run in the background but then it dies after a while (15 or 20 mins?), not sure why. I usually exit the ssh session after starting the app, I'm hoping that's not the reason.

回答1:

nohup play start works for me.



回答2:

I'm using the following startup script (on CentOS) for my Play app, seems to work fine, it puts it in the background and in its own process group and session so it's immune to hangups etc. The tip about play stage and target/start comes from Guillaume Bort and is "the proper way of doing it".

#!/bin/bash
#
# chkconfig: 2345 98 1
# description: MyApp application
#

case "$1" in
start)
  su - apps <<'EOF'
cd /opt/myapp || exit 1
PATH=/opt/play-2.1.1:$PATH
echo "Starting MyApp..."
play stage 
setsid target/start < /dev/null > /dev/null 2>&1 & 
EOF
  ;;
stop)
  su - apps <<'EOF'
cd /opt/myapp || exit 1
PATH=/opt/play-2.1.1:$PATH
echo "Stopping MyApp..."
play stop
EOF
  ;;
esac

You can verify it's isolated with:

ps -e -o user,pid,ppid,pgrp,sid,command | grep -i play

You'll see something like:

apps      2949     1  2949  2949 java -cp target/staged/* play.core.server.NettyServer target/..

Meaning init (pid 1) is its parent and it's isolated in its own process group (2949).



回答3:

I would suggest that you prepare the project deployment binary by using the stage command that the activator (formerly play) script takes. You can run that binary in the background, it can be found in the path which the second command in the code below shows.

./activator stage
target/universal/stage/bin/project-name &


回答4:

For play 2.2.3 ... play "start -Dhttp.port=8080" worked for me!