91 lines
2.4 KiB
Ruby
91 lines
2.4 KiB
Ruby
#!/usr/bin/env ruby
|
|
#
|
|
# ildusd - daemon for Dynamic DNS management using a database and the ILDUS protocol
|
|
#
|
|
# Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
|
|
#
|
|
# Ildus is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free
|
|
# Software Foundation; either version 2 of the License, or (at your option)
|
|
# any later version.
|
|
#
|
|
# Ildus is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with Ildus; see the file COPYING. If not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
# USA.
|
|
|
|
require 'getoptlong'
|
|
require 'ildus/server'
|
|
|
|
# Set the program name and version.
|
|
$0 = $0.split[-1]
|
|
Program = File.basename $0
|
|
Version = '1.1'
|
|
|
|
# Usage and version printing methods.
|
|
def print_usage
|
|
puts <<USAGE
|
|
Usage: #{Program} [OPTION]...
|
|
Starts the Ildus #{Version} server, waits for commands from clients and
|
|
processes them.
|
|
|
|
Configuration options:
|
|
-c, --config=CFG use CFG as the configuration file instead of the default
|
|
|
|
Other options:
|
|
-h, --help display this help and exit
|
|
-v, --version display the version and exit
|
|
USAGE
|
|
end
|
|
|
|
def print_version
|
|
puts "#{Program} #{Version}"
|
|
end
|
|
|
|
# Argument parsing.
|
|
cfg_file = "ildusd.conf"
|
|
opts = GetoptLong.new(
|
|
[ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ],
|
|
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
|
[ '--version', '-v', GetoptLong::NO_ARGUMENT ]
|
|
)
|
|
|
|
begin
|
|
opts.each do |opt, arg|
|
|
case opt
|
|
when "--config": cfg_file = arg
|
|
when "--help": print_usage; exit 0
|
|
when "--version": print_version; exit 0
|
|
end
|
|
end
|
|
rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument
|
|
print_usage; exit 1
|
|
end
|
|
|
|
# Main.
|
|
|
|
begin
|
|
server = Ildus::Server.new(cfg_file)
|
|
puts <<-START
|
|
#{Program} #{Version} Copyright (C) 2005 Paul van Tilburg <paul@luon.net>
|
|
Ildus comes with ABSOLUTELY NO WARRANTY; This is free software, and you
|
|
are welcome to redistribute it under certain conditions; for details see
|
|
the COPYING file.
|
|
|
|
START
|
|
|
|
['INT', 'TERM', 'QUIT'].each do |sig|
|
|
Signal.trap(sig) { server.shutdown }
|
|
end
|
|
|
|
server.start
|
|
rescue StandardError => e
|
|
puts "#{Program}: #{e}"
|
|
exit 2
|
|
end
|