Module: RExec::Daemon::ProcessFile
- Defined in:
- lib/rexec/daemon/process_file.rb
Overview
This module controls the storage and retrieval of process id files.
Class Method Summary collapse
-
.cleanup(daemon) ⇒ Object
Remove the pid file if the daemon is not running.
-
.clear(daemon) ⇒ Object
Removes the pid saved for a particular daemon.
-
.recall(daemon) ⇒ Object
Retrieves the pid for the given daemon.
-
.running(daemon) ⇒ Object
Checks whether the daemon is running by checking the saved pid and checking the corresponding process.
-
.status(daemon) ⇒ Object
This function returns the status of the daemon.
-
.store(daemon, pid) ⇒ Object
Saves the pid for the given daemon.
Class Method Details
.cleanup(daemon) ⇒ Object
Remove the pid file if the daemon is not running
54 55 56 |
# File 'lib/rexec/daemon/process_file.rb', line 54 def self.cleanup(daemon) clear(daemon) unless running(daemon) end |
.clear(daemon) ⇒ Object
Removes the pid saved for a particular daemon
36 37 38 39 40 |
# File 'lib/rexec/daemon/process_file.rb', line 36 def self.clear(daemon) if File.exist? daemon.process_file_path FileUtils.rm(daemon.process_file_path) end end |
.recall(daemon) ⇒ Object
Retrieves the pid for the given daemon
31 32 33 |
# File 'lib/rexec/daemon/process_file.rb', line 31 def self.recall(daemon) IO.read(daemon.process_file_path).to_i rescue nil end |
.running(daemon) ⇒ Object
Checks whether the daemon is running by checking the saved pid and checking the corresponding process
43 44 45 46 47 48 49 50 51 |
# File 'lib/rexec/daemon/process_file.rb', line 43 def self.running(daemon) pid = recall(daemon) return false if pid == nil gpid = Process.getpgid(pid) rescue nil return gpid != nil ? true : false end |
.status(daemon) ⇒ Object
This function returns the status of the daemon. This can be one of :running
, :unknown
(pid file exists but no corresponding process can be found) or :stopped
.
60 61 62 63 64 65 66 |
# File 'lib/rexec/daemon/process_file.rb', line 60 def self.status(daemon) if File.exist? daemon.process_file_path return ProcessFile.running(daemon) ? :running : :unknown else return :stopped end end |
.store(daemon, pid) ⇒ Object
Saves the pid for the given daemon
26 27 28 |
# File 'lib/rexec/daemon/process_file.rb', line 26 def self.store(daemon, pid) File.open(daemon.process_file_path, 'w') {|f| f << pid} end |