Class: Appserver::Logrotate
- Inherits:
-
Struct
- Object
- Struct
- Appserver::Logrotate
- Defined in:
- lib/appserver/logrotate.rb
Instance Attribute Summary collapse
-
#server_dir ⇒ Object
Returns the value of attribute server_dir.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(server_dir) ⇒ Logrotate
constructor
A new instance of Logrotate.
- #write_config ⇒ Object
Constructor Details
#initialize(server_dir) ⇒ Logrotate
Returns a new instance of Logrotate.
8 9 10 |
# File 'lib/appserver/logrotate.rb', line 8 def initialize (server_dir) self.server_dir = server_dir end |
Instance Attribute Details
#server_dir ⇒ Object
Returns the value of attribute server_dir
2 3 4 |
# File 'lib/appserver/logrotate.rb', line 2 def server_dir @server_dir end |
Class Method Details
.write_config(server_dir) ⇒ Object
4 5 6 |
# File 'lib/appserver/logrotate.rb', line 4 def self.write_config (server_dir) new(server_dir).write_config end |
Instance Method Details
#write_config ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/appserver/logrotate.rb', line 12 def write_config Utils.safe_replace_file(server_dir.logrotate_conf) do |f| f.puts "# Logrotate configuration automagically generated by the \"appserver\" gem using" f.puts "# the appserver directory config #{server_dir.config_file}" f.puts "# Include this file into your system's logrotate.conf (using an include statement)" f.puts "# to use it. See http://github.com/zargony/appserver for details." # Handle access logs of Nginx in one statement, so Nginx only needs to reopen once access_logs = server_dir.apps.map { |app| app.access_log }.compact f.puts "#{access_logs.join(' ')} {" f.puts " missingok" f.puts " delaycompress" f.puts " sharedscripts" f.puts " postrotate" f.puts " #{server_dir.nginx_reopen}" f.puts " endscript" f.puts "}" # Add application-specific Logrotate configuration server_dir.apps.each do |app| f.puts "" f.puts "# Application: #{app.name}" if app.server_log f.puts "#{app.server_log} {" f.puts " missingok" f.puts " delaycompress" f.puts " sharedscripts" f.puts " postrotate" f.puts " #{server_dir.appserver_cmd('reload', app.name)}" f.puts " endscript" f.puts "}" end end end end |