Class: Appserver::ServerDir
- Inherits:
-
Struct
- Object
- Struct
- Appserver::ServerDir
- Defined in:
- lib/appserver/server_dir.rb
Constant Summary collapse
- CONFIG_FILE_NAME =
'appserver.conf.rb'
- SETTINGS_DEFAULTS =
{ :monit_conf => 'monitrc', :monit_reload => '/usr/sbin/monit reload', :nginx_conf => 'nginx.conf', :nginx_reload => '/usr/sbin/nginx -s reload', :nginx_reopen => '/usr/sbin/nginx -s reopen', :logrotate_conf => 'logrotate.conf', }
- SETTINGS_EXPAND =
[ :monit_conf, :nginx_conf, :logrotate_conf ]
Instance Attribute Summary collapse
-
#logrotate_conf ⇒ Object
Returns the value of attribute logrotate_conf.
-
#monit_conf ⇒ Object
Returns the value of attribute monit_conf.
-
#monit_reload ⇒ Object
Returns the value of attribute monit_reload.
-
#nginx_conf ⇒ Object
Returns the value of attribute nginx_conf.
-
#nginx_reload ⇒ Object
Returns the value of attribute nginx_reload.
-
#nginx_reopen ⇒ Object
Returns the value of attribute nginx_reopen.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
- .config_file_template ⇒ Object
- .discover(path = '.', options = {}) ⇒ Object
- .init(path, options = {}) ⇒ Object
Instance Method Summary collapse
- #app(name) ⇒ Object
- #apps ⇒ Object
- #apps_path ⇒ Object
- #appserver_cmd(*args) ⇒ Object
- #config_file ⇒ Object
-
#initialize(path, options = {}) ⇒ ServerDir
constructor
A new instance of ServerDir.
- #log_path ⇒ Object
- #repository(path) ⇒ Object
- #tmp_path ⇒ Object
- #write_configs ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ ServerDir
Returns a new instance of ServerDir.
46 47 48 49 50 51 52 53 |
# File 'lib/appserver/server_dir.rb', line 46 def initialize (path, = {}) self.path = File.(path) # Load and apply configuration settings app_keys = App::SETTINGS_DEFAULTS.keys global_keys = SETTINGS_DEFAULTS.keys + App::SETTINGS_DEFAULTS.keys @config = Configurator.new(File.exist?(config_file) ? config_file : nil, global_keys, app_keys) @config.apply!(self) end |
Instance Attribute Details
#logrotate_conf ⇒ Object
Returns the value of attribute logrotate_conf
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def logrotate_conf @logrotate_conf end |
#monit_conf ⇒ Object
Returns the value of attribute monit_conf
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def monit_conf @monit_conf end |
#monit_reload ⇒ Object
Returns the value of attribute monit_reload
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def monit_reload @monit_reload end |
#nginx_conf ⇒ Object
Returns the value of attribute nginx_conf
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def nginx_conf @nginx_conf end |
#nginx_reload ⇒ Object
Returns the value of attribute nginx_reload
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def nginx_reload @nginx_reload end |
#nginx_reopen ⇒ Object
Returns the value of attribute nginx_reopen
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def nginx_reopen @nginx_reopen end |
#path ⇒ Object
Returns the value of attribute path
7 8 9 |
# File 'lib/appserver/server_dir.rb', line 7 def path @path end |
Class Method Details
.config_file_template ⇒ Object
22 23 24 |
# File 'lib/appserver/server_dir.rb', line 22 def self.config_file_template File.("../#{CONFIG_FILE_NAME}", __FILE__) end |
.discover(path = '.', options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/appserver/server_dir.rb', line 26 def self.discover (path = '.', = {}) if File.exist?(File.join(path, CONFIG_FILE_NAME)) new(path, ) elsif path != '/' discover(File.('..', path), ) else raise NotInitializedError end end |
.init(path, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/appserver/server_dir.rb', line 36 def self.init (path, = {}) raise DirectoryAlreadyExistError if File.exist?(path) && ![:force] FileUtils.mkdir_p path Dir.chdir(path) do FileUtils.cp config_file_template, CONFIG_FILE_NAME FileUtils.mkdir_p ['apps', 'tmp', 'log'] end new(path, ) end |
Instance Method Details
#app(name) ⇒ Object
76 77 78 79 |
# File 'lib/appserver/server_dir.rb', line 76 def app (name) @apps ||= {} @apps[name] ||= App.new(self, name, @config) end |
#apps ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/appserver/server_dir.rb', line 81 def apps Dir.glob(File.join(apps_path, '*')). select { |f| File.directory?(f) }. map { |f| File.basename(f) }. reject { |f| f =~ /\.(tmp|old|new)$/ }. map { |name| app(name) } end |
#apps_path ⇒ Object
64 65 66 |
# File 'lib/appserver/server_dir.rb', line 64 def apps_path File.join(path, 'apps') end |
#appserver_cmd(*args) ⇒ Object
59 60 61 62 |
# File 'lib/appserver/server_dir.rb', line 59 def appserver_cmd (*args) cmd = File.('../../../bin/appserver', __FILE__) "#{cmd} -d #{path} #{args.join(' ')}" end |
#config_file ⇒ Object
55 56 57 |
# File 'lib/appserver/server_dir.rb', line 55 def config_file File.join(path, CONFIG_FILE_NAME) end |
#log_path ⇒ Object
72 73 74 |
# File 'lib/appserver/server_dir.rb', line 72 def log_path File.join(path, 'log') end |
#repository(path) ⇒ Object
89 90 91 92 |
# File 'lib/appserver/server_dir.rb', line 89 def repository (path) @repositories ||= {} @repositories[File.(path, self.path)] ||= Repository.new(self, path, @config) end |
#tmp_path ⇒ Object
68 69 70 |
# File 'lib/appserver/server_dir.rb', line 68 def tmp_path File.join(path, 'tmp') end |
#write_configs ⇒ Object
94 95 96 97 98 |
# File 'lib/appserver/server_dir.rb', line 94 def write_configs Monit.write_config(self) Nginx.write_config(self) Logrotate.write_config(self) end |