sinatra 以编程方式作为守护进程启动

sinatra start as daemon programmatically

现在,加载完所有内容后,我的可执行文件会像这样运行我的应用程序:

Rack::Handler::pick(['puma']).run VCK::App

它可以工作,但它会阻塞终端(这对开发来说没问题)

如何从我的可执行文件中以编程方式将其作为守护程序启动?

编辑:

我用来将 sinatra 作为守护进程启动的代码:

    if options[:daemonize]
        pid = fork {Rack::Handler::pick(['puma']).run VCK::App}
        File.open(pid_file_loc, 'w') {|f| f.write(pid)}
        Process.detach(pid)
    else
        Rack::Handler::pick(['puma']).run VCK::App
    end

我用来停止 Sinatra 守护进程的代码:

Process.kill(15, File.read(pid_file_loc).to_i)

您可以使用 Process#daemon

从您的代码中守护任何 ruby 进程