# File lib/thin/daemonizing.rb, line 137 def force_kill(pid_file) if pid = read_pid_file(pid_file) Logging.log "Sending KILL signal to process #{pid} ... " Process.kill("KILL", pid) File.delete(pid_file) if File.exist?(pid_file) else Logging.log "Can't stop process, no PID found in #{pid_file}" end end
Send a QUIT or INT (if timeout is 0
) signal the process which
PID is stored in pid_file
. If the process is still running
after timeout
, KILL signal is sent.
# File lib/thin/daemonizing.rb, line 103 def kill(pid_file, timeout=60) if timeout == 0 send_signal('INT', pid_file, timeout) else send_signal('QUIT', pid_file, timeout) end end
# File lib/thin/daemonizing.rb, line 147 def read_pid_file(file) if File.file?(file) && pid = File.read(file) pid.to_i else nil end end
Restart the server by sending HUP signal.
# File lib/thin/daemonizing.rb, line 112 def restart(pid_file) send_signal('HUP', pid_file) end
Send a signal
to the process which PID is stored in
pid_file
.
# File lib/thin/daemonizing.rb, line 117 def send_signal(signal, pid_file, timeout=60) if pid = read_pid_file(pid_file) Logging.log "Sending #{signal} signal to process #{pid} ... " Process.kill(signal, pid) Timeout.timeout(timeout) do sleep 0.1 while Process.running?(pid) end else Logging.log "Can't stop process, no PID found in #{pid_file}" end rescue Timeout::Error Logging.log "Timeout!" force_kill pid_file rescue Interrupt force_kill pid_file rescue Errno::ESRCH # No such process Logging.log "process not found!" force_kill pid_file end