Module: Rpush::Daemon

Extended by:
Term::ANSIColor
Defined in:
lib/rpush/daemon.rb,
lib/rpush/daemon/adm.rb,
lib/rpush/daemon/gcm.rb,
lib/rpush/daemon/apns.rb,
lib/rpush/daemon/wpns.rb,
lib/rpush/daemon/batch.rb,
lib/rpush/daemon/feeder.rb,
lib/rpush/daemon/delivery.rb,
lib/rpush/daemon/loggable.rb,
lib/rpush/daemon/constants.rb,
lib/rpush/daemon/app_runner.rb,
lib/rpush/daemon/proc_title.rb,
lib/rpush/daemon/reflectable.rb,
lib/rpush/daemon/ring_buffer.rb,
lib/rpush/daemon/store/redis.rb,
lib/rpush/daemon/adm/delivery.rb,
lib/rpush/daemon/gcm/delivery.rb,
lib/rpush/daemon/synchronizer.rb,
lib/rpush/daemon/apns/delivery.rb,
lib/rpush/daemon/queue_payload.rb,
lib/rpush/daemon/wpns/delivery.rb,
lib/rpush/daemon/dispatcher/tcp.rb,
lib/rpush/daemon/signal_handler.rb,
lib/rpush/daemon/string_helpers.rb,
lib/rpush/daemon/tcp_connection.rb,
lib/rpush/daemon/dispatcher/http.rb,
lib/rpush/daemon/dispatcher_loop.rb,
lib/rpush/daemon/store/interface.rb,
lib/rpush/daemon/dispatcher/apns_tcp.rb,
lib/rpush/daemon/interruptible_sleep.rb,
lib/rpush/daemon/retry_header_parser.rb,
lib/rpush/daemon/store/active_record.rb,
lib/rpush/daemon/apns/feedback_receiver.rb,
lib/rpush/daemon/service_config_methods.rb,
lib/rpush/daemon/store/active_record/reconnectable.rb

Defined Under Namespace

Modules: Adm, Apns, Dispatcher, Gcm, Loggable, Reflectable, ServiceConfigMethods, Store, StringHelpers, Wpns Classes: AppRunner, Batch, Delivery, DispatcherLoop, Feeder, InterruptibleSleep, ProcTitle, QueuePayload, RetryHeaderParser, RingBuffer, SignalHandler, Synchronizer, TcpConnection, TcpConnectionError

Constant Summary collapse

HTTP_STATUS_CODES =
{
  100  => 'Continue',
  101  => 'Switching Protocols',
  102  => 'Processing',
  200  => 'OK',
  201  => 'Created',
  202  => 'Accepted',
  203  => 'Non-Authoritative Information',
  204  => 'No Content',
  205  => 'Reset Content',
  206  => 'Partial Content',
  207  => 'Multi-Status',
  226  => 'IM Used',
  300  => 'Multiple Choices',
  301  => 'Moved Permanently',
  302  => 'Found',
  303  => 'See Other',
  304  => 'Not Modified',
  305  => 'Use Proxy',
  306  => 'Reserved',
  307  => 'Temporary Redirect',
  400  => 'Bad Request',
  401  => 'Unauthorized',
  402  => 'Payment Required',
  403  => 'Forbidden',
  404  => 'Not Found',
  405  => 'Method Not Allowed',
  406  => 'Not Acceptable',
  407  => 'Proxy Authentication Required',
  408  => 'Request Timeout',
  409  => 'Conflict',
  410  => 'Gone',
  411  => 'Length Required',
  412  => 'Precondition Failed',
  413  => 'Request Entity Too Large',
  414  => 'Request-URI Too Long',
  415  => 'Unsupported Media Type',
  416  => 'Requested Range Not Satisfiable',
  417  => 'Expectation Failed',
  418  => "I'm a Teapot",
  422  => 'Unprocessable Entity',
  423  => 'Locked',
  424  => 'Failed Dependency',
  426  => 'Upgrade Required',
  429  => 'Too Many Requests',
  500  => 'Internal Server Error',
  501  => 'Not Implemented',
  502  => 'Bad Gateway',
  503  => 'Service Unavailable',
  504  => 'Gateway Timeout',
  505  => 'HTTP Version Not Supported',
  506  => 'Variant Also Negotiates',
  507  => 'Insufficient Storage',
  510  => 'Not Extended'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storeObject

Returns the value of attribute store.



54
55
56
# File 'lib/rpush/daemon.rb', line 54

def store
  @store
end

Class Method Details

.initialize_storeObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rpush/daemon.rb', line 100

def self.initialize_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

.shutdownObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rpush/daemon.rb', line 77

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
    Feeder.stop
    AppRunner.stop
    delete_pid_file
    puts green('') if Rpush.config.foreground
  end
end

.shutdown_lockObject



94
95
96
97
98
# File 'lib/rpush/daemon.rb', line 94

def self.shutdown_lock
  return @shutdown_lock if @shutdown_lock
  @shutdown_lock = Mutex.new
  @shutdown_lock
end

.startObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rpush/daemon.rb', line 57

def self.start
  Process.daemon if daemonize?
  SignalHandler.start
  initialize_store
  write_pid_file
  Synchronizer.sync

  # 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