简体   繁体   English

与Mina和Foreman正确部署Rails应用程序

[英]Proper deployment of a Rails app with Mina and Foreman

For production purposes I need three processes running. 出于生产目的,我需要运行三个进程。 This is my procfile and I use Foreman to start them: 这是我的procfile,我使用Foreman启动它们:

web: bundle exec rails s Puma -p $PORT
queuing: bundle exec clockwork clock.rb
workers: bundle exec rake resque:workers

For deployment I'm using Mina. 部署我正在使用Mina。 What's the appropriate way to start Foreman at the end of deploy task? 在部署任务结束时启动Foreman的适当方法是什么? Currently I'm starting like this: 目前我开始是这样的:

desc "Deploys the current version to the server."
  task :deploy => :environment do
    deploy do
      invoke :'git:clone'
      invoke :'deploy:link_shared_paths'
      invoke :'bundle:install'
      invoke :'rails:db_migrate'
      invoke :'rails:assets_precompile'

      to :launch do
        queue "touch #{deploy_to}/tmp/restart.txt"
        queue "bundle exec foreman start"
      end
   end
 end

... but I don't think that's the proper way since the "mina deploy" command never successfully exits and the local console just starts outputting whatever these processes are doing. ...但我不认为这是正确的方式,因为“mina deploy”命令永远不会成功退出,本地控制台只是开始输出这些进程正在做的任何事情。

Question number two: How do I initialize logging for each of these three processes separately in separate files? 问题二:如何在单独的文件中分别初始化这三个进程中的每个进程的日志记录?

And how do I prevent killing all of these three processes when one of them crashes? 当其中一个进程崩溃时,如何防止杀死所有这三个进程? How do I make the process restart when it crashes? 如何在崩溃时重新启动进程?

Thanks! 谢谢!

OK, so that's 3 questions. 好的,这就是3个问题。

1) I think you want to detach foreman process from the terminal. 1)我认为你想要从终端分离领班过程。 That way the deployment process will finish and foreman process will be running even after you have disconnected from the server. 这样,部署过程将完成,即使您与服务器断开连接,也将运行foreman进程。 nohup is great for that, eg this will launch your app and pipe all logs to server.log file: nohup很棒,例如,这将启动你的应用程序并将所有日志传递给server.log文件:

nohup foreman start > server.log 2>&1 &

2) AFAIK, foreman doesn't let you do that. 2)AFAIK,工头不允许你这样做。 You should probably use another process management service (eg systemd, upstart). 您应该使用其他流程管理服务(例如systemd,upstart)。 Thankfully, foreman lets you easily export your config to different process management formats ( http://ddollar.github.io/foreman/#EXPORTING ). 值得庆幸的是,foreman可以让您轻松地将配置导出为不同的流程管理格式( http://ddollar.github.io/foreman/#EXPORTING )。

3) Again, you probably want to separate your processes and manage them separately via upstart, systemd, etc. 3)同样,您可能想要分离您的流程并通过upstart,systemd等单独管理它们。

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

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