Class: ForemanTasks::Dynflow::Daemon
- Inherits:
-
Object
- Object
- ForemanTasks::Dynflow::Daemon
- Defined in:
- lib/foreman_tasks/dynflow/daemon.rb
Instance Method Summary collapse
-
#run(foreman_root = Dir.pwd) ⇒ Object
load the Rails environment and initialize the executor in this thread.
-
#run_background(command = "start", options = {}) ⇒ Object
run the executor as a daemon.
Instance Method Details
#run(foreman_root = Dir.pwd) ⇒ Object
load the Rails environment and initialize the executor in this thread.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/foreman_tasks/dynflow/daemon.rb', line 8 def run(foreman_root = Dir.pwd) STDERR.puts("Starting Rails environment") foreman_env_file = File.("./config/environment.rb", foreman_root) unless File.exists?(foreman_env_file) raise "#{foreman_root} doesn't seem to be a foreman root directory" end ForemanTasks.dynflow.executor! require foreman_env_file STDERR.puts("Everything ready") sleep ensure STDERR.puts("Exiting") end |
#run_background(command = "start", options = {}) ⇒ Object
run the executor as a daemon
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/foreman_tasks/dynflow/daemon.rb', line 23 def run_background(command = "start", = {}) = { foreman_root: Dir.pwd, process_name: 'dynflow_executor', pid_dir: "#{Rails.root}/tmp/pids", log_dir: File.join(Rails.root, 'log'), wait_attempts: 300, wait_sleep: 1 } = .merge() FileUtils.mkdir_p([:pid_dir]) begin require 'daemons' rescue LoadError raise "You need to add gem 'daemons' to your Gemfile if you wish to use it." end unless %w[start stop restart run].include?(command) raise "Command exptected to be 'start', 'stop', 'restart', 'run', was #{command.inspect}" end STDERR.puts("Dynflow Executor: #{command} in progress") Daemons.run_proc([:process_name], :dir => [:pid_dir], :log_dir => [:log_dir], :dir_mode => :normal, :monitor => true, :log_output => true, :ARGV => [command]) do |*args| begin ::Logging.reopen run([:foreman_root]) rescue => e STDERR.puts e. Foreman::Logging.exception("Failed running foreman-tasks daemon", e) exit 1 end end end |