<commit_before>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.running = run_specinfra(:check_service_is_running, attributes.name)
        current.enabled = run_specinfra(:check_service_is_enabled, attributes.name)
      end

      def action_start(options)
        unless current.running
          run_specinfra(:start_service, attributes.name)
        end
      end

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

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

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

      def action_enable(options)
        run_specinfra(:enable_service, attributes.name)<commit_msg>Stop a service only if the service is running.<commit_after>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.running = run_specinfra(:check_service_is_running, attributes.name)
        current.enabled = run_specinfra(:check_service_is_enabled, attributes.name)
      end

      def action_start(options)
        unless current.running
          run_specinfra(:start_service, attributes.name)
        end
      end

      def action_stop(options)
        if current.running
          run_specinfra(:stop_service, attributes.name)
        end
      end

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

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

      def action_enable(options)
        run_specinfra(:enable_service, attributes.name)
{'fraction_non_alphanumeric': 0.06206896551724138, 'fraction_numerical': 0.0, 'mean_word_length': 2.4355263157894735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1439972', 'n_tokens_mistral': 708, 'n_tokens_neox': 676, 'n_words': 166}