Module: NginxStage::Configuration
- Included in:
- NginxStage
- Defined in:
- lib/nginx_stage/configuration.rb
Overview
An object that stores the configuration options to control NginxStage’s behavior.
Instance Attribute Summary collapse
-
#app_config_path(env:, owner:, name:) ⇒ String
Path to generated NGINX app config.
-
#app_passenger_env(env:, owner:, name:) ⇒ String
The passenger environment used for the given app environment.
-
#app_request_regex ⇒ Hash
Regular expression used to distinguish the environment from a request URI and from there distinguish the app owner and app name.
-
#app_request_uri(env:, owner:, name:) ⇒ String
The URI used to access the app from the browser, not including any base-uri.
-
#app_root(env:, owner:, name:) ⇒ String
Path to the app root on the local filesystem.
-
#app_token(env:, owner:, name:) ⇒ String
Token used to identify a given app from the other apps.
-
#disabled_shell ⇒ String
Restrict starting up per-user NGINX process as user with this shell.
-
#mime_types_path ⇒ String
Path to system-installed NGINX mime.types config file.
-
#min_uid ⇒ Integer
Minimum user id required to run the per-user NGINX as this user.
-
#nginx_bin ⇒ String
Path to system-installed NGINX binary.
-
#nginx_signals ⇒ Array<Symbol>
A whitelist of signals that can be sent to the NGINX process.
-
#passenger_nodejs ⇒ String
Path to system-installed NodeJS binary.
-
#passenger_python ⇒ String
Path to system-installed python binary.
-
#passenger_root ⇒ String
Path to system-installed Passenger locations.ini file.
-
#passenger_ruby ⇒ String
Path to system-installed Ruby binary.
-
#proxy_user ⇒ String
The reverse proxy daemon user used to access the sockets.
-
#pun_access_log_path(user:) ⇒ String
Path to the user’s personal access.log.
-
#pun_app_configs(user:) ⇒ Array<Hash>
List of hashes that help define the location of the app configs for the per-user NGINX config.
-
#pun_config_path(user:) ⇒ String
Root location where per-user NGINX configs are generated Path to generated per-user NGINX config file.
-
#pun_error_log_path(user:) ⇒ String
Path to the user’s personal error.log.
-
#pun_pid_path(user:) ⇒ String
Path to the user’s per-user NGINX pid file.
-
#pun_sendfile_root(user:) ⇒ String
Path to the local filesystem root where the per-user Nginx serves files from with the sendfile feature.
-
#pun_sendfile_uri ⇒ String
The internal URI used to access the filesystem for downloading files from the browser, not including any base-uri.
-
#pun_socket_path(user:) ⇒ String
Path to the user’s per-user NGINX socket file.
-
#pun_tmp_root(user:) ⇒ String
Path to user’s personal tmp root.
-
#template_root ⇒ String
Location of ERB templates used as NGINX configs.
-
#user_regex ⇒ Regexp
Regular expression used to validate a given user name.
Class Method Summary collapse
-
.extended(base) ⇒ Object
Sets default configuration options in any class that extends Configuration.
Instance Method Summary collapse
-
#configure {|config| ... } ⇒ void
Yields the configuration object.
-
#default_config_path ⇒ String
Default configuration file.
-
#read_configuration(file) ⇒ void
Read in a configuration from a file.
-
#set_default_configuration ⇒ void
Sets the default configuration options.
Instance Attribute Details
#app_config_path(env:, owner:, name:) ⇒ String
Path to generated NGINX app config
183 184 185 |
# File 'lib/nginx_stage/configuration.rb', line 183 def app_config_path(env:, owner:, name:) File. @app_config_path[env] % {env: env, owner: owner, name: name} end |
#app_passenger_env(env:, owner:, name:) ⇒ String
The passenger environment used for the given app environment
273 274 275 |
# File 'lib/nginx_stage/configuration.rb', line 273 def app_passenger_env(env:, owner:, name:) @app_passenger_env.fetch(env, "production") end |
#app_request_regex ⇒ Hash
Regular expression used to distinguish the environment from a request URI and from there distinguish the app owner and app name
236 237 238 |
# File 'lib/nginx_stage/configuration.rb', line 236 def app_request_regex @app_request_regex.each_with_object({}) { |(k, v), h| h[k] = ::Regexp.new v } end |
#app_request_uri(env:, owner:, name:) ⇒ String
The URI used to access the app from the browser, not including any base-uri
223 224 225 226 227 |
# File 'lib/nginx_stage/configuration.rb', line 223 def app_request_uri(env:, owner:, name:) @app_request_uri.fetch(env) do raise InvalidRequest, "invalid request environment: #{env}" end % {env: env, owner: owner, name: name} end |
#app_root(env:, owner:, name:) ⇒ String
Path to the app root on the local filesystem
201 202 203 204 205 206 207 |
# File 'lib/nginx_stage/configuration.rb', line 201 def app_root(env:, owner:, name:) File.( @app_root.fetch(env) do raise InvalidRequest, "invalid request environment: #{env}" end % {env: env, owner: owner, name: name} ) end |
#app_token(env:, owner:, name:) ⇒ String
Token used to identify a given app from the other apps
254 255 256 257 258 |
# File 'lib/nginx_stage/configuration.rb', line 254 def app_token(env:, owner:, name:) @app_token.fetch(env) do raise InvalidRequest, "invalid request environment: #{env}" end % {env: env, owner: owner, name: name} end |
#disabled_shell ⇒ String
Restrict starting up per-user NGINX process as user with this shell. NB: This only affects the pun command, you are still able to
start or stop the PUN using other commands (e.g., <tt>nginx</tt>,
<tt>nginx_clean</tt>, ...)
301 302 303 |
# File 'lib/nginx_stage/configuration.rb', line 301 def disabled_shell @disabled_shell end |
#mime_types_path ⇒ String
Path to system-installed NGINX mime.types config file
33 34 35 |
# File 'lib/nginx_stage/configuration.rb', line 33 def mime_types_path @mime_types_path end |
#min_uid ⇒ Integer
Minimum user id required to run the per-user NGINX as this user. This restricts running processes as special users (i.e., ‘root’)
294 295 296 |
# File 'lib/nginx_stage/configuration.rb', line 294 def min_uid @min_uid end |
#nginx_bin ⇒ String
Path to system-installed NGINX binary
25 26 27 |
# File 'lib/nginx_stage/configuration.rb', line 25 def nginx_bin @nginx_bin end |
#nginx_signals ⇒ Array<Symbol>
A whitelist of signals that can be sent to the NGINX process
29 30 31 |
# File 'lib/nginx_stage/configuration.rb', line 29 def nginx_signals @nginx_signals end |
#passenger_nodejs ⇒ String
Path to system-installed NodeJS binary
45 46 47 |
# File 'lib/nginx_stage/configuration.rb', line 45 def passenger_nodejs @passenger_nodejs end |
#passenger_python ⇒ String
Path to system-installed python binary
49 50 51 |
# File 'lib/nginx_stage/configuration.rb', line 49 def passenger_python @passenger_python end |
#passenger_root ⇒ String
Path to system-installed Passenger locations.ini file
37 38 39 |
# File 'lib/nginx_stage/configuration.rb', line 37 def passenger_root @passenger_root end |
#passenger_ruby ⇒ String
Path to system-installed Ruby binary
41 42 43 |
# File 'lib/nginx_stage/configuration.rb', line 41 def passenger_ruby @passenger_ruby end |
#proxy_user ⇒ String
The reverse proxy daemon user used to access the sockets
21 22 23 |
# File 'lib/nginx_stage/configuration.rb', line 21 def proxy_user @proxy_user end |
#pun_access_log_path(user:) ⇒ String
Path to the user’s personal access.log
86 87 88 |
# File 'lib/nginx_stage/configuration.rb', line 86 def pun_access_log_path(user:) File. @pun_access_log_path % {user: user} end |
#pun_app_configs(user:) ⇒ Array<Hash>
List of hashes that help define the location of the app configs for the per-user NGINX config. These will be arguments for #app_config_path.
157 158 159 160 161 162 163 164 |
# File 'lib/nginx_stage/configuration.rb', line 157 def pun_app_configs(user:) @pun_app_configs.map do |envmt| envmt.each_with_object({}) do |(k, v), h| h[k] = v.respond_to?(:%) ? (v % {user: user}) : v h[k] = v.to_sym if k == :env end end end |
#pun_config_path(user:) ⇒ String
Root location where per-user NGINX configs are generated Path to generated per-user NGINX config file
62 63 64 |
# File 'lib/nginx_stage/configuration.rb', line 62 def pun_config_path(user:) File. @pun_config_path % {user: user} end |
#pun_error_log_path(user:) ⇒ String
Path to the user’s personal error.log
98 99 100 |
# File 'lib/nginx_stage/configuration.rb', line 98 def pun_error_log_path(user:) File. @pun_error_log_path % {user: user} end |
#pun_pid_path(user:) ⇒ String
Path to the user’s per-user NGINX pid file
110 111 112 |
# File 'lib/nginx_stage/configuration.rb', line 110 def pun_pid_path(user:) File. @pun_pid_path % {user: user} end |
#pun_sendfile_root(user:) ⇒ String
Path to the local filesystem root where the per-user Nginx serves files from with the sendfile feature
135 136 137 |
# File 'lib/nginx_stage/configuration.rb', line 135 def pun_sendfile_root(user:) File. @pun_sendfile_root % {user: user} end |
#pun_sendfile_uri ⇒ String
The internal URI used to access the filesystem for downloading files from the browser, not including any base-uri
147 148 149 |
# File 'lib/nginx_stage/configuration.rb', line 147 def pun_sendfile_uri @pun_sendfile_uri end |
#pun_socket_path(user:) ⇒ String
Path to the user’s per-user NGINX socket file
122 123 124 |
# File 'lib/nginx_stage/configuration.rb', line 122 def pun_socket_path(user:) File. @pun_socket_path % {user: user} end |
#pun_tmp_root(user:) ⇒ String
Path to user’s personal tmp root
74 75 76 |
# File 'lib/nginx_stage/configuration.rb', line 74 def pun_tmp_root(user:) File. @pun_tmp_root % {user: user} end |
#template_root ⇒ String
Location of ERB templates used as NGINX configs
13 14 15 |
# File 'lib/nginx_stage/configuration.rb', line 13 def template_root @template_root end |
#user_regex ⇒ Regexp
Regular expression used to validate a given user name
285 286 287 |
# File 'lib/nginx_stage/configuration.rb', line 285 def user_regex /\A#{@user_regex}\z/ end |
Class Method Details
.extended(base) ⇒ Object
Sets default configuration options in any class that extends NginxStage::Configuration
326 327 328 |
# File 'lib/nginx_stage/configuration.rb', line 326 def self.extended(base) base.set_default_configuration end |
Instance Method Details
#configure {|config| ... } ⇒ void
This method returns an undefined value.
Yields the configuration object.
321 322 323 |
# File 'lib/nginx_stage/configuration.rb', line 321 def configure yield self end |
#default_config_path ⇒ String
Default configuration file
309 310 311 312 313 314 315 316 |
# File 'lib/nginx_stage/configuration.rb', line 309 def default_config_path config = config_file unless File.file?(config) config = File.join root, 'config', 'nginx_stage.yml' warn "[DEPRECATION] The file '#{config}' is being deprecated. Please move this file to '#{config_file}'." if File.file?(config) end config end |
#read_configuration(file) ⇒ void
This method returns an undefined value.
Read in a configuration from a file
399 400 401 402 403 404 405 406 407 408 |
# File 'lib/nginx_stage/configuration.rb', line 399 def read_configuration(file) config_hash = symbolize(YAML.load_file(file)) || {} config_hash.each do |k,v| if instance_variable_defined? "@#{k}" self.send("#{k}=", v) else $stderr.puts %{Warning: invalid configuration option "#{k}"} end end end |
#set_default_configuration ⇒ void
This method returns an undefined value.
Sets the default configuration options
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/nginx_stage/configuration.rb', line 332 def set_default_configuration self.template_root = "#{root}/templates" self.proxy_user = 'apache' self.nginx_bin = '/opt/rh/nginx16/root/usr/sbin/nginx' self.nginx_signals = i(stop quit reopen reload) self.mime_types_path = '/opt/rh/nginx16/root/etc/nginx/mime.types' self.passenger_root = '/opt/rh/rh-passenger40/root/usr/share/passenger/phusion_passenger/locations.ini' self.passenger_ruby = "#{root}/bin/ruby" self.passenger_nodejs = "#{root}/bin/node" self.passenger_python = "#{root}/bin/python" self.pun_config_path = '/var/lib/nginx/config/puns/%{user}.conf' self.pun_tmp_root = '/var/lib/nginx/tmp/%{user}' self.pun_access_log_path = '/var/log/nginx/%{user}/access.log' self.pun_error_log_path = '/var/log/nginx/%{user}/error.log' self.pun_pid_path = '/var/run/nginx/%{user}/passenger.pid' self.pun_socket_path = '/var/run/nginx/%{user}/passenger.sock' self.pun_sendfile_root = '/' self.pun_sendfile_uri = '/sendfile' self.pun_app_configs = [ {env: :dev, owner: '%{user}', name: '*'}, {env: :usr, owner: '*', name: '*'}, {env: :sys, owner: '', name: '*'} ] self.app_config_path = { dev: '/var/lib/nginx/config/apps/dev/%{owner}/%{name}.conf', usr: '/var/lib/nginx/config/apps/usr/%{owner}/%{name}.conf', sys: '/var/lib/nginx/config/apps/sys/%{name}.conf' } self.app_root = { dev: '~%{owner}/ondemand/dev/%{name}', usr: '/var/www/ood/apps/usr/%{owner}/gateway/%{name}', sys: '/var/www/ood/apps/sys/%{name}' } self.app_request_uri = { dev: '/dev/%{name}', usr: '/usr/%{owner}/%{name}', sys: '/sys/%{name}' } self.app_request_regex = { dev: '^/dev/(?<name>[-\w.]+)', usr: '^/usr/(?<owner>[\w]+)/(?<name>[-\w.]+)', sys: '^/sys/(?<name>[-\w.]+)' } self.app_token = { dev: 'dev/%{owner}/%{name}', usr: 'usr/%{owner}/%{name}', sys: 'sys/%{name}' } self.app_passenger_env = { dev: 'development', usr: 'production', sys: 'production' } self.user_regex = '[\w@\.\-]+' self.min_uid = 1000 self.disabled_shell = '/access/denied' read_configuration(default_config_path) if File.file?(default_config_path) end |