summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-12-11 00:26:33 -0600
committerLuke Kanies <luke@madstop.com>2007-12-11 00:26:33 -0600
commited642ac45842b8717b8f54f2df9f25b3dc6fe684 (patch)
tree783e551d162aee27ef5aca5f4614fed89d84ac2d /lib
parent117f005ab22ef90686f4eb19aee3ea5c8dc93865 (diff)
downloadpuppet-ed642ac45842b8717b8f54f2df9f25b3dc6fe684.tar.gz
puppet-ed642ac45842b8717b8f54f2df9f25b3dc6fe684.tar.xz
puppet-ed642ac45842b8717b8f54f2df9f25b3dc6fe684.zip
Replacing freebsd service provider with the one
provided by raj in #880.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/service/freebsd.rb55
1 files changed, 32 insertions, 23 deletions
diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb
index 31fdacb86..8076469e1 100644
--- a/lib/puppet/provider/service/freebsd.rb
+++ b/lib/puppet/provider/service/freebsd.rb
@@ -1,46 +1,55 @@
# Manage FreeBSD services.
Puppet::Type.type(:service).provide :freebsd, :parent => :init do
desc "FreeBSD's (and probably NetBSD?) form of ``init``-style service
- management; uses ``rc-update`` for service enabling and disabling."
-
- commands :rcupdate => "/usr/local/sbin/rc-update"
+ management; uses ``rc.conf.d`` for service enabling and disabling."
defaultfor :operatingsystem => :freebsd
+ @@rcconf_dir = '/etc/rc.conf.d'
+
def self.defpath
superclass.defpath
end
+ if self.suitable?
+ Puppet.type(:service).newpath(:freebsd, defpath())
+ end
+
+ # remove service file from rc.conf.d to disable it
def disable
- begin
- output = rcupdate("disable", @model[:name])
- rescue Puppet::ExecutionFailure
- raise Puppet::Error, "Could not disable %s: %s" %
- [self.name, output]
+ rcfile = File.join(@@rcconf_dir, @model[:name])
+ if File.exists?(rcfile)
+ File.delete(rcfile)
end
end
-
+
+ # if the service file exists in rc.conf.d then it's already enabled
def enabled?
- begin
- output = rcupdate("enabled", @model[:name])
- rescue Puppet::ExecutionFailure
- return :false
- end
-
- # If it's enabled, output is 0
- if output =~ /^0$/
+ rcfile = File.join(@@rcconf_dir, @model[:name])
+ if File.exists?(rcfile)
return :true
end
return :false
end
-
+
+ # enable service by creating a service file under rc.conf.d with the
+ # proper contents
def enable
- begin
- output = rcupdate("enable", @model[:name])
- rescue Puppet::ExecutionFailure => detail
- raise Puppet::Error, "Could not enable %s: %s" %
- [self.name, detail]
+ if not File.exists?(@@rcconf_dir)
+ Dir.mkdir(@@rcconf_dir)
end
+ rcfile = File.join(@@rcconf_dir, @model[:name])
+ open(rcfile, 'w') { |f| f << "%s_enable=\"YES\"\n" % @model[:name] }
+ end
+
+ # Override stop/start commands to use one<cmd>'s and the avoid race condition
+ # where provider trys to stop/start the service before it is enabled
+ def startcmd
+ [self.initscript, :onestart]
+ end
+
+ def stopcmd
+ [self.initscript, :onestop]
end
end