~lynxman/ubuntu/precise/puppet/puppetlabsfixbug12844

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2.6.1-0ubuntu2/lib/puppet/provider/service/init.rb

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2010-09-21 13:53:10 UTC
  • Revision ID: james.westby@ubuntu.com-20100921135310-y942hx46cq2lo375
Tags: 2.6.1-0ubuntu2
debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
set the location of the CRL in apache2 configuration. Fix apache2 
configuration on upgrade as well (LP: #641001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# The standard init-based service type.  Many other service types are
 
2
# customizations of this module.
 
3
Puppet::Type.type(:service).provide :init, :parent => :base do
 
4
  desc "Standard init service management.
 
5
 
 
6
  This provider assumes that the init script has no `status` command,
 
7
  because so few scripts do, so you need to either provide a status
 
8
  command or specify via `hasstatus` that one already exists in the
 
9
  init script.
 
10
 
 
11
"
 
12
 
 
13
  class << self
 
14
    attr_accessor :defpath
 
15
  end
 
16
 
 
17
  case Facter["operatingsystem"].value
 
18
  when "FreeBSD"
 
19
    @defpath = ["/etc/rc.d", "/usr/local/etc/rc.d"]
 
20
  when "HP-UX"
 
21
    @defpath = "/sbin/init.d"
 
22
  else
 
23
    @defpath = "/etc/init.d"
 
24
  end
 
25
 
 
26
  # We can't confine this here, because the init path can be overridden.
 
27
  #confine :exists => @defpath
 
28
 
 
29
  # List all services of this type.
 
30
  def self.instances
 
31
    get_services(self.defpath)
 
32
  end
 
33
 
 
34
  def self.get_services(defpath, exclude=[])
 
35
    defpath = [defpath] unless defpath.is_a? Array
 
36
    instances = []
 
37
    defpath.each do |path|
 
38
      unless FileTest.directory?(path)
 
39
        Puppet.debug "Service path #{path} does not exist"
 
40
        next
 
41
      end
 
42
 
 
43
      check = [:ensure]
 
44
 
 
45
      check << :enable if public_method_defined? :enabled?
 
46
 
 
47
      Dir.entries(path).each do |name|
 
48
        fullpath = File.join(path, name)
 
49
        next if name =~ /^\./
 
50
        next if exclude.include? name
 
51
        next if not FileTest.executable?(fullpath)
 
52
        instances << new(:name => name, :path => path, :hasstatus => true)
 
53
      end
 
54
    end
 
55
    instances
 
56
  end
 
57
 
 
58
  # Mark that our init script supports 'status' commands.
 
59
  def hasstatus=(value)
 
60
    case value
 
61
    when true, "true"; @parameters[:hasstatus] = true
 
62
    when false, "false"; @parameters[:hasstatus] = false
 
63
    else
 
64
      raise Puppet::Error, "Invalid 'hasstatus' value #{value.inspect}"
 
65
    end
 
66
  end
 
67
 
 
68
  # Where is our init script?
 
69
  def initscript
 
70
    @initscript ||= self.search(@resource[:name])
 
71
  end
 
72
 
 
73
  def paths
 
74
    @paths ||= @resource[:path].find_all do |path|
 
75
      if File.directory?(path)
 
76
        true
 
77
      else
 
78
        if File.exist?(path) and ! File.directory?(path)
 
79
          self.debug "Search path #{path} is not a directory"
 
80
        else
 
81
          self.debug "Search path #{path} does not exist"
 
82
        end
 
83
        false
 
84
      end
 
85
    end
 
86
  end
 
87
 
 
88
  def search(name)
 
89
    paths.each { |path|
 
90
      fqname = File.join(path,name)
 
91
      begin
 
92
        stat = File.stat(fqname)
 
93
      rescue
 
94
        # should probably rescue specific errors...
 
95
        self.debug("Could not find #{name} in #{path}")
 
96
        next
 
97
      end
 
98
 
 
99
      # if we've gotten this far, we found a valid script
 
100
      return fqname
 
101
    }
 
102
 
 
103
    paths.each { |path|
 
104
      fqname_sh = File.join(path,"#{name}.sh")
 
105
      begin
 
106
        stat = File.stat(fqname_sh)
 
107
      rescue
 
108
        # should probably rescue specific errors...
 
109
        self.debug("Could not find #{name}.sh in #{path}")
 
110
        next
 
111
      end
 
112
 
 
113
      # if we've gotten this far, we found a valid script
 
114
      return fqname_sh
 
115
    }
 
116
    raise Puppet::Error, "Could not find init script for '#{name}'"
 
117
  end
 
118
 
 
119
  # The start command is just the init scriptwith 'start'.
 
120
  def startcmd
 
121
    [initscript, :start]
 
122
  end
 
123
 
 
124
  # The stop command is just the init script with 'stop'.
 
125
  def stopcmd
 
126
    [initscript, :stop]
 
127
  end
 
128
 
 
129
  def restartcmd
 
130
    (@resource[:hasrestart] == :true) && [initscript, :restart]
 
131
  end
 
132
 
 
133
  # If it was specified that the init script has a 'status' command, then
 
134
  # we just return that; otherwise, we return false, which causes it to
 
135
  # fallback to other mechanisms.
 
136
  def statuscmd
 
137
    (@resource[:hasstatus] == :true) && [initscript, :status]
 
138
  end
 
139
 
 
140
end
 
141