使用 capistrano 部署 Rails 项目时遇到一个问题:运行 bin 目录下的文件,但是进程没起来。
在 deploy.rb
文件中新增了如下内容
on roles(:chasqui) do
execute "for i in $( ps ax | awk '/chasqui_start/ {print $1}' ); do kill ${i}; done"
execute <<-BASH.squish!
cd #{deploy_to}/current
&& nohup ruby ./bin/chasqui_start >/dev/null 2>&1 &
BASH
end
然后部署时相关结果如下:
...
INFO [397a5432] Running for i in $( ps ax | awk '/chasqui_start/ {print $1}' ); do kill ${i}; done as deploy@server_ip_a
DEBUG [397a5432] Command: for i in $( ps ax | awk '/chasqui_start/ {print $1}' ); do kill ${i}; done
INFO [aa096778] Running cd /home/deploy/project_name/current && nohup ruby ./bin/chasqui_start >/dev/null 2>&1 & as deploy@server_ip_a
DEBUG [aa096778] Command: cd /home/deploy/project_name/current && nohup ruby ./bin/chasqui_start >/dev/null 2>&1 &
INFO [aa096778] Finished in 0.065 seconds with exit status 0 (successful).
...
部署成功之后,我上去对应服务器查看服务是否起来:
ps ax | awk '/bin\/chasqui_start/ {print $1}'
没有输出。
但如果上去服务器上执行,服务能够正常起来。
deploy@prime-server-1:~/project_name$ cd /home/deploy/project_name/current && nohup ruby ./bin/chasqui_start >/dev/null 2>&1 &
[2] 2460
[1] Done cd /home/deploy/project_name/current && nohup ruby ./bin/chasqui_start > /dev/null 2>&1
deploy@prime-server-1:~/project_name$ ps ax | awk '/bin\/chasqui_start/ {print $1}'
2500
另外,如果我手动在服务器上执行 bin/chasqui_start
之后,然后通过 capistrano 重新部署,chasqui_start 进程会挂掉,说明 execute "for i in $( ps ax | awk '/chasqui_start/ {print $1}' ); do kill ${i}; done"
还是会执行的,但是cd #{deploy_to}/current
&& nohup ruby ./bin/chasqui_start >/dev/null 2>&1 &
没有执行。
思索并搜索未果,故此一帖请教,多谢。