Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

bsd.rb

By: a guest on Jun 26th, 2012  |  syntax: Ruby  |  size: 1.36 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Manage FreeBSD services.
  2. Puppet::Type.type(:service).provide :bsd, :parent => :init do
  3.   desc <<-EOT
  4.     FreeBSD's (and probably NetBSD's?) form of `init`-style service management.
  5.  
  6.     Uses `rc.conf.d` for service enabling and disabling.
  7.  
  8.   EOT
  9.  
  10.   confine :operatingsystem => [:freebsd, :netbsd, :openbsd]
  11.  
  12.   class_variable_set(:@@rcconf, '/etc/rc.conf')
  13.  
  14.   def self.defpath
  15.     superclass.defpath
  16.   end
  17.  
  18.   # remove service file from rc.conf.d to disable it
  19.   def disable
  20.     rcfile = File.join(@@rcconf_dir, @model[:name])
  21.     File.delete(rcfile) if File.exists?(rcfile)
  22.   end
  23.  
  24.  
  25.   # if the service file exists in rc.conf.d then it's already enabled
  26.   def enabled?
  27.     rcfile = File.join(@@rcconf_dir, @model[:name])
  28.     return :true if File.exists?(rcfile)
  29.  
  30.     :false
  31.   end
  32.  
  33.   # enable service by creating a service file under rc.conf.d with the
  34.   # proper contents
  35.   def enable
  36.     Dir.mkdir(@@rcconf_dir) if not File.exists?(@@rcconf_dir)
  37.     rcfile = File.join(@@rcconf_dir, @model[:name])
  38.     open(rcfile, 'w') { |f| f << "%s_enable=\"YES\"\n" % @model[:name] }
  39.   end
  40.  
  41.   # Override stop/start commands to use one<cmd>'s and the avoid race condition
  42.   # where provider trys to stop/start the service before it is enabled
  43.   def startcmd
  44.     [self.initscript, :onestart]
  45.   end
  46.  
  47.   def stopcmd
  48.     [self.initscript, :onestop]
  49.   end
  50. end
clone this paste RAW Paste Data