bin/ezmlm-listd
author Michael Granger <mgranger@laika.com>
Wed, 06 Aug 2008 17:24:00 +0000
changeset 6 66beb495a861
permissions -rwxr-xr-x
Checkpoint commit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     1
#!/usr/bin/env ruby
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     2
# 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     3
# A startup script for an instance of Ezmlm::ListDaemon.
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     4
# $Id$
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     5
# 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     6
# Authors:
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     7
# * Michael Granger <mgranger@laika.com>
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     8
# * Jeremiah Jordan <jjordan@laika.com>
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
     9
# 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    10
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    11
BEGIN {
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    12
	require 'pathname'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    13
	basedir = Pathname.new( __FILE__ ).dirname.parent
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    14
	libdir = basedir + 'lib'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    15
	
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    16
	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    17
}
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    18
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    19
begin
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    20
	require 'rubygems'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    21
	require 'optparse'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    22
	require 'ezmlm/listdaemon'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    23
rescue LoadError
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    24
	unless Object.const_defined?( :Gem )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    25
		require 'rubygems'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    26
		retry
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    27
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    28
	raise
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    29
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    30
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    31
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    32
progname = Pathname.new( $0 ).basename
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    33
opts = Ezmlm::ListDaemon.default_options
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    34
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    35
oparser = OptionParser.new do |oparser|
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    36
	oparser.accept( Pathname ) {|path| Pathname.new(path) }
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    37
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    38
	oparser.banner = "Usage: #{progname.basename} OPTIONS LISTSDIRECTORY"
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    39
	oparser.separator 'Version ' + Ezmlm::VERSION
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    40
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    41
	oparser.separator ''
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    42
	oparser.separator 'Options:'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    43
	oparser.on( '--bind ADDRESS', '-b', String, 
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    44
		"Specify the address to bind to. Defaults to '#{opts.bind_addr}'" ) do |bindaddr|
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    45
		opts.bind_addr = bindaddr
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    46
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    47
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    48
	oparser.on( '--port PORTNUMBER', '-p', Integer,
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    49
		"Specify the port to connect to. Defaults to '#{opts.bind_port}" ) do |portnumber|
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    50
		opts.bind_port = portnumber
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    51
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    52
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    53
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    54
	oparser.separator ''
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    55
	oparser.separator 'Other Options:'
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    56
	oparser.on( '--debug', '-d', FalseClass, "Turn on debugging" ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    57
		$DEBUG = true
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    58
		$stderr.puts "Debugging enabled."
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    59
		opts.debugmode = true
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    60
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    61
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    62
	oparser.on_tail( '--help', '-h', FalseClass, "Display help for the given command." ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    63
		$stderr.puts( oparser )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    64
		exit!( 0 )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    65
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    66
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    67
	oparser.on_tail( '--version', '-V', "Print Ezmlm library version on STDOUT and quit." ) do
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    68
		$stdout.puts Ezmlm::VERSION
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    69
		exit!( 0 )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    70
	end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    71
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    72
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    73
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    74
# Parse command-line flags and display the help if there isn't exactly one argument
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    75
remaining_args = oparser.parse( ARGV )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    76
if remaining_args.nitems != 1
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    77
	$stderr.puts( oparser )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    78
	exit( 64 ) # EX_USAGE
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    79
end
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    80
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    81
listsdir = remaining_args.shift
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    82
daemon = Ezmlm::ListDaemon.new( listsdir, opts )
66beb495a861 Checkpoint commit.
Michael Granger <mgranger@laika.com>
parents:
diff changeset
    83
daemon.start.join