#!/usr/bin/env ruby # # Author:: Christian Reiniger # License:: GNU GPL v2 or later, as described in the accompanying LICENSE file # Homepage: http://dsadmin.dotsrc.org/ # # ---- # Last change: # # CVS User:: $Author: creinig $ # Date:: $Date: 2006-10-24 10:29:33 +0200 (Tue, 24 Oct 2006) $ # Revision:: $Revision: 110 $ # require 'optparse' require 'ostruct' require 'pathname' RAILS_ENV = 'production' TEST_MODE = false unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS_ROOT = root_path end INSTALL_PATH = Pathname.new(RAILS_ROOT).realpath.to_s def parseOpts options = OpenStruct.new options.daemonize = false options.instanceid = nil options.environment = 'production' options.cfgfile = "config/admind.xml" opts = OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options]" opts.separator "" opts.separator "Specific options (defaults in square brackets):" opts.on("-d", "--daemon", "--daemonize", "Run as daemon [run in foreground]") { |options.do_daemonize| } opts.on("-c", "--cfgfile CONFIGFILE", "Use the given config file [#{options.cfgfile}]") { |options.cfgfile| } opts.on("-e", "--environment=name", %w{test development production}, "The environment to run this server under (test/development/production).", "[production]") { |options.environment| } opts.on("-i", "--instanceid=name", String, "The id of the admind instance to run as.", "[current hostname]") { |options.instanceid| } opts.separator "" opts.separator "Common options:" # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end opts.parse!(ARGV.clone) options end def startupEnvironment() options = parseOpts ENV["RAILS_ENV"] = options.environment RAILS_ENV.replace(options.environment) if defined?(RAILS_ENV) $: << File.join(INSTALL_PATH, 'lib') $: << File.join(INSTALL_PATH, 'vendor/activeldap/lib') $: << File.join(INSTALL_PATH, 'app/models') options end options = startupEnvironment unless(Process.euid == 0) $stderr.puts "This has to be run with 'root' privileges" exit(1) end require "dsadmin/admind/AdminDaemon" main = Dsadmin::Admind::AdminDaemon.instance main.run(options)