Class: TinyDaemon::ProcessFile
- Inherits:
-
Struct
- Object
- Struct
- TinyDaemon::ProcessFile
- Defined in:
- lib/tiny_daemon/process_file.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#pid_dir ⇒ Object
Returns the value of attribute pid_dir.
Instance Method Summary collapse
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name
2 3 4 |
# File 'lib/tiny_daemon/process_file.rb', line 2 def app_name @app_name end |
#pid_dir ⇒ Object
Returns the value of attribute pid_dir
2 3 4 |
# File 'lib/tiny_daemon/process_file.rb', line 2 def pid_dir @pid_dir end |
Instance Method Details
#clean ⇒ Object
26 27 28 |
# File 'lib/tiny_daemon/process_file.rb', line 26 def clean FileUtils.rm(pid_file_path) if File.exists?(pid_file_path) end |
#get ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/tiny_daemon/process_file.rb', line 16 def get pid = if File.exists?(pid_file_path) IO.read(pid_file_path).strip.to_i else 0 end pid == 0 ? nil : pid end |
#pid_file_path ⇒ Object
3 4 5 |
# File 'lib/tiny_daemon/process_file.rb', line 3 def pid_file_path File.join(self.pid_dir, "#{self.app_name}.pid") end |
#store(pid) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/tiny_daemon/process_file.rb', line 7 def store(pid) raise "#{pid_file_path} already exists. The process might already run. Remove it manually if it doesn't." if File.exists?(pid_file_path) FileUtils.mkdir_p(self.pid_dir) File.open(pid_file_path, 'w') do |f| f.write("#{pid}") end end |