简体   繁体   English

Scala在生产中启动Play服务器

[英]Scala start Play server in production

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. 我在EC2上部署了一个Play 2.0应用程序,我启动应用程序并play start它在后台运行,我可以Ctrl-D并且该过程将继续在后台运行,但之后它会在一段时间后死亡(15或20分钟?),不知道为什么。 I usually exit the ssh session after starting the app, I'm hoping that's not the reason. 我通常在启动应用程序后退出ssh会话,我希望这不是原因。

nohup play start对我nohup play start

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". 我正在使用以下启动脚本(在CentOS上)为我的Play应用程序,似乎工作正常,它把它放在后台和自己的进程组和会话中,因此它不受挂起等等。关于play stagetarget/start来自Guillaume Bort ,是“正确的做法”。

#!/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 ). 意思是init (pid 1 )是它的父级,它在自己的进程组中被隔离( 2949 )。

I would suggest that you prepare the project deployment binary by using the stage command that the activator (formerly play) script takes. 我建议你使用激活器(以前的播放)脚本所采用的stage命令来准备项目部署二进制文件。 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 &

对于游戏2.2.3 ...播放“start -Dhttp.port = 8080”为我工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM