Sha256: aeec4efb2a02a603d0019f485f70894a98c2a6ea320a8710d5c818e406a51cc7

Contents?: true

Size: 1.78 KB

Versions: 50

Compression:

Stored size: 1.78 KB

Contents

require 'itamae'

module Itamae
  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

50 entries across 50 versions & 2 rubygems

Version Path
itamae-1.10.3 lib/itamae/resource/service.rb
itamae-1.10.2 lib/itamae/resource/service.rb
itamae-1.10.1 lib/itamae/resource/service.rb
itamae-1.10.0 lib/itamae/resource/service.rb
itamae-1.9.13 lib/itamae/resource/service.rb
itamae-1.9.12 lib/itamae/resource/service.rb
itamae-1.9.11 lib/itamae/resource/service.rb
itamae-1.9.10 lib/itamae/resource/service.rb
itamae-1.9.9 lib/itamae/resource/service.rb
itamae-1.9.8 lib/itamae/resource/service.rb
itamae-1.9.7.pre lib/itamae/resource/service.rb
itamae-1.9.6 lib/itamae/resource/service.rb
itamae-1.9.6.pre lib/itamae/resource/service.rb
itamae-1.9.5 lib/itamae/resource/service.rb
itamae-1.9.4 lib/itamae/resource/service.rb
itamae-mitsurin-0.4 lib/itamae/resource/service.rb
itamae-mitsurin-0.3 lib/itamae/resource/service.rb
itamae-mitsurin-0.2 lib/itamae/resource/service.rb
itamae-mitsurin-0.1 lib/itamae/resource/service.rb
itamae-1.9.3 lib/itamae/resource/service.rb