diff options
Diffstat (limited to 'bin/nickserver')
-rwxr-xr-x | bin/nickserver | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/nickserver b/bin/nickserver new file mode 100755 index 0000000..b0cabac --- /dev/null +++ b/bin/nickserver @@ -0,0 +1,58 @@ +#!/usr/bin/ruby +# +# Nickserver key discovery daemon +# + +# +# bootstrap nickserver library +# +begin # try without rubygems (might be already loaded or not present) + require 'nickserver' +rescue LoadError + begin # try with rubygems + require 'rubygems' + require 'nickserver' + rescue LoadError # try manually + BASE_DIR = File.expand_path('../..', File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__) + $LOAD_PATH << "#{BASE_DIR}/lib" + require "nickserver" + end +end + +# +# Handle craceful Ctrl-C +# +Signal.trap("SIGINT") do + puts "\nQuit" + exit +end + +# +# Handle '--version' ourselves +# +if ARGV.grep(/--version/).any? + puts "nickserver #{Nickserver::VERSION}, ruby #{RUBY_VERSION}" + exit(0) +end + +# +# Start the daemon +# +require 'daemons' + +options = {:app_name => 'nickserver', :multiple => false, :backtrace => true} + +# pick where the pid file should go (must be readable/writable by current user) +if File.writable?('/var/run/nickserver') + options.merge!(:dir_mode => :normal, :dir => '/var/run/nickserver') +elsif ENV["USER"] == "root" + options.merge!(:dir_mode => :system) +else + options.merge!(:dir_mode => :normal, :dir => '/tmp') +end + +Daemons.run_proc('nickserver', options) do + EventMachine.run do + Nickserver::Server.start + end +end |