我正在尝试在我的 ubuntu 服务器上持续部署一些 rails 微服务,我认为 runit 可能是监督这些流程的好主意,然后在 chef 中使用迁移来更新微服务 - 但我坚持让一项服务工作。基本上安装似乎在 chef deploy 中工作,但应用程序没有启动并且没有在 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 l 很多这些条目
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