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

Instance Method Summary collapse

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_fileObject



49
50
51
# File 'lib/plugins/daemon.rb', line 49

def log_file
  @options[:log_file]
end

#pid_fileObject

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

#scriptObject



53
54
55
# File 'lib/plugins/daemon.rb', line 53

def script
  @options[:script] ||= File.expand_path($0)
end

#shutdownObject



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

#startupObject



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