Commit b67e8983 authored by Bryan McLellan's avatar Bryan McLellan
Browse files

Merge branch 'CHEF-2367' into 0.9-stable

parents 4c6022d9 df1a4f3d
......@@ -20,16 +20,16 @@ require 'chef/provider/service/init'
require 'chef/mixin/command'
class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
def initialize(new_resource, run_context)
super
@init_command = "/etc/rc.d/#{@new_resource.service_name}"
end
def load_current_resource
raise Chef::Exceptions::Service unless ::File.exists?("/etc/rc.conf")
raise Chef::Exceptions::Service unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/)
raise Chef::Exceptions::Service unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m)
super
......@@ -38,38 +38,46 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
@current_resource
end
# Get list of all daemons from the file '/etc/rc.conf'.
# Mutiple lines and background form are supported. Example:
# DAEMONS=(\
# foobar \
# @example \
# !net \
# )
def daemons
entries = []
if ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/)
entries += $1.split(" ") if $1.length > 0
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
# FIXME: Multiple entries of DAEMONS will cause very bad results :)
def update_daemons(entries)
content = ::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/, "DAEMONS=(#{entries.join(' ')})")
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
def enable_service()
new_daemons = []
entries = daemons
if entries.include?(new_resource.service_name)
# exists and already enabled
new_daemons += entries
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}"
if daemon == "!#{new_resource.service_name}"
new_daemons << new_resource.service_name
else
else
new_daemons << daemon
end
end
......@@ -78,32 +86,31 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
new_daemons += entries
new_daemons << new_resource.service_name
end
update_daemons(new_daemons)
end
update_daemons(new_daemons)
end
def disable_service()
new_daemons = []
entries = daemons
if entries.include?("!#{new_resource.service_name}")
# exists and disabled
new_daemons += entries
# new_daemons += entries
else
if entries.include?(new_resource.service_name)
# exists but enabled
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 daemon == new_resource.service_name
if [new_resource.service_name, "@#{new_resource.service_name}"].include?(daemon)
new_daemons << "!#{new_resource.service_name}"
else
else
new_daemons << daemon
end
end
end
update_daemons(new_daemons)
end
update_daemons(new_daemons)
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment