diff options
author | elijah <elijah@riseup.net> | 2013-08-05 02:07:59 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-08-05 02:07:59 -0700 |
commit | d355aca3f2d913e6fad9913064f217b45afb8061 (patch) | |
tree | 6a1d229b76fd3ab22aabc6cfa6faeacae89c4633 /lib/nickserver | |
parent | 63ab91606173a34bb34dfa61164dc20e0a505e77 (diff) |
added 'foreground' start option (start, but don't daemonize)
Diffstat (limited to 'lib/nickserver')
-rw-r--r-- | lib/nickserver/daemon.rb | 26 | ||||
-rw-r--r-- | lib/nickserver/server.rb | 3 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/nickserver/daemon.rb b/lib/nickserver/daemon.rb index 651c6ce..c316b0a 100644 --- a/lib/nickserver/daemon.rb +++ b/lib/nickserver/daemon.rb @@ -146,7 +146,7 @@ module Nickserver puts msg puts puts "Usage: #{@name} [OPTION] COMMAND" - puts "COMMAND is one of: start, stop, restart, status, version" + puts "COMMAND is one of: start, stop, restart, status, version, foreground" puts "OPTION is one of: --verbose" puts exit 1 @@ -201,13 +201,14 @@ module Nickserver def parse_options loop do case ARGV[0] - when 'start' then ARGV.shift; @command = :start - when 'stop' then ARGV.shift; @command = :stop - when 'restart' then ARGV.shift; @command = :restart - when 'status' then ARGV.shift; @command = :status - when 'version' then ARGV.shift; @command = :version - when '--verbose' then ARGV.shift; Config.versbose = true - when /^-/ then override_default_config(ARGV.shift, ARGV.shift) + when 'start' then ARGV.shift; @command = :start + when 'stop' then ARGV.shift; @command = :stop + when 'restart' then ARGV.shift; @command = :restart + when 'status' then ARGV.shift; @command = :status + when 'version' then ARGV.shift; @command = :version + when 'foreground' then ARGV.shift; @command = :foreground + when '--verbose' then ARGV.shift; Config.versbose = true + when /^-/ then override_default_config(ARGV.shift, ARGV.shift) else break end end @@ -243,6 +244,15 @@ module Nickserver end end + def command_foreground(&block) + trap("INT") do + puts "\nShutting down..." + exit(0) + end + yield + exit(0) + end + def command_stop if daemon_running? kill_pid diff --git a/lib/nickserver/server.rb b/lib/nickserver/server.rb index 6234fd6..8434759 100644 --- a/lib/nickserver/server.rb +++ b/lib/nickserver/server.rb @@ -22,6 +22,9 @@ module Nickserver def self.start(opts={}) Nickserver::Config.load options = {:host => '0.0.0.0', :port => Nickserver::Config.port.to_i}.merge(opts) + unless defined?(TESTING) + puts "Starting nickserver #{options[:host]}:#{options[:port]}" + end EM.start_server options[:host], options[:port], Nickserver::Server end |