summaryrefslogtreecommitdiffstats
path: root/modules/slackware/lib/puppet/provider/service
diff options
context:
space:
mode:
authorGravatar Daniel Washburn <daniel@washburn.at> 2018-07-13 10:44:07 -0400
committerGravatar Daniel Washburn <daniel@washburn.at> 2018-07-13 10:44:07 -0400
commit2da2fed5f9c21288cbe8a807458a8f56272631af (patch)
treea6411cfdbd34290e6020ef3598649d7d08c2bd07 /modules/slackware/lib/puppet/provider/service
parent3ce94f1b5124daceb255ad7de4ab58b0c8b69188 (diff)
downloadpuppet-slackware-2da2fed5f9c21288cbe8a807458a8f56272631af.tar.gz
puppet-slackware-2da2fed5f9c21288cbe8a807458a8f56272631af.tar.bz2
puppet-slackware-2da2fed5f9c21288cbe8a807458a8f56272631af.zip
Add Slackware package and service and slapt-get package providersHEADmaster
Diffstat (limited to 'modules/slackware/lib/puppet/provider/service')
-rw-r--r--modules/slackware/lib/puppet/provider/service/slackware.rb84
1 files changed, 84 insertions, 0 deletions
diff --git a/modules/slackware/lib/puppet/provider/service/slackware.rb b/modules/slackware/lib/puppet/provider/service/slackware.rb
new file mode 100644
index 0000000..4c22554
--- /dev/null
+++ b/modules/slackware/lib/puppet/provider/service/slackware.rb
@@ -0,0 +1,84 @@
+# Manage Slackware services
+
+Puppet::Type.type(:service).provide :slackware, :parent => :init do
+ desc "Manage Slackware's old-school BSD-style init scripts. Services
+ are enabled or disabled by toggling the executable bit."
+
+ defaultfor :operatingsystem => :slackware
+ confine :operatingsystem => :slackware
+
+ has_feature :enableable
+ has_feature :refreshable
+
+ def self.defpath
+ "/etc/rc.d"
+ end
+
+ def self.excludes
+ exclude = []
+ # Runlevel init scripts and symlinks thereto
+ exclude += %w{rc.0 rc.4 rc.6 rc.K rc.M rc.S}
+ # Additional system init scripts which aren't, strictly
+ # speaking, services
+ exclude += %w{rc.inet1 rc.inet2 rc.loop rc.font}
+ # rc.inet1.conf is a configuration file
+ exclude += %w{rc.inet1.conf}
+ end
+
+ def self.instances
+ get_instances(self.defpath)
+ end
+
+ def self.get_instances(defpath, exclude = self.excludes)
+ path = defpath
+ instances = []
+ unless FileTest.directory?(path)
+ Puppet.debug "Service path #{path} does not exist"
+ end
+
+ check = [:ensure]
+
+ check << :enable if public_method_defined? :enabled?
+
+ Dir.entries(path).each do |script|
+ fullpath = File.join(path, script)
+ next if script =~ /^\./
+ next if exclude.include? script
+ next if FileTest.directory?(fullpath)
+ next if FileTest.symlink?(fullpath)
+ name = /^rc\.(.*)$/.match(script)[1]
+ instances << new(:name => name, :path => path, :hasstatus => :false)
+ end
+ instances
+ end
+
+ def search(name)
+ paths.each { |path|
+ fqname_sh = File.join(path,"rc.#{name}")
+ begin
+ stat = File.stat(fqname_sh)
+ rescue
+ # should probably rescue specific errors...
+ self.debug("Could not find rc.#{name} in #{path}")
+ next
+ end
+
+ # if we've gotten this far, we found a valid script
+ return fqname_sh
+ }
+ raise Puppet::Error, "Could not find init script for '#{name}'"
+ end
+
+ def enabled?
+ FileTest.executable?(initscript)
+ end
+
+ def enable
+ File.chmod(0755, initscript) if not FileTest.executable?(initscript)
+ end
+
+ def disable
+ File.chmod(0644, initscript) if FileTest.executable?(initscript)
+ end
+
+end