Class: Circus::Processes::Daemontools
- Inherits:
-
Object
- Object
- Circus::Processes::Daemontools
- Defined in:
- lib/circus/processes/daemontools.rb
Overview
Support for working with Daemontools
Instance Method Summary collapse
- #await_service_pause(name, working_dir, logger) ⇒ Object
- #await_service_startup(name, working_dir, logger) ⇒ Object
- #is_service_running?(working_dir) ⇒ Boolean
- #pause_service(name, working_dir, logger) ⇒ Object
- #resume_service(name, working_dir, logger) ⇒ Object
Instance Method Details
#await_service_pause(name, working_dir, logger) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/circus/processes/daemontools.rb', line 40 def await_service_pause(name, working_dir, logger) logger.info("Waiting for shutdown of #{name}") (1..5).each do |i| return true unless is_service_running?(working_dir) sleep 1 end (1..100).each do |i| # Attempt a more brutal shutdown `svc -k #{working_dir}` return true unless is_service_running?(working_dir) sleep 1 end return false end |
#await_service_startup(name, working_dir, logger) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/circus/processes/daemontools.rb', line 29 def await_service_startup(name, working_dir, logger) logger.info("Waiting for startup of #{name}") (1..100).each do |i| return true if is_service_running?(working_dir) sleep 1 end return false end |
#is_service_running?(working_dir) ⇒ Boolean
59 60 61 62 |
# File 'lib/circus/processes/daemontools.rb', line 59 def is_service_running?(working_dir) res = `svstat #{working_dir}` $? == 0 && res.include?('up (pid') end |
#pause_service(name, working_dir, logger) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/circus/processes/daemontools.rb', line 5 def pause_service(name, working_dir, logger) res = `svc -d #{working_dir}` if $? != 0 logger.error("Failed to initiate service shutdown for #{name}") return end unless await_service_pause(name, working_dir, logger) logger.error("Service did not shutdown") end end |
#resume_service(name, working_dir, logger) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/circus/processes/daemontools.rb', line 17 def resume_service(name, working_dir, logger) res = `svc -u #{working_dir}` if $? != 0 logger.error("Failed to initiate service startup for #{name}") return end unless await_service_startup(name, working_dir, logger) logger.error("Service did not resume") end end |