Sha256: c85586b21a538de315da5acbb97383556b693e5761f501e44008fd12b8d120d7

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require 'itamae'

module Itamae
  module Resource
    class Service < Base
      define_attribute :action, default: :nothing
      define_attribute :name, type: String, default_name: true

      def pre_action
        case @current_action
        when :start, :restart
          @attributes[:running?] = true
        when :stop
          @attributes[:running?] = false
        when :enable
          @attributes[:enabled?] = true
        when :disable
          @attributes[:enabled?] = false
        end
      end

      def set_current_attributes
        @current_attributes[:running?] = run_specinfra(:check_service_is_running, name)
        @current_attributes[:enabled?] = run_specinfra(:check_service_is_enabled, name)
      end

      def action_start(options)
        run_specinfra(:start_service, name)
      end

      def action_stop(options)
        run_specinfra(:stop_service, name)
      end

      def action_restart(options)
        run_specinfra(:restart_service, name)
      end

      def action_reload(options)
        run_specinfra(:reload_service, name)
      end

      def action_enable(options)
        run_specinfra(:enable_service, name)
      end

      def action_disable(options)
        run_specinfra(:disable_service, name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
itamae-1.0.0.beta41 lib/itamae/resource/service.rb
itamae-1.0.0.beta40 lib/itamae/resource/service.rb
itamae-1.0.0.beta39 lib/itamae/resource/service.rb
itamae-1.0.0.beta38 lib/itamae/resource/service.rb