简体   繁体   English

如何使用capistrano在远程计算机上启动play2应用程序

[英]How to start a play2 application on a remote machine using capistrano

I'm trying to deploy a play2 application with capistrano, but I can't figure out how to (re)start the play2 application after a successful deployment. 我正在尝试使用capistrano部署play2应用程序,但在成功部署后我无法弄清楚如何(重新)启动play2应用程序。 Just triggering 'play start' will cause the process to be hanging waiting for me to press ctrl+D 只是触发“播放开始”将导致进程挂起,等待我按下ctrl + D.

I've created a start script in the play app root folder 我在play app根文件夹中创建了一个启动脚本

#!/bin/bash

nohup bash -c "/var/lib/play2/play start &>> /tmp/myapp.log 2>&1" &> /dev/null &

It works great when I run this on the server. 当我在服务器上运行它时,它工作得很好。 When I try to call this from my local machine over ssh it also works. 当我尝试通过ssh从我的本地机器调用它时它也可以工作。 But when I am using capistrano, it doesn't seem to do anything. 但是当我使用capistrano时,它似乎什么也没做。 My capistrano config looks like this: 我的capistrano配置看起来像这样:

namespace :deploy do

  task :restart do
    stop
    sleep 1
    start
  end

  task :start do
    run "cd #{current_release}/trip-api && ./start.sh"
  end

  task :stop do
    run "cd #{current_release}/trip-api && ./stop.sh"
  end
end

What's the best way to start a play2 application on a remote machine? 在远程计算机上启动play2应用程序的最佳方法是什么? How to get it working with capistrano? 如何使用capistrano?

Have a look at play documentation on deploying your application on production 查看有关在生产中部署应用程序的播放文档

The recommended way is to package your app with 推荐的方法是打包你的应用程序

play clean compile stage

And then run it with 然后运行它

$ target/start $ target / start

To stop it, have a look at the docs: 要停止它,请查看文档:

The server's process id is displayed at bootstrap and written to the RUNNING_PID file. 服务器的进程ID在引导程序中显示并写入RUNNING_PID文件。 To kill a running Play server, it is enough to send a SIGTERM to the process to properly shutdown the application. 要杀死正在运行的Play服务器,只需将SIGTERM发送到进程即可正确关闭应用程序。

In this quickstart for Openshift , it shows another way to start play as a service and how to stop it . 在这个Openshift的快速入门中 ,它展示了另一种开始播放服务以及如何阻止它的方法

basically you do something like this to start: 基本上你做这样的事情开始:

APP_COMMAND="${OPENSHIFT_REPO_DIR}target/start $PLAY_PARAMS "\
"-Dhttp.port=${OPENSHIFT_INTERNAL_PORT} "\
"-Dhttp.address=${OPENSHIFT_INTERNAL_IP} "\
"-Dconfig.resource=openshift.conf"

echo $APP_COMMAND &>> $LOG_FILE
nohup bash -c "${APP_COMMAND} &>> ${LOG_FILE} 2>&1" &> /dev/null &

and to stop it 并阻止它

pid=`cat RUNNING_PID`
echo "Stopping play application" >> $LOG_FILE
kill -SIGTERM $pid

There are few fresh topics about running application available at Google Groups: 关于在Google网上论坛中运行应用程序的新主题很少:

It's good idea to follow or join them 跟随或加入它们是个好主意

I would suggest using runit. 我建议使用runit。 We are currently running a bunch of services in production and it works great. 我们目前正在生产中运行一系列服务,效果很好。

It only involves creating a simple shell script named run, pointing runit to its containing directory and then start it. 它只涉及创建一个名为run的简单shell脚本,将runit指向其包含的目录,然后启动它。 Services should not daemonize by themselves and runit controls pid files, etc. 服务不应该自己守护和runit控制pid文件等。

There is a command ( sv ) to start, stop and query services. 有一个命令( sv )来启动,停止和查询服务。 ( sv start|stop|status|restart yourapp ). sv start|stop|status|restart yourapp )。

A cursory google search got me this http://rubygems.org/gems/capistrano-runit though I do not use capistrano at all so I can't vouch for it's usefulness. 一个粗略的谷歌搜索给了我这个http://rubygems.org/gems/capistrano-runit虽然我根本不使用capistrano所以我不能保证它的用处。

http://smarden.org/runit/ http://smarden.org/runit/

The faq is the best place to start: http://smarden.org/runit/faq.html 常见问题解答是最好的起点: http//smarden.org/runit/faq.html

In debian you just apt-get install runit and are good to go. 在debian中你只需要apt-get install runit就可以了。 update-service --add /your/service/dir/ will register the service with runit. update-service --add /your/service/dir/将使用runit注册服务。

On deployment we stop services, change binaries and start services; 在部署时,我们停止服务,更改二进制文件和启动服务; it is really simple. 这很简单。

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

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