Class: Daemonizer::CLI
- Inherits:
-
Thor
- Object
- Thor
- Daemonizer::CLI
- Defined in:
- lib/daemonizer/cli.rb
Instance Method Summary collapse
- #debug(pool_name = nil) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #restart(pool_name = nil) ⇒ Object
- #start(pool_name = nil) ⇒ Object
- #stop(pool_name = nil) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 |
# File 'lib/daemonizer/cli.rb', line 10 def initialize(*) super Daemonizer.demfile = [:demfile] || "Demfile" end |
Instance Method Details
#debug(pool_name = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/daemonizer/cli.rb', line 88 def debug(pool_name = nil) puts "You should supply pool_name to debug" if pool_name.nil? control_pools_loop(pool_name, "execution ended", true) do |pool| STDOUT.sync = true print_pool pool.name, "Debugging pool: " engine = Engine.new(pool) engine.debug! print_pool pool.name, " Done!" exit(0) end return true end |
#list ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/daemonizer/cli.rb', line 70 def list puts "List of configured pools:" puts "" Daemonizer.find_pools(nil).each do |pool| puts " * #{pool.name}" end puts "" return true end |
#restart(pool_name = nil) ⇒ Object
82 83 84 85 |
# File 'lib/daemonizer/cli.rb', line 82 def restart(pool_name = nil) invoke :stop, pool_name invoke :start, pool_name end |
#start(pool_name = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/daemonizer/cli.rb', line 16 def start(pool_name = nil) control_pools_loop(pool_name, "successfully started") do |pool| # Pid file check if Daemonize.check_pid(pool.pid_file) print_pool pool.name, "Can't start, another process exists!" exit(1) end print_pool pool.name, "Starting pool" app_name = "#{pool.name} monitor\0" Daemonize.daemonize(app_name) Dir.chdir(Daemonizer.root) # Make sure we're in the working directory # Pid file creation Daemonize.create_pid(pool.pid_file) # Workers processing engine = Engine.new(pool) engine.start! # Workers exited, cleaning up File.delete(pool.pid_file) rescue nil end return true end |
#stop(pool_name = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/daemonizer/cli.rb', line 46 def stop(pool_name = nil) control_pools_loop(pool_name, "successfully stoped") do |pool| STDOUT.sync = true unless Daemonize.check_pid(pool.pid_file) print_pool pool.name, "No pid file or a stale pid file!" exit 1 end pid = Daemonize.read_pid(pool.pid_file) print_pool pool.name, "Killing the process: #{pid}: " loop do Process.kill('SIGTERM', pid) sleep(1) break unless Daemonize.check_pid(pool.pid_file) end print_pool pool.name, " Done!" exit(0) end return true end |