Sha256: 09770c65c4a0a0fe09d7bcb1f5c6cf014a71a284a45ef2f8fdfb47c3309d0f42

Contents?: true

Size: 1.79 KB

Versions: 90

Compression:

Stored size: 1.79 KB

Contents

require 'itamae-mitsurin'

module ItamaeMitsurin
  module Resource
    class Service < Base
      define_attribute :action, default: :nothing
      define_attribute :name, type: String, default_name: true
      define_attribute :provider, type: Symbol, default: nil

      def initialize(*args)
        super
        @under = attributes.provider ? "_under_#{attributes.provider}" : ""
      end

      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.running = run_specinfra(:"check_service_is_running#{@under}", attributes.name)
        current.enabled = run_specinfra(:"check_service_is_enabled#{@under}", attributes.name)
      end

      def action_start(options)
        unless current.running
          run_specinfra(:"start_service#{@under}", attributes.name)
        end
      end

      def action_stop(options)
        if current.running
          run_specinfra(:"stop_service#{@under}", attributes.name)
        end
      end

      def action_restart(options)
        run_specinfra(:"restart_service#{@under}", attributes.name)
      end

      def action_reload(options)
        if current.running
          run_specinfra(:"reload_service#{@under}", attributes.name)
        end
      end

      def action_enable(options)
        unless current.enabled
          run_specinfra(:"enable_service#{@under}", attributes.name)
        end
      end

      def action_disable(options)
        if current.enabled
          run_specinfra(:"disable_service#{@under}", attributes.name)
        end
      end
    end
  end
end

Version data entries

90 entries across 47 versions & 1 rubygems

Version Path
itamae-mitsurin-1.0.3 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-1.0.2 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-1.0.1 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-1.0.0 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.50 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.50 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.49 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.49 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.48 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.48 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.47 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.47 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.46 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.46 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.45 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.45 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.44 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.44 test/test_itamae-mitsurin/resource/test_service.rb
itamae-mitsurin-0.43 lib/itamae-mitsurin/resource/service.rb
itamae-mitsurin-0.43 test/test_itamae-mitsurin/resource/test_service.rb