summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-10-29 16:21:46 -0700
committerelijah <elijah@riseup.net>2014-10-29 16:21:46 -0700
commit5c39ab10b490c3571d1169128c7e3095e9b6fefc (patch)
tree90ada07a81dbb6756d34d48d4716e8334342c57b
parent7a3da65dfebf6b69a0dada438427078f72514a63 (diff)
catch SIGINT and SIGHUP
-rw-r--r--lib/nickserver/daemon.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/nickserver/daemon.rb b/lib/nickserver/daemon.rb
index d03c394..c6752d8 100644
--- a/lib/nickserver/daemon.rb
+++ b/lib/nickserver/daemon.rb
@@ -65,7 +65,7 @@ module Nickserver
Process.setsid
exit if fork
create_pid_file(Config.pid_file, Config.user)
- catch_interrupt
+ catch_signals
redirect_output
drop_permissions_to(Config.user) if Config.user
File.umask 0000
@@ -126,18 +126,20 @@ module Nickserver
end
#
- # Gracefully handle Ctrl-C
+ # stop when we should
#
- def catch_interrupt
- Signal.trap("SIGINT") do
+ def catch_signals
+ sigtrap = proc {
command_stop
$stdout.puts "\nQuit"
$stdout.flush
exit
+ }
+ ["SIGTERM", "SIGINT", "SIGHUP"].each do |signal|
+ Signal.trap(signal, sigtrap)
end
end
-
#
# OUTPUT
#