Class Dctl::Daemon
In: lib/dctl/daemon.rb
Parent: Object

This class is used to perform daemon commands.

Methods

new   restart   run   start   status   stop   which   zap  

Included Modules

Daemonize

Public Class methods

[Source]

    # File lib/dctl/daemon.rb, line 10
10:     def initialize(cmd, pidpath, check=true)
11:       @app_path = File.expand_path(Daemon::which(cmd) || cmd)
12:       if check
13:         raise Errno::EISDIR, @app_path if File.directory? @app_path
14:         raise Errno::ENOENT, @app_path until File.file? @app_path
15:         raise Errno::EACCES, @app_path until File.executable? @app_path
16:       end
17:       @pidfile = PidFile.new pidpath, File.basename(cmd)
18:     end

[Source]

    # File lib/dctl/daemon.rb, line 20
20:     def self.which(prog_name)
21:       ENV["PATH"].split(':').map { |p| File.join p, prog_name }.find { |p| File.file? p and File.executable? p }
22:     end

Public Instance methods

[Source]

    # File lib/dctl/daemon.rb, line 36
36:     def restart(args=[], stdin='/dev/null', stdout='/dev/null', stderr='/dev/null')
37:       stop ; sleep 2 ; start(args, stdin, stdout, stderr)
38:     end

[Source]

    # File lib/dctl/daemon.rb, line 44
44:     def run(args = [])
45:       @pidfile.write
46:       exec "#{@app_path} #{args.join ' '}"
47:     end

[Source]

    # File lib/dctl/daemon.rb, line 24
24:     def start(args=[], stdin='/dev/null', stdout='/dev/null', stderr='/dev/null')
25:       @pidfile.write
26:       daemonize(stdin, stdout, stderr)
27:       @pidfile.delete
28:       run args
29:     end

[Source]

    # File lib/dctl/daemon.rb, line 49
49:     def status
50:       (pid = @pidfile.read) rescue return :unhandled
51:       Process.kill 0, pid rescue return :not_running
52:       :running
53:     end

[Source]

    # File lib/dctl/daemon.rb, line 31
31:     def stop
32:       Process.kill 'TERM', @pidfile.read
33:       zap
34:     end

[Source]

    # File lib/dctl/daemon.rb, line 40
40:     def zap
41:       @pidfile.delete
42:     end

[Validate]