# class Chef::Provider::Service::Arch

### Public Class Methods

new(new_resource, run_context) click to toggle source
Calls superclass method Chef::Provider::Service::Init.new

    # File lib/chef/provider/service/arch.rb, line 24
    def initialize(new_resource, run_context)
      super
      @init_command = "/etc/rc.d/#{@new_resource.service_name}"
    end

### Public Instance Methods

daemons() { |entries| ... } click to toggle source

Get list of all daemons from the file ‘/etc/rc.conf’. Mutiple lines and background form are supported. Example:

    DAEMONS=(\
      foobar \
      @example \
      !net \
    )

    # File lib/chef/provider/service/arch.rb, line 45
    def daemons
      entries = []
      if ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m)
        entries += $1.gsub(/\?[\r\n]/, ' ').gsub(/# *[^ ]+/,' ').split(' ') if $1.length > 0
      end

      yield(entries) if block_given?

      entries
    end

disable_service() click to toggle source

    # File lib/chef/provider/service/arch.rb, line 90
    def disable_service()
      new_daemons = []
      entries = daemons

      if entries.include?("!#{new_resource.service_name}")
        # exists and disabled
        # new_daemons += entries
      else
        if entries.include?(new_resource.service_name) or entries.include?("@#{new_resource.service_name}")
          # exists but enabled (or enabled as a back-ground service)
          # FIXME: Does arch support !@foobar ?
          entries.each do |daemon|
            if [new_resource.service_name, "@#{new_resource.service_name}"].include?(daemon)
              new_daemons << "!#{new_resource.service_name}"
            else
              new_daemons << daemon
            end
          end
        end
        update_daemons(new_daemons)
      end
    end

enable_service() click to toggle source

    # File lib/chef/provider/service/arch.rb, line 64
    def enable_service()
      new_daemons = []
      entries = daemons

      if entries.include?(new_resource.service_name) or entries.include?("@#{new_resource.service_name}")
        # exists and already enabled (or already enabled as a background service)
        # new_daemons += entries
      else
        if entries.include?("!#{new_resource.service_name}")
          # exists but disabled
          entries.each do |daemon|
            if daemon == "!#{new_resource.service_name}"
              new_daemons << new_resource.service_name
            else
              new_daemons << daemon
            end
          end
        else
          # does not exist
          new_daemons += entries
          new_daemons << new_resource.service_name
        end
        update_daemons(new_daemons)
      end
    end

load_current_resource() click to toggle source
Calls superclass method Chef::Provider::Service::Simple#load_current_resource

    # File lib/chef/provider/service/arch.rb, line 29
    def load_current_resource
      raise Chef::Exceptions::Service, "Could not find /etc/rc.conf"  unless ::File.exists?("/etc/rc.conf")
      raise Chef::Exceptions::Service, "No DAEMONS found in /etc/rc.conf"  unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m)
      super

      @current_resource.enabled(daemons.include?(@current_resource.service_name))
      @current_resource
    end

update_daemons(entries) click to toggle source

FIXME: Multiple entries of DAEMONS will cause very bad results :)

    # File lib/chef/provider/service/arch.rb, line 57
    def update_daemons(entries)
      content = ::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/m, "DAEMONS=(#{entries.join(' ')})")
      ::File.open("/etc/rc.conf", "w") do |f|
        f.write(content)
      end
    end