Class: HiddenHippo::Daemon
- Inherits:
-
Object
- Object
- HiddenHippo::Daemon
show all
- Includes:
- Paths
- Defined in:
- lib/hidden_hippo/daemon.rb
Instance Method Summary
collapse
Methods included from Paths
#home
Constructor Details
#initialize(name) ⇒ Daemon
Returns a new instance of Daemon.
7
8
9
|
# File 'lib/hidden_hippo/daemon.rb', line 7
def initialize(name)
@name = name
end
|
Instance Method Details
#start ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/hidden_hippo/daemon.rb', line 11
def start
if running?
puts "#{@name} is already running"
puts "If this is not the case, delete #{pid_file}"
exit 1
else
if stale_pid_file?
puts 'Found a stale pid file, removing it'
pid_file.delete
end
pid_file.dirname.mkpath
log_file.dirname.mkpath
pid = run
File.write pid_file, pid
puts "Started #{@name} service"
end
end
|
#status ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/hidden_hippo/daemon.rb', line 44
def status
if pid_file.exist?
pid = pid_file.read.to_i
if HiddenHippo.pid_exists? pid
puts "#{@name} is running with pid #{pid}"
exit 0
else
puts "#{@name} is not running, but the pid file is present"
puts "You may need to delete #{pid_file}"
exit 2
end
else
puts "#{@name} is not running"
exit 1
end
end
|
#stop ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/hidden_hippo/daemon.rb', line 33
def stop
if pid_file.exist?
pid = pid_file.read.to_i
Process.kill 15, pid
pid_file.delete
else
puts "#{@name} service is not running"
exit 1
end
end
|