capistrano-ops 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2744c35793b74ff96ed5933892458ed3bbb86d33b93b4a9aab119996ab099048
4
- data.tar.gz: 8245cc91a46097474588d94f4b935dc0f2c83090bf1818c7da4e6f37662bfaa0
3
+ metadata.gz: 8c6192691d485f5348cadfb470f7c06c7e86e4aca51daedcb1ffe33be9923a2d
4
+ data.tar.gz: 469cba09f0f444133aa54451d8e7f06fac4430d3ab9cc67bc52714f76402949f
5
5
  SHA512:
6
- metadata.gz: ddc408fdde37cbc926b36ce1fd3dce989a2aa6c4a73e61a700af581c02b3432274b49837784d182fa1f07ea48cb1ca253e8c6e9647d5aadbe6313d8c319bb57f
7
- data.tar.gz: 14c1223afe87285ced3ce3790ef73b3b515a2912dd62cfd15da8e08ea2bebee3945c0773ba2af423bfc6753756a3dbd3f7d22acebcdf3de5117c6051c0934615
6
+ metadata.gz: 0bca2a6b0dd5e2b7dd724c623ea1f9f22bb6c05ca16ee654f805253fac5dedbf955c1c729dac8aa3c4d66822eead8b38cb7a62645dca5d7b11fe034cf860b3ca
7
+ data.tar.gz: 74c95eea7b0f4bc7b95b24010f7a651a987a06234f455c63e68d9e8cac3961930a2fe0cc9dee105be44401b40aef01a40ba274734cd1bf9cc3255884dfe6766c
data/README.md CHANGED
@@ -96,6 +96,9 @@ require 'capistrano/ops'
96
96
  | `cap <environment> logs:rails` | display server log live |
97
97
  | `cap <environment> whenever:show_crontab` | display server app crontab generated with whenever |
98
98
  | `cap <environment> invoke:rake TASK=<your:task>` | invoke rake task on server |
99
+ | `cap <environment> logrotate:enable` | enable logrotate for logfiles on server |
100
+ | `cap <environment> logrotate:disable` | disable logrotate for logfiles on server |
101
+ | `cap <environment> logrotate:check` | show logrotate status for logfiles on server |
99
102
  | `rake pg:dump` | creates postgres database backup |
100
103
  | `rake pg:remove_old_dumps` | remove old postgres backups |
101
104
  | `rake storage:backup` | creates backup of storage |
@@ -232,6 +235,35 @@ S3_BACKUP_SECRET: '<your-s3-secret>'
232
235
  S3_BACKUP_ENDPOINT: '<your-s3-endpoint>' # optional, used for other S3 compatible services
233
236
  ```
234
237
 
238
+ ## Logrotate
239
+
240
+ Logrotate is a utility designed for administrators who manage servers producing a high volume of log files to help them save some disk space as well as to avoid a potential risk making a system unresponsive due to the lack of disk space.
241
+
242
+ The capistrano-ops gem provides a set of tasks to manage logrotate on your server:
243
+
244
+ - `cap <environment> logrotate:enable` - This task enables logrotate for logfiles on the server.
245
+ - `cap <environment> logrotate:disable` - This task disables logrotate for logfiles on the server.
246
+ - `cap <environment> logrotate:check` - This task shows the logrotate status for logfiles on the server.
247
+
248
+ ### Configuration
249
+
250
+ You can optionally specify the logrotate configuration file path (Defaults to `/etc/logrotate.conf`):
251
+
252
+ ```ruby
253
+ # Defaults to '/etc/logrotate.conf'
254
+ set :logrotate_path, '/path/to/your/logrotate.conf'
255
+ ```
256
+
257
+ ### Usage
258
+
259
+ To use logrotate, you need to have it installed on your server. If it's not installed, you can install it using the package manager of your system. For example, on Ubuntu, you can install it using apt:
260
+
261
+ ```bash
262
+ sudo apt-get install logrotate
263
+ ```
264
+
265
+ Once logrotate is installed, you can use the capistrano-ops tasks to manage it.
266
+
235
267
  ## Contributing
236
268
 
237
269
  1. Fork it ( https://github.com/zauberware/capistrano-ops/fork )
@@ -247,3 +279,7 @@ The gem is available as open source under the terms of the [MIT License](http://
247
279
  ```
