简体   繁体   English

具有停止和重启能力的rackup服务器

[英]rackup server with ability to stop and restart

i'm planning to add some tasks to my capistrano recipes file to give ability for admins to remote start/stop/restart private_pub server. 我打算在我的capistrano食谱文件中添加一些任务,以便管理员能够远程启动/停止/重启private_pub服务器。 But if for start i can use something like 但如果一开始我可以使用类似的东西

  desc "Start private_pub server"
  task :start do
    run "cd #{current_path};rackup private_pub.ru -s thin -E production -D"
  end

i cannot find any documentation how to stop or restart rackup server. 我找不到任何文档如何停止或重新启动rackup服务器。 i see option 我看到选项

  -P, --pid FILE           file to store PID (default: rack.pid)

but maybe use kill command to stop server - not good idea? 但也许使用kill命令来停止服务器 - 不是好主意?

I found this while searching for the same solution. 我在寻找相同的解决方案时发现了这一点。

gist.github.com/3197633 gist.github.com/3197633

basically while starting the process you have it write the pid number to a file in /tmp/pids and then when you go to stop it you read that file and it runs kill -9 ... 基本上在启动过程时你可以将pid编号写入/ tmp / pids中的文件然后当你去停止它时你会读取该文件并运行kill -9 ...

Hope it helps. 希望能帮助到你。

Your'e correct in that using kill -9 is a bad idea. 你使用kill -9是正确的,这是个坏主意。 This can lead to uneccesary loss of data, and as I understand it is recommended to use kill 2 or kill -INT which is equivalent to hitting 'control-c' and should close a normal server for you. 这可能导致不必要的数据丢失,据我所知,建议使用kill 2kill -INT ,这相当于命中'control-c',并且应该关闭一个普通的服务器。 I personally have started managing my servers with the God gem by TPW. 我个人已经开始使用TPW的God gem来管理我的服务器。 Here is the script I use for running a local 'geminabox' server, for instance: 这是我用来运行本地'geminabox'服务器的脚本,例如:

God.watch do |w|
w.name = 'gemserver'
    w.dir = '/usr/local/gemserver'
    w.pid_file = "#{ENV['HOME']}/.god/pids/#{w.name}.pid"
    ru = File.expand_path `which rackup`
    w.start = "#{ru} -D #{w.dir}/config.ru -P #{w.pid_file}"
    # w.stop = lambda { Process.kill(3, `lsof -i :9292`.chomp.to_i) }
    w.behavior :clean_pid_file
    w.keepalive
end

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

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