简体   繁体   English

使用Forever重新启动Node.js.

[英]Restarting Node.js with Forever

I have a Capistrano recipe for deploying a Node.js application 我有一个Capistrano配方用于部署Node.js应用程序

 task :start, :roles => :app do
   run "cd #{current_path} && NODE_ENV=#{node_env} forever start socket-server.js"
 end

 task :stop, :roles => :app do
   run "cd #{current_path} && NODE_ENV=#{node_env} forever stop socket-server.js"
 end

 task :restart, :roles => :app do
   run "cd #{current_path} && NODE_ENV=#{node_env} forever restart socket-server.js"
 end

The problem is the "restart" task, there should be a check if the server is already running. 问题是“重启”任务,应该检查服务器是否已经运行。

Because restarting a not running server trough forever doesn't work, I need to run it first when it is not running. 因为永远重新启动未运行的服务器不起作用,所以我需要在它未运行时首先运行它。 But how I can do the check ? 但我怎么做检查?

Make your restart task call the stop and start tasks. 让您的重启任务调用停止和启动任务。

task :restart do
  stop
  sleep 5
  start
end

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

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