summaryrefslogtreecommitdiff
path: root/bin/nickserver
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-12-24 16:25:39 -0800
committerelijah <elijah@riseup.net>2012-12-24 16:25:39 -0800
commit8a70059fed66daa00dd9f8558748255735c91846 (patch)
tree47d22bb1719d389f4c1cc9b3a91d7cdb94fdee84 /bin/nickserver
parent8b5cd59867b00829dfe9d38531d44f1fdf4edbdc (diff)
added nickserver daemon
Diffstat (limited to 'bin/nickserver')
-rwxr-xr-xbin/nickserver58
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