Module: LND::Tool::Daemon
- Defined in:
- lib/lnd/tool/daemon.rb
Overview
Daemon module for cli
Class Method Summary collapse
-
.base_dir ⇒ Pathname
Get base directory path.
-
.db_path ⇒ Pathname
Get database file path.
-
.pid_file? ⇒ Boolean
Check whether pid file exist?.
-
.pid_path ⇒ Pathname
Get pid file path.
-
.running? ⇒ Boolean
Check whether daemon running?.
-
.start ⇒ Object
Start block program as daemon.
-
.stop ⇒ Object
Stop daemon.
Class Method Details
.base_dir ⇒ Pathname
Get base directory path.
14 15 16 |
# File 'lib/lnd/tool/daemon.rb', line 14 def base_dir Pathname.new(File.("#{Dir.home}/.lnd-tool")) end |
.db_path ⇒ Pathname
Get database file path.
20 21 22 |
# File 'lib/lnd/tool/daemon.rb', line 20 def db_path base_dir.join('storage.db') end |
.pid_file? ⇒ Boolean
Check whether pid file exist?
32 33 34 |
# File 'lib/lnd/tool/daemon.rb', line 32 def pid_file? pid_path.file? end |
.pid_path ⇒ Pathname
Get pid file path.
26 27 28 |
# File 'lib/lnd/tool/daemon.rb', line 26 def pid_path base_dir.join('pid') end |
.running? ⇒ Boolean
Check whether daemon running?
38 39 40 41 42 |
# File 'lib/lnd/tool/daemon.rb', line 38 def running? base_dir.exist? && pid_file? && Process.kill(0, pid_path.read.to_i) == 1 rescue Errno::ESRCH false end |
.start ⇒ Object
Start block program as daemon.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/lnd/tool/daemon.rb', line 50 def start base_dir.mkdir unless base_dir.exist? raise LND::Tool::Error, "process(#{pid_path.read.to_i}) already running." if running? Process.daemon(true) pid_path.write(Process.pid.to_s) yield ensure pid_path.delete if pid_file? end |
.stop ⇒ Object
Stop daemon.
45 46 47 |
# File 'lib/lnd/tool/daemon.rb', line 45 def stop Process.kill('KILL', pid_path.read.to_i) if running? end |