4f0d1d8f056ccb7cc7667e751308ed3c1402a9d2
[packages/precise/mcollective.git] / bin / mcollectived
1 #!/usr/bin/env ruby
2
3 require 'mcollective'
4 require 'getoptlong'
5
6 opts = GetoptLong.new(
7   [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
8   [ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT],
9   [ '--pidfile', '-p', GetoptLong::REQUIRED_ARGUMENT]
10 )
11
12 configfile = "/etc/mcollective/server.cfg"
13 pid = ""
14
15 opts.each do |opt, arg|
16   case opt
17     when '--help'
18       puts "Usage: mcollectived.rb [--config /path/to/config] [--pidfile /path/to/pid]"
19       exit
20     when '--config'
21       configfile = arg
22     when '--pidfile'
23       pid = arg
24   end
25 end
26
27 config = MCollective::Config.instance
28
29 config.loadconfig(configfile) unless config.configured
30
31 MCollective::Log.info("The Marionette Collective #{MCollective::VERSION} started logging at #{config.loglevel} level")
32
33 if config.daemonize
34   MCollective::Log.debug("Starting in the background (#{config.daemonize})")
35
36   if MCollective::Util.windows?
37     require 'mcollective/windows_daemon'
38
39     MCollective::WindowsDaemon.daemonize_runner
40   else
41     require 'mcollective/unix_daemon'
42
43     MCollective::UnixDaemon.daemonize_runner(pid)
44   end
45 else
46   MCollective::Log.debug("Starting in the foreground")
47   runner = MCollective::Runner.new(configfile)
48   runner.run
49 end