Class: Daemon
- Includes:
- Observable, ObservablePool, ServiceManager, Singleton
- Defined in:
- lib/daemon.rb
Defined Under Namespace
Modules: Notification
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Instance Method Summary collapse
- #clean_workdir ⇒ Object
- #detach ⇒ Object
- #detached? ⇒ Boolean
-
#initialize ⇒ Daemon
constructor
module Notification.
- #reload_config ⇒ Object
- #start_daemon(*args) ⇒ Object
- #stop_daemon ⇒ Object
Methods included from ObservablePool
#add_global_observer, #add_global_observers, #add_observable, #add_observables, #count_all_observers, #count_global_observers, #count_observables, #delete_global_observer, #delete_global_observers, #delete_observable, #delete_observables, #each_observables, #global_observer?, #list_all_observers, #list_global_observers, #list_observables, #list_observables_observed, #observable, #observable?
Methods included from Observable
#add_observers, included, #list_observers, #notify_observer, #observer?
Methods included from ServiceManager
#count_services, #each_services, #join_services, #list_services, #service_server, #start_service, #stop_service, #stop_services
Constructor Details
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
53 54 55 |
# File 'lib/daemon.rb', line 53 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
109 110 111 |
# File 'lib/daemon.rb', line 109 def logger @logger end |
#workdir ⇒ Object
Returns the value of attribute workdir.
68 69 70 |
# File 'lib/daemon.rb', line 68 def workdir @workdir end |
Instance Method Details
#clean_workdir ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/daemon.rb', line 70 def clean_workdir @workdir.each_entry do |p| next if p.to_s =~ /^\./ (@workdir + p).rmtree end changed notify_observers(Notification::CLEAN_WORKDIR) nil end |
#detach ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/daemon.rb', line 80 def detach return if @detached @detached = true if pid = fork # father exit else # son Dir.chdir(@workdir.to_s.empty? ? '/' : @workdir.to_s) Process.setsid STDIN.close STDOUT.close STDERR.close end changed notify_observers(Notification::DETACH) nil end |
#detached? ⇒ Boolean
97 98 99 |
# File 'lib/daemon.rb', line 97 def detached? @detached end |
#reload_config ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/daemon.rb', line 118 def reload_config unless @config.nil? @config.__load__ changed notify_observers(Notification::RELOAD_CONFIG) @config end end |
#start_daemon(*args) ⇒ Object
127 128 |
# File 'lib/daemon.rb', line 127 def start_daemon(*args) end |
#stop_daemon ⇒ Object
111 112 113 114 115 116 |
# File 'lib/daemon.rb', line 111 def stop_daemon stop_services changed notify_observers(Notification::STOP) exit end |