248
280
 
249
281
  ```
282
+
283
+ ```
284
+
285
+ ```
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logrotate_helper'
4
+
5
+ namespace :logrotate do
6
+ include LogrotateHelper
7
+
8
+ desc 'show logrotate state and config'
9
+ task :check do
10
+ on roles(:app) do
11
+ within release_path do
12
+ set_config
13
+ if logrotate_enabled
14
+ puts "logrotate running with config\n========================="
15
+ puts capture "cat #{@config_file_path}"
16
+ else
17
+ puts 'logrotate disabled'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logrotate_helper'
4
+
5
+ namespace :logrotate do
6
+ include LogrotateHelper
7
+
8
+ desc 'disable logrotate'
9
+ task :disable do
10
+ on roles(:app) do
11
+ within release_path do
12
+ set_config
13
+ if logrotate_disabled
14
+ puts 'logrotate already disabled'
15
+ else
16
+ whenever 'clear' if logrotate_enabled
17
+ delete_files
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logrotate_helper'
4
+
5
+ namespace :logrotate do
6
+ include LogrotateHelper
7
+ desc 'Enable logrotate for the application'
8
+ task :enable do
9
+ on roles(:app) do
10
+ within release_path do
11
+ set_config
12
+ if logrotate_enabled
13
+ puts "logrotate already enabled:\n========================="
14
+ puts capture "cat #{@config_file_path}"
15
+ else
16
+ make_basepath
17
+ upload! StringIO.new(@config_template), @config_file_path
18
+ upload! StringIO.new(@schedule_template), @schedule_file_path
19
+ whenever 'update' if logrotate_enabled
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LogrotateHelper
4
+ # rubocop:disable Naming/MemoizedInstanceVariableName
5
+ def set_config
6
+ info ''
7
+ @shared_path ||= shared_path
8
+ @log_file_path ||= fetch(:log_file_path) || "#{@shared_path}/log"
9
+ @template_config_filename ||= fetch(:logrotate_template_config_file) || 'templates/logrotate.conf.erb'
10
+ @template_schedule_filename ||= fetch(:logrotate_template_schedule_file) || 'templates/schedule.rb.erb'
11
+ @basepath ||= fetch(:logrotate_basepath) || "#{shared_path}/logrotate"
12
+ @config_filename ||= File.basename(@template_config_filename, '.erb')
13
+ @schedule_filename ||= File.basename(@template_schedule_filename, '.erb')
14
+ @config_file_path ||= "#{@basepath}/#{@config_filename}"
15
+ @schedule_file_path ||= "#{@basepath}/#{@schedule_filename}"
16
+ @config_template ||= config_template
17
+ @schedule_template ||= schedule_template
18
+ end
19
+ # rubocop:enable Naming/MemoizedInstanceVariableName
20
+
21
+ def config
22
+ {
23
+ template_config_file: fetch(:logrotate_template_config_file) || 'templates/logrotate.conf.erb',
24
+ template_schedule_file: fetch(:logrotate_template_schedule_file) || 'templates/schedule.rb.erb'
25
+ }
26
+ end
27
+
28
+ def make_basepath
29
+ puts capture "mkdir -pv #{@basepath}"
30
+ end
31
+
32
+ def delete_files
33
+ puts capture "rm -rfv #{@basepath}"
34
+ end
35
+
36
+ def config_template
37
+ return nil unless @template_config_filename && File.exist?(File.expand_path(@template_config_filename, __dir__))
38
+
39
+ ERB.new(File.read(File.expand_path(@template_config_filename, __dir__))).result(binding)
40
+ end
41
+
42
+ def schedule_template
43
+ return nil unless @template_schedule_filename && File.exist?(File.expand_path(@template_schedule_filename, __dir__))
44
+
45
+ ERB.new(File.read(File.expand_path(@template_schedule_filename, __dir__))).result(binding)
46
+ end
47
+
48
+ def logrotate_enabled
49
+ test("[ -f #{@config_file_path} ]") && test("[ -f #{@schedule_file_path} ]")
50
+ end
51
+
52
+ def logrotate_disabled
53
+ !(test("[ -f #{@config_file_path} ]") && test("[ -f #{@schedule_file_path} ]"))
54
+ end
55
+
56
+ def whenever(type)
57
+ case type
58
+ when 'clear'
59
+ puts capture :bundle, :exec, :whenever, '--clear-crontab',
60
+ "-f #{@schedule_file_path} #{fetch(:whenever_identifier)}_logrotate"
61
+ when 'update'
62
+ puts capture :bundle, :exec, :whenever, '--update-crontab', "-f #{@schedule_file_path}",
63
+ "-i #{fetch(:whenever_identifier)}_logrotate"
64
+ else
65
+ puts 'type not found'
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,10 @@
1
+ <%= @log_file_path %>/*.log {
2
+ daily
3
+ dateext
4
+ missingok
5
+ rotate 52
6
+ compress
7
+ delaycompress
8
+ notifempty
9
+ copytruncate
10
+ }
@@ -0,0 +1,8 @@
1
+ env :PATH, ENV['PATH']
2
+ set :output, -> { '2>&1 | logger -t logrotate' }
3
+
4
+ job_type :logrotate, '/usr/sbin/logrotate -s <%= @shared_path %>/logrotate/status <%= @shared_path %>/logrotate/logrotate.conf :output'
5
+
6
+ every "0 0 * * *" do
7
+ logrotate "logrotate"
8
+ end
@@ -6,10 +6,11 @@ if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).releas
6
6
  load File.expand_path('capistrano/v3/tasks/whenever.rake', __dir__)
7
7
  load File.expand_path('capistrano/v3/tasks/backup.rake', __dir__)
8
8
  load File.expand_path('capistrano/v3/tasks/figaro_yml.rake', __dir__)
9
- load File.expand_path('capistrano/v3/tasks/logs.rake', __dir__)
10
9
  load File.expand_path('capistrano/v3/tasks/invoke.rake', __dir__)
11
10
  path = File.expand_path(__dir__)
12
11
  Dir.glob("#{path}/capistrano/v3/tasks/backup/**/*.rake").each { |f| load f }
12
+ Dir.glob("#{path}/capistrano/v3/tasks/logrotate/**/*.rake").each { |f| load f }
13
+ Dir.glob("#{path}/capistrano/v3/tasks/logs/**/*.rake").each { |f| load f }
13
14
  else
14
15
  puts 'Capistrano 3 is required to use this gem'
15
16
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module Ops
5
- VERSION = '0.2.11'
5
+ VERSION = '0.2.12'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Crusius
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-15 00:00:00.000000000 Z
11
+ date: 2024-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -128,7 +128,13 @@ files:
128
128
  - lib/capistrano/ops/capistrano/v3/tasks/backup/storage/pull.rake
129
129
  - lib/capistrano/ops/capistrano/v3/tasks/figaro_yml.rake
130
130
  - lib/capistrano/ops/capistrano/v3/tasks/invoke.rake
131
- - lib/capistrano/ops/capistrano/v3/tasks/logs.rake
131
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/check.rake
132
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/disable.rake
133
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/enable.rake
134
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/logrotate_helper.rb
135
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/templates/logrotate.conf.erb
136
+ - lib/capistrano/ops/capistrano/v3/tasks/logrotate/templates/schedule.rb.erb
137
+ - lib/capistrano/ops/capistrano/v3/tasks/logs/rails.rake
132
138
  - lib/capistrano/ops/capistrano/v3/tasks/whenever.rake
133
139
  - lib/capistrano/ops/notification.rb
134
140
  - lib/capistrano/ops/notification/api.rb