Module: NginxStage
- Extended by:
- Configuration
- Defined in:
- lib/nginx_stage.rb,
lib/nginx_stage/user.rb,
lib/nginx_stage/errors.rb,
lib/nginx_stage/version.rb,
lib/nginx_stage/pid_file.rb,
lib/nginx_stage/generator.rb,
lib/nginx_stage/application.rb,
lib/nginx_stage/socket_file.rb,
lib/nginx_stage/configuration.rb,
lib/nginx_stage/generator_helpers.rb,
lib/nginx_stage/views/app_config_view.rb,
lib/nginx_stage/views/pun_config_view.rb,
lib/nginx_stage/generators/app_list_generator.rb,
lib/nginx_stage/generators/app_clean_generator.rb,
lib/nginx_stage/generators/app_reset_generator.rb,
lib/nginx_stage/generators/app_config_generator.rb,
lib/nginx_stage/generators/nginx_list_generator.rb,
lib/nginx_stage/generators/nginx_show_generator.rb,
lib/nginx_stage/generators/pun_config_generator.rb,
lib/nginx_stage/generators/nginx_clean_generator.rb,
lib/nginx_stage/generators/nginx_process_generator.rb
Overview
The main namespace for NginxStage. Provides a global configuration.
Defined Under Namespace
Modules: AppConfigView, Application, Configuration, GeneratorHelpers, PunConfigView Classes: AppCleanGenerator, AppConfigGenerator, AppListGenerator, AppResetGenerator, Error, Generator, InvalidAppInitUrl, InvalidCommand, InvalidConfigOption, InvalidPidFile, InvalidRequest, InvalidSocket, InvalidSocketFile, InvalidSubUri, InvalidUser, MissingCommand, MissingOption, MissingPidFile, MissingSocketFile, NginxCleanGenerator, NginxListGenerator, NginxProcessGenerator, NginxShowGenerator, PidFile, PunConfigGenerator, SocketFile, StalePidFile, User
Constant Summary collapse
- VERSION =
The current version of NginxStage
"0.5.0"
Instance Attribute Summary
Attributes included from Configuration
#app_config_path, #app_passenger_env, #app_request_regex, #app_request_uri, #app_root, #app_token, #disabled_shell, #mime_types_path, #min_uid, #nginx_bin, #nginx_signals, #ondemand_portal, #ondemand_title, #ondemand_version_path, #passenger_nodejs, #passenger_python, #passenger_root, #passenger_ruby, #proxy_user, #pun_access_log_path, #pun_app_configs, #pun_config_path, #pun_error_log_path, #pun_pid_path, #pun_sendfile_root, #pun_sendfile_uri, #pun_socket_path, #pun_tmp_root, #template_root, #user_regex
Class Method Summary collapse
-
.active_users ⇒ Array<User>
List of users with nginx processes running.
-
.as_user(user) { ... } ⇒ Object
Run Ruby block as a different user if possible NB: Will forego user switching if current process is not root-owned.
-
.config_file ⇒ String
Path to the configuration file.
-
.nginx_args(user:, signal: nil) ⇒ Array<String>
Arguments used during execution of nginx binary.
-
.nginx_env(user:) ⇒ Hash{String=>String}
Environment used during execution of nginx binary.
-
.ondemand_version ⇒ String?
The current version of OnDemand installed.
-
.parse_app_request(request:) ⇒ Hash
Regex used to parse an app request.
-
.portal ⇒ String
The unique name of the hosted OnDemand portal used to namespace apps, their data, and logging information.
-
.root ⇒ String
Root path of this library.
-
.staged_apps ⇒ Hash
Get a hash of all the staged app configs.
-
.title ⇒ String
The title of the hosted OnDemand portal.
Methods included from Configuration
configure, default_config_path, extended, read_configuration, set_default_configuration
Class Method Details
.active_users ⇒ Array<User>
List of users with nginx processes running
142 143 144 |
# File 'lib/nginx_stage.rb', line 142 def self.active_users Dir[pun_pid_path(user: '*')].map{|v| User.new v[/#{pun_pid_path(user: '(.+)')}/, 1]} end |
.as_user(user) { ... } ⇒ Object
Run Ruby block as a different user if possible NB: Will forego user switching if current process is not root-owned
177 178 179 |
# File 'lib/nginx_stage.rb', line 177 def self.as_user(user, &block) (Process.uid == 0) && user ? sudo(user, &block) : block.call end |
.config_file ⇒ String
Path to the configuration file
33 34 35 |
# File 'lib/nginx_stage.rb', line 33 def self.config_file ENV["NGINX_STAGE_CONFIG_FILE"] || '/etc/ood/config/nginx_stage.yml' end |
.nginx_args(user:, signal: nil) ⇒ Array<String>
Arguments used during execution of nginx binary
134 135 136 137 138 |
# File 'lib/nginx_stage.rb', line 134 def self.nginx_args(user:, signal: nil) args = ['-c', pun_config_path(user: user)] args.push('-s', signal.to_s) if signal args end |
.nginx_env(user:) ⇒ Hash{String=>String}
Environment used during execution of nginx binary
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/nginx_stage.rb', line 112 def self.nginx_env(user:) { "USER" => user, "ONDEMAND_VERSION" => ondemand_version, "ONDEMAND_PORTAL" => portal, "ONDEMAND_TITLE" => title, # backwards compatibility "OOD_PORTAL" => ondemand_portal, "OOD_DASHBOARD_TITLE" => ondemand_title, } end |
.ondemand_version ⇒ String?
The current version of OnDemand installed
45 46 47 48 49 50 |
# File 'lib/nginx_stage.rb', line 45 def self.ondemand_version version = File.read(ondemand_version_path).strip version.empty? ? nil : version rescue nil end |
.parse_app_request(request:) ⇒ Hash
Regex used to parse an app request
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nginx_stage.rb', line 93 def self.parse_app_request(request:) app_info = {} app_request_regex.each do |env, regex| if matches = regex.match(request) app_info[:env] = env matches.names.each { |k| app_info[k.to_sym] = matches[k] } break end end raise InvalidRequest, "invalid request: #{request}" if app_info.empty? app_info end |
.portal ⇒ String
The unique name of the hosted OnDemand portal used to namespace apps, their data, and logging information
59 60 61 62 63 64 65 66 |
# File 'lib/nginx_stage.rb', line 59 def self.portal portal = ondemand_portal.to_s.strip if portal.empty? "ondemand" else portal.downcase.gsub(/\s+/, "_") end end |
.root ⇒ String
Root path of this library
27 28 29 |
# File 'lib/nginx_stage.rb', line 27 def self.root File.dirname __dir__ end |
.staged_apps ⇒ Hash
Get a hash of all the staged app configs
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/nginx_stage.rb', line 159 def self.staged_apps staged_apps = {} @app_config_path.each do |env, path| staged_apps[env] = Dir[app_config_path(env: env, owner: '*', name: '*')].map do |v| matches = /#{app_config_path(env: env, owner: '(?<owner>.+)', name: '(?<name>.+)')}/.match(v) { owner: matches.names.include?('owner') ? matches[:owner] : nil, name: matches.names.include?('name') ? matches[:name] : nil } end end staged_apps end |
.title ⇒ String
The title of the hosted OnDemand portal
74 75 76 77 78 79 80 81 |
# File 'lib/nginx_stage.rb', line 74 def self.title title = ondemand_title.to_s.strip if title.empty? "Open OnDemand" else title end end |