部署 现在启动了 faye,想在程序中判断一下 Faye 是否已经启动了。防止2重启动。

jerrym · August 22, 2014 · Last by jerrym replied at August 25, 2014 · 1675 hits

现在启动了 faye,想在程序中判断一下faye是否已经启动了。防止2重启动。

把进程 ID 保存在 tmp 下。

@ruby_sky 能告诉我具体方法么?谢谢了

#2 楼 @jerrym

def write_pid
    ::File.open(options[:pid], ::File::CREAT | ::File::EXCL | ::File::WRONLY ){ |f| f.write("#{Process.pid}") }
    at_exit { ::File.delete(options[:pid]) if ::File.exist?(options[:pid]) }
  rescue Errno::EEXIST
    check_pid!
    retry
end

仅供参考,并未在 faye 中尝试。

好的,谢谢,试一下

You need to Sign in before reply, if you don't have an account, please Sign up first.