Home > database >  Is there a way to stop a Puma/Rack server on a HTTP request?
Is there a way to stop a Puma/Rack server on a HTTP request?

Time:05-28

I have a Ruby app (written in Roda, running as a Rack app on Puma) which I want to be able to stop on a click of a button in the browser - basically to stop the server on request. What would be a good way to do that?

CodePudding user response:

I have not tested this but since you can run shell commands from a controller using system, you could setup a button on your page triggering a specific controller action with the shell command to stop your server, ex something like system "system killall -9 rails" to stop running apps with rails in their name, or anything more specific to your case.

CodePudding user response:

You can control Puma with process signals. If you are running Puma in a single process, you can simply send the signal to the current process:

Process.kill("TERM", Process.pid)

For a clustered mode you will have to find the PID of Puma master process.

Puma also offers a built-in control/status web server if you don't want to write your own.

  • Related