module Rpush::Daemon
Constants
- HTTP_STATUS_CODES
Attributes
store[RW]
Public Class Methods
common_init()
click to toggle source
# File lib/rpush/daemon.rb, line 120 def self.common_init init_store init_plugins end
shutdown()
click to toggle source
# File lib/rpush/daemon.rb, line 98 def self.shutdown if Rpush.config.foreground # Eat the '^C' STDOUT.write("\b\b") STDOUT.flush end Rpush.logger.info('Shutting down... ', true) shutdown_lock.synchronize do Rpc::Server.stop Feeder.stop AppRunner.stop delete_pid_file puts ANSI.green { '✔' } if Rpush.config.foreground end end
shutdown_lock()
click to toggle source
# File lib/rpush/daemon.rb, line 116 def self.shutdown_lock @shutdown_lock ||= Mutex.new end
start()
click to toggle source
# File lib/rpush/daemon.rb, line 77 def self.start Process.daemon if daemonize? write_pid_file SignalHandler.start common_init Synchronizer.sync Rpc::Server.start # No further store connections will be made from this thread. store.release_connection Rpush.logger.info('Rpush operational.') show_welcome_if_needed # Blocking call, returns after Feeder.stop is called from another thread. Feeder.start # Wait for shutdown to complete. shutdown_lock.synchronize { true } end
Protected Class Methods
daemonize?()
click to toggle source
# File lib/rpush/daemon.rb, line 147 def self.daemonize? !(Rpush.config.push || Rpush.config.foreground || Rpush.config.embedded || Rpush.jruby?) end
delete_pid_file()
click to toggle source
# File lib/rpush/daemon.rb, line 162 def self.delete_pid_file pid_file = Rpush.config.pid_file File.delete(pid_file) if !pid_file.blank? && File.exist?(pid_file) end
init_plugins()
click to toggle source
# File lib/rpush/daemon.rb, line 140 def self.init_plugins Rpush.plugins.each do |name, plugin| plugin.init_block.call Rpush.logger.info("[plugin:#{name}] Loaded.") end end
init_store()
click to toggle source
# File lib/rpush/daemon.rb, line 127 def self.init_store return if store begin name = Rpush.config.client.to_s require "rpush/daemon/store/#{name}" self.store = Rpush::Daemon::Store.const_get(name.camelcase).new rescue StandardError, LoadError => e Rpush.logger.error("Failed to load '#{Rpush.config.client}' storage backend.") Rpush.logger.error(e) exit 1 end end
show_welcome_if_needed()
click to toggle source
# File lib/rpush/daemon.rb, line 167 def self.show_welcome_if_needed if Rpush::Daemon::AppRunner.app_ids.count == 0 puts <<-EOS * #{ANSI.green { 'Is this your first time using Rpush?' }} You need to create an App before you can start using Rpush. Please refer to the documentation at https://github.com/rpush/rpush EOS end end
write_pid_file()
click to toggle source
# File lib/rpush/daemon.rb, line 151 def self.write_pid_file unless Rpush.config.pid_file.blank? begin FileUtils.mkdir_p(File.dirname(Rpush.config.pid_file)) File.open(Rpush.config.pid_file, 'w') { |f| f.puts Process.pid } rescue SystemCallError => e Rpush.logger.error("Failed to write PID to '#{Rpush.config.pid_file}': #{e.inspect}") end end end