Scala start Play server in production
Asked Answered
B

4

7

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.

Batchelder answered 23/5, 2012 at 23:50 Comment(3)
Yeah, it's probably closing as a result of the hang-up signal from you ending your ssh session. Try launching the Unix program screen (a multiplexer), then launching your Play server like normal. Then, before logging out of ssh, press ctrl + a and then d to "detach" the screen session. This will leave Play running in the background (through screen), even after your ssh session ends.Despoil
Have you tried disowning the process? See https://mcmap.net/q/53042/-how-do-i-put-an-already-running-process-under-nohupFarant
@Destin, yeah it was due to my ssh session ending and nohup works.Batchelder
C
10

nohup play start works for me.

Census answered 24/5, 2012 at 8:17 Comment(1)
nohup activator run doesn't work anymore. Had to do it this : https://mcmap.net/q/1434649/-scala-start-play-server-in-production way.Bowel
M
3

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).

Mealymouthed answered 26/4, 2013 at 17:4 Comment(0)
B
1

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 &
Bowel answered 15/9, 2014 at 16:46 Comment(1)
You should probably disown the process afterwards as well.Immoderacy
K
0

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

Kaltman answered 3/6, 2015 at 3:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.