This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logrotate): implement logrotate
Currently, frameworks (rails) and webservers (apache2 and nginx) are supported. Resolves #78
- Loading branch information
Showing
14 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Drivers | ||
module Dsl | ||
module Logrotate | ||
def self.included(klass) | ||
klass.instance_eval do | ||
def log_paths(*log_paths) | ||
@log_paths ||= [] | ||
@log_paths += Array.wrap(log_paths) | ||
@log_paths | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def log_paths | ||
self.class.log_paths.presence || | ||
(self.class.superclass.respond_to?(:log_paths) && self.class.superclass.log_paths) | ||
end | ||
|
||
def configure_logrotate | ||
return if (log_paths || []).empty? | ||
lr_path = logrotate_log_paths | ||
lr_rotate = logrotate_rotate | ||
|
||
context.logrotate_app "#{app['shortname']}-#{adapter}-#{deploy_env}" do | ||
path lr_path | ||
frequency 'daily' | ||
rotate lr_rotate | ||
options %w[missingok compress delaycompress notifempty copytruncate sharedscripts] | ||
end | ||
end | ||
|
||
def logrotate_log_paths | ||
log_paths.map do |log_path| | ||
next log_path.call(self) if log_path.is_a?(Proc) | ||
next log_path if log_path.start_with?('/') | ||
File.join(deploy_dir(app), log_path) | ||
end.flatten.uniq | ||
end | ||
|
||
def logrotate_rotate | ||
globals(:logrotate_rotate, app['shortname']) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ def raw_out | |
|
||
def configure | ||
build_env | ||
super | ||
end | ||
|
||
def deploy_before_restart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters