Skip to content

Commit

Permalink
[FEATURE REQUEST] Allow users to run oxidized from CLI with a custom …
Browse files Browse the repository at this point in the history
…config (#3088)

* Allow users to pass oxidized home dir from cmd line

* Allow users to pass oxidized config file from cmd line

* Add run_once config option
  • Loading branch information
n-rodriguez authored Feb 27, 2024
1 parent 1694ff3 commit ae5499c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/oxidized/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/oxidized/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/oxidized/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ae5499c

Please sign in to comment.