Module: Revenant::Daemon
- Defined in:
- lib/plugins/daemon.rb
Overview
“startup” and “shutdown” are the methods Task expects modules like this one to replace.
Class Method Summary collapse
-
.install(task) ⇒ Object
Installs this plugin in the given
task
.
Instance Method Summary collapse
- #log_file ⇒ Object
-
#pid_file ⇒ Object
Everything else is a daemon implementation detail.
- #script ⇒ Object
- #shutdown ⇒ Object
- #startup ⇒ Object
Class Method Details
.install(task) ⇒ Object
Installs this plugin in the given task
. Out of the box, this is always to provide daemon support. install
is expected to know when to do nothing.
11 12 13 14 15 16 17 |
# File 'lib/plugins/daemon.rb', line 11 def self.install(task) if task.daemon? class << task include ::Revenant::Daemon end end end |
Instance Method Details
#log_file ⇒ Object
49 50 51 |
# File 'lib/plugins/daemon.rb', line 49 def log_file @options[:log_file] end |
#pid_file ⇒ Object
Everything else is a daemon implementation detail.
45 46 47 |
# File 'lib/plugins/daemon.rb', line 45 def pid_file @options[:pid_file] ||= File.join("/tmp", "#{@name}.pid") end |
#script ⇒ Object
53 54 55 |
# File 'lib/plugins/daemon.rb', line 53 def script @options[:script] ||= File.($0) end |
#shutdown ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/plugins/daemon.rb', line 25 def shutdown @pid.remove if restart_pending? log "#{name} is restarting" if @original_dir Dir.chdir @original_dir end system script else log "#{name} is shutting down" end exit 0 end |
#startup ⇒ Object
19 20 21 22 23 |
# File 'lib/plugins/daemon.rb', line 19 def startup @original_dir = ::Revenant.working_directory daemonize log "#{name} is starting" end |