blob: b0cabac2e465ad3bbe7e7818ec1b7e3016435efb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
|