如何使用runit来监督rails微服务

时间:2015-10-14 23:27:18

标签: ruby-on-rails chef runit

我正在尝试在我的ubuntu服务器上持续部署一些rails微服务,我想也许runit是监督这些进程的好主意,然后使用chef中的迁移来更新微服务 - 但是我无法获得一项服务。基本上安装似乎在厨师部署中工作,但应用程序无法启动,并且没有在3000上监听(在部署文件夹中手动启动确实在杀死server.pid后工作)

这是一台干净配置的机器和盒子上唯一的rails应用程序 - 所以我认为日志中提到的错误是我试图启动它的症状。

关于这可能如何起作用的任何提示(替代方案)表示赞赏!

模板

#!/bin/bash
set -e
exec chpst -u root:root nohup rails server &  

看起来不像nohup是这样做的 - 日志文件产生了这个。我不明白服务器是如何运行的 - 第一个日志条目表明它已经在运行......但是

2015-10-14_22:15:24.87117 A server is already running. Check     /opt/deploy/releases/39b30d7738bfba76462e257eb15100e1bea4edf0/tmp/pids/server.pid.
2015-10-14_22:15:25.32768 => Booting Thin
2015-10-14_22:15:25.32771 => Rails 4.2.0 application starting in development on http://localhost:3000
2015-10-14_22:15:25.32772 => Run `rails server -h` for more startup options
2015-10-14_22:15:25.32772 => Ctrl-C to shutdown server
2015-10-14_22:15:25.32773 Exiting

这会重复几次......直到此错误不再记录为止。

2015-10-14_22:15:17.16187 A server is already running. Check     /opt/deploy/releases/39b30d7738bfba76462e257eb15100e1bea4edf0/tmp/pids/server.pid.
2015-10-14_22:15:17.60398 => Booting Thin
2015-10-14_22:15:17.60401 => Rails 4.2.0 application starting in development    on http://localhost:3000
2015-10-14_22:15:17.60402 => Run `rails server -h` for more startup options
2015-10-14_22:15:17.60403 => Ctrl-C to shutdown server
2015-10-14_22:15:17.60404 Exiting

如果我ps aux | grep rails it很多这些条目

root     17709  3.6  1.4  93692 29468 ?       Rl   23:18   0:01 /usr/bin/ruby1.9.1 bin/rails server
root     17713  3.7  1.4  92112 28684 ?        Rl   23:18   0:01 /usr/bin/ruby1.9.1 bin/rails server
root     17717  3.7  1.3  91844 27696 ?        Rl   23:18   0:00 /usr/bin/ruby1.9.1 bin/rails server
root     17721  3.5  1.2  90164 26072 ?        Rl   23:18   0:00 /usr/bin/ruby1.9.1 bin/rails server
root     17725  3.6  1.2  90164 26192 ?        Rl   23:18   0:00 /usr/bin/ruby1.9.1 bin/rails server

配方

deploy_revision("/opt/deploy") do
  revision "master"
  repository "https://repo" 
  user "root"
  action :deploy
  shallow_clone true
  keep_releases 3
  rollback_on_error true  # remove release if callbacks failed
  migrate true
  migration_command "rake db:migrate"
  before_migrate do
    execute "bundle install" do
      command "bundle install"
      cwd  "#{release_path}"
      user "root" 
    end
  end

  symlink_before_migrate.clear
  create_dirs_before_symlink.clear
  purge_before_symlink.clear
  symlinks.clear
end

runit_service "auth" do
  run_template_name "myapp"
  log_template_name "myapp"
  options({
    :app_env => "development",
    :app_home => "/opt/deploy/current",
    :data_dir => "/opt/deploy/data"
  })
  retries 3
  retry_delay 5
end

0 个答案:

没有答案