Method: Sunshine::Daemon#initialize

Defined in:
lib/sunshine/daemon.rb

#initialize(app, options = {}) ⇒ Daemon

Daemon objects need only an App object to be instantiated but many options are available for customization:

:bin

bin_path - Set the daemon app bin path (e.g. usr/local/nginx)

defaults to svr_name.

:processes

prcss_num - Number of processes daemon should run;

defaults to 1.

:config_file

name - Remote file name the daemon should load;

defaults to svr_name.conf

:config_path

path - Remote path daemon configs will be uploaded to;

defaults to app.current_path/daemons/svr_name

:config_template

path - Glob path to tempates to render and upload;

defaults to sunshine_path/templates/svr_name/*

:log_path

path - Path to where the log files should be output;

defaults to app.log_path.

:pid

pid_path - Set the pid; default: app.shared_path/pids/svr_name.pid

defaults to app.shared_path/pids/svr_name.pid.

:sudo

bool|str - Define if sudo should be used to run the daemon,

and/or with what user.

:timeout

int - Timeout to use for daemon config, defaults to 0.

The Daemon constructor also supports any App#find options to narrow the server apps to use. Note: subclasses such as Server already have a default :role that can be overridden.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/sunshine/daemon.rb', line 89

def initialize app, options={}
  @options = options
  @app     = app

  @name        = options[:name] || self.class.short_name
  @pid         = options[:pid]  || "#{@app.shared_path}/pids/#{@name}.pid"
  @bin         = options[:bin]  || self.class.short_name
  @sudo        = options[:sudo]
  @timeout     = options[:timeout]   || 0
  @dep_name    = options[:dep_name]  || self.class.short_name
  @processes   = options[:processes] || 1
  @sigkill     = 'QUIT'

  @config_template = options[:config_template] ||
    "#{Sunshine::ROOT}/templates/#{self.class.short_name}/*"

  @config_path     = options[:config_path] ||
    "#{@app.current_path}/daemons/#{@name}"

  @config_file = options[:config_file] || "#{self.class.short_name}.conf"

  log_path  = options[:log_path] || @app.log_path
  @log_files = {
    :stderr => "#{log_path}/#{@name}_stderr.log",
    :stdout => "#{log_path}/#{@name}_stdout.log"
  }

  @start_cmd = @stop_cmd = @restart_cmd = @status_cmd = nil

  @setup_successful = nil

  register_after_user_script
end