| Class | Daemon |
| In: |
lib/daemon.rb
|
| Parent: | Object |
| config | [R] | |
| logger | [R] | |
| workdir | [R] |
# File lib/daemon.rb, line 35 def initialize @config = nil @workdir = Pathname.new('') @detached = false add_observable(self) @logger = nil end
# 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
# File lib/daemon.rb, line 43 def config=(config) unless config.nil? or config.respond_to?(:__load__) raise(NoMethodError, 'configuration class need to respond to `load\'') end @config = config changed notify_observers(Notification::CONFIG, @config) @config end
# 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
# File lib/daemon.rb, line 101 def logger=(logger) delete_global_observer(@logger) unless @logger.nil? @logger = logger add_global_observer(@logger) changed notify_observers(Notification::START) end
# File lib/daemon.rb, line 118 def reload_config unless @config.nil? @config.__load__ changed notify_observers(Notification::RELOAD_CONFIG) @config end end
# File lib/daemon.rb, line 111 def stop_daemon stop_services changed notify_observers(Notification::STOP) exit end