类似这样的功能:
services = [
{:port => 3306, :cmd => 'mysqld_safe xxxxx'},
{:port => 6379, :cmd => 'redis-server xxxx'}
]
while true
services.each do |service|
if service[:port].not_in_use?
Thread.new(service) do |service|
server_sock = TCPServer.new(serivce[:port])
server_sock.listen(backlog)
server_sock.accept
server_sock.close()
system(service[:cmd])
end
end
end
sleep(interval)
end
launchd 可以实现 on-demand launching,但是需要被启动的 service 程序支持才行