Sha256: 6fa5bab36a81e4ac0aab9caf3c3ad73050745d1aee3b3b4c205c91ee18ec7c88

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module Capistrano
  module Ops
    module Logrotate
      module Helpers
        def config_template
          return nil unless File.exist?(File.expand_path(logrotate_config_file_template, __dir__))

          ERB.new(File.read(File.expand_path(logrotate_config_file_template, __dir__))).result(binding)
        end

        def schedule_template
          return nil unless File.exist?(File.expand_path(logrotate_schedule_file_template, __dir__))

          ERB.new(File.read(File.expand_path(logrotate_schedule_file_template, __dir__))).result(binding)
        end

        def logrotate_enabled
          test("[ -f #{logrotate_config_file_path} ]") && test("[ -f #{logrotate_schedule_file_path} ]")
        end

        def logrotate_disabled
          !(test("[ -f #{logrotate_config_file_path} ]") && test("[ -f #{logrotate_schedule_file_path} ]"))
        end

        def make_basepath
          puts capture "mkdir -pv #{logrotate_basepath}"
        end

        def delete_files
          puts capture "rm -rfv #{logrotate_basepath}"
        end

        def whenever(type)
          case type
          when 'clear'
            puts capture :bundle, :exec, :whenever, '--clear-crontab',
                         "-f #{logrotate_schedule_file_path} #{fetch(:whenever_identifier)}_logrotate"
          when 'update'
            puts capture :bundle, :exec, :whenever, '--update-crontab', "-f #{logrotate_schedule_file_path}",
                         "-i #{fetch(:whenever_identifier)}_logrotate"
          else
            puts 'type not found'
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
capistrano-ops-1.0.4 lib/capistrano/ops/logrotate/helpers.rb
capistrano-ops-1.0.3 lib/capistrano/ops/logrotate/helpers.rb
capistrano-ops-1.0.2 lib/capistrano/ops/logrotate/helpers.rb
capistrano-ops-1.0.1 lib/capistrano/ops/logrotate/helpers.rb
capistrano-ops-1.0.0 lib/capistrano/ops/logrotate/helpers.rb