在给定端口上启动和停止进程的更好方法
Better way to start and stop process on a given port
我的代码有效,但有更好的解决方案吗?
我有一个重新启动外部工具的操作。有时它会重新启动或启动。我将端口设置为 12928。我的检查对象有一个从系统获取 PID 的方法。
def pids
%x{netstat -tanp | grep 12928}
end
使用 pid 方法(如下)我得到了 pid。
def pid
/(?<pid>\d+)\//.match(pits.to_s)[:pid].to_i
end
要停止此服务,我使用:
Process.kill("SIGTERM",pid)
Process.detach(pid)
我找到了一个名为 eye
(https://github.com/kostya/eye) 的 gem,它的灵感来自 Bluepill 和 God。
看起来不错,我会试一试。
如果有人对此感兴趣,这里是存储库中的示例:
process :sample1 do
pid_file '1.pid'
start_command 'ruby ./sample.rb'
daemonize true
stdall 'sample1.log'
end
开始你的工作:
eye start sample1
要停止此作业,您键入:
eye stop sample1
我的代码有效,但有更好的解决方案吗?
我有一个重新启动外部工具的操作。有时它会重新启动或启动。我将端口设置为 12928。我的检查对象有一个从系统获取 PID 的方法。
def pids
%x{netstat -tanp | grep 12928}
end
使用 pid 方法(如下)我得到了 pid。
def pid
/(?<pid>\d+)\//.match(pits.to_s)[:pid].to_i
end
要停止此服务,我使用:
Process.kill("SIGTERM",pid)
Process.detach(pid)
我找到了一个名为 eye
(https://github.com/kostya/eye) 的 gem,它的灵感来自 Bluepill 和 God。
看起来不错,我会试一试。
如果有人对此感兴趣,这里是存储库中的示例:
process :sample1 do
pid_file '1.pid'
start_command 'ruby ./sample.rb'
daemonize true
stdall 'sample1.log'
end
开始你的工作:
eye start sample1
要停止此作业,您键入:
eye stop sample1