sinatra start as daemon programmatically

1.8k views Asked by At

Right now, after having loaded everything my executable runs my app like this:

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

and it works, but it blocks the terminal (which is ok for development)

How do I get this to start as a daemon programmatically from within my executable?

EDIT:

Code I use to start sinatra as a daemon:

    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

Code I use to stop Sinatra Daemon:

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

There are 1 answers

2
Anthony On BEST ANSWER

You can daemonize any ruby process from within your code by using Process#daemon