diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb index 1057387a8..692b2734f 100644 --- a/lib/oxidized/cli.rb +++ b/lib/oxidized/cli.rb @@ -44,6 +44,8 @@ def parse_opts opts = Slop.parse do |opt| opt.on '-d', '--debug', 'turn on debugging' opt.on '--daemonize', 'Daemonize/fork the process' + opt.string '--home-dir', 'Oxidized home dir', default: nil + opt.string '--config-file', 'Oxidized config file', default: nil opt.on '-h', '--help', 'show usage' do puts opt exit diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index 4ad1e433b..5b8d6ca47 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -15,7 +15,9 @@ class Config SLEEP = 1 def self.load(cmd_opts = {}) - asetus = Asetus.new(name: 'oxidized', load: false, key_to_s: true, usrdir: Oxidized::Config::ROOT) + usrdir = File.expand_path(cmd_opts[:home_dir] || Oxidized::Config::ROOT) + cfgfile = cmd_opts[:config_file] || 'config' + asetus = Asetus.new(name: 'oxidized', load: false, key_to_s: true, usrdir: usrdir, cfgfile: cfgfile) Oxidized.asetus = asetus asetus.default.username = 'username' @@ -25,6 +27,7 @@ def self.load(cmd_opts = {}) asetus.default.interval = 3600 asetus.default.use_syslog = false asetus.default.debug = false + asetus.default.run_once = false asetus.default.threads = 30 asetus.default.use_max_threads = false asetus.default.timeout = 20 diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index d1323e495..9fb9f7b81 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -33,7 +33,10 @@ def work Oxidized.logger.debug "lib/oxidized/worker.rb: Added #{node.group}/#{node.name} to the job queue" end - run_done_hook if cycle_finished? + if cycle_finished? + run_done_hook + exit 0 if Oxidized.config.run_once + end Oxidized.logger.debug("lib/oxidized/worker.rb: #{@jobs.size} jobs running in parallel") unless @jobs.empty? end