Class: Jah::Agent
- Inherits:
-
Object
- Object
- Jah::Agent
- Defined in:
- lib/jah/agent.rb
Constant Summary collapse
- PID_FILE =
File.join("/tmp", "jah.pid")
Class Method Summary collapse
- .config ⇒ Object (also: install)
- .restart ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
Instance Method Summary collapse
- #daemonize ⇒ Object
-
#initialize(options = nil) ⇒ Agent
constructor
, config).
- #pid_file ⇒ Object
- #run_agent_run ⇒ Object
Constructor Details
Class Method Details
.config ⇒ Object Also known as: install
64 65 66 |
# File 'lib/jah/agent.rb', line 64 def self.config Install.new end |
.restart ⇒ Object
58 59 60 61 62 |
# File 'lib/jah/agent.rb', line 58 def self.restart stop sleep 2 start end |
Instance Method Details
#daemonize ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jah/agent.rb', line 72 def daemonize begin File.open(pid_file, File::CREAT|File::EXCL|File::WRONLY) do |pid| pid.puts $$ end at_exit do begin File.unlink(pid_file) rescue Log.error "Unable to unlink pid file: #{$!.}" end end rescue pid = File.read(pid_file).strip.to_i rescue "unknown" running = true begin Process.kill(0, pid) if stat = File.stat(pid_file) if mtime = stat.mtime if Time.now - mtime > 25 * 60 # assume process is hung after 25m Log.info "Trying to KILL an old process..." Process.kill("KILL", pid) running = false end end end rescue Errno::ESRCH running = false rescue # do nothing, we didn't have permission to check the running process end if running if pid == "unknown" Log.warn "Could not create or read PID file. " + "You may need to the path to the config directory. " + "See: http://scoutapp.com/help#data_file" else Log.warn "Process #{pid} was already running" end exit else Log.info "Stale PID file found. Clearing it and reloading..." File.unlink(pid_file) rescue nil retry end end self end |
#pid_file ⇒ Object
27 28 29 |
# File 'lib/jah/agent.rb', line 27 def pid_file @pidfile ||= PID_FILE end |