Update version according to OSCI-856
[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 if MCollective::Util.windows?
13   configfile = File.join(MCollective::Util.windows_prefix, "etc", "server.cfg")
14 else
15   configfile = "/etc/mcollective/server.cfg"
16 end
17 pid = ""
18
19 opts.each do |opt, arg|
20   case opt
21     when '--help'
22       puts "Usage: mcollectived.rb [--config /path/to/config] [--pidfile /path/to/pid]"
23       exit
24     when '--config'
25       configfile = arg
26     when '--pidfile'
27       pid = arg
28   end
29 end
30
31 config = MCollective::Config.instance
32
33 config.loadconfig(configfile) unless config.configured
34
35 MCollective::Log.info("The Marionette Collective #{MCollective::VERSION} started logging at #{config.loglevel} level")
36
37 if config.daemonize
38   MCollective::Log.debug("Starting in the background (#{config.daemonize})")
39
40   if MCollective::Util.windows?
41     require 'mcollective/windows_daemon'
42
43     MCollective::WindowsDaemon.daemonize_runner
44   else
45     require 'mcollective/unix_daemon'
46
47     MCollective::UnixDaemon.daemonize_runner(pid)
48   end
49 else
50   MCollective::Log.debug("Starting in the foreground")
51   runner = MCollective::Runner.new(configfile)
52   runner.run
53 end