Class: Asmodai::Daemon
Defined Under Namespace
Modules: ProcessManagement, RakeTask
Class Method Summary
collapse
Instance Method Summary
collapse
is_running?, pid, pid_file_path, terminate
Methods included from RakeTask
install_rake_task
Constructor Details
#initialize ⇒ Daemon
Returns a new instance of Daemon.
24
25
|
# File 'lib/asmodai/daemon.rb', line 24
def initialize
end
|
Class Method Details
.autoload_paths ⇒ Object
11
12
13
|
# File 'lib/asmodai/daemon.rb', line 11
def autoload_paths
@autoload_paths ||= []
end
|
.daemon_name ⇒ Object
19
20
21
|
# File 'lib/asmodai/daemon.rb', line 19
def daemon_name
@daemon_name || name.split("::").last.to_s.underscore
end
|
.set_daemon_name(name) ⇒ Object
15
16
17
|
# File 'lib/asmodai/daemon.rb', line 15
def set_daemon_name(name)
@daemon_name=name.to_s.underscore
end
|
Instance Method Details
#daemon_name ⇒ Object
27
28
29
|
# File 'lib/asmodai/daemon.rb', line 27
def daemon_name
self.class.daemon_name
end
|
#foreground ⇒ Object
36
37
38
39
|
# File 'lib/asmodai/daemon.rb', line 36
def foreground
prepare_run
perform_run
end
|
#on_signal(sig) ⇒ Object
31
32
33
|
# File 'lib/asmodai/daemon.rb', line 31
def on_signal(sig)
end
|
#start ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/asmodai/daemon.rb', line 41
def start
prepare_run
raise 'Fork failed' if (pid=fork) == -1
if !pid
Process.setsid
raise 'Fork failed' if (pid=fork) == -1
if !pid
pid = Process.pid
self.class.pid_file_path.open("w") do |f|
f.puts pid
end
$stdin.reopen('/dev/null')
$stdout.reopen(log_file)
$stderr.reopen(log_file)
logger.info "Starting up #{daemon_name} at #{Time.now}, pid: #{Process.pid}"
perform_run
end
end
end
|