~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to lib/puppet/provider/service/upstart.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - 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)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Puppet::Type.type(:service).provide :upstart, :parent => :init do
 
2
  desc "Ubuntu service manager upstart.
 
3
 
 
4
  This provider manages upstart jobs which have replaced initd.
 
5
 
 
6
  See:
 
7
   * http://upstart.ubuntu.com/
 
8
  "
 
9
  # confine to :ubuntu for now because I haven't tested on other platforms
 
10
  confine :operatingsystem => :ubuntu #[:ubuntu, :fedora, :debian]
 
11
 
 
12
  commands :start   => "/sbin/start",
 
13
           :stop    => "/sbin/stop",
 
14
           :restart => "/sbin/restart",
 
15
           :status_exec  => "/sbin/status",
 
16
           :initctl => "/sbin/initctl"
 
17
 
 
18
  # upstart developer haven't implemented initctl enable/disable yet:
 
19
  # http://www.linuxplanet.com/linuxplanet/tutorials/7033/2/
 
20
  # has_feature :enableable
 
21
 
 
22
  def self.instances
 
23
    instances = []
 
24
    execpipe("#{command(:initctl)} list") { |process|
 
25
      process.each { |line|
 
26
        # needs special handling of services such as network-interface:
 
27
        # initctl list:
 
28
        # network-interface (lo) start/running
 
29
        # network-interface (eth0) start/running
 
30
        # network-interface-security start/running
 
31
        name = \
 
32
          if matcher = line.match(/^(network-interface)\s\(([^\)]+)\)/)
 
33
            "#{matcher[1]} INTERFACE=#{matcher[2]}"
 
34
          else
 
35
            line.split.first
 
36
          end
 
37
        instances << new(:name => name)
 
38
      }
 
39
    }
 
40
    instances
 
41
  end
 
42
 
 
43
  def startcmd
 
44
    [command(:start), @resource[:name]]
 
45
  end
 
46
 
 
47
  def stopcmd
 
48
    [command(:stop), @resource[:name]]
 
49
  end
 
50
 
 
51
  def restartcmd
 
52
    (@resource[:hasrestart] == :true) && [command(:restart), @resource[:name]]
 
53
  end
 
54
 
 
55
  def status
 
56
    # allows user override of status command
 
57
    if @resource[:status]
 
58
      ucommand(:status, false)
 
59
      if $?.exitstatus == 0
 
60
        return :running
 
61
      else
 
62
        return :stopped
 
63
      end
 
64
    else
 
65
      output = status_exec(@resource[:name].split)
 
66
      if (! $?.nil?) && (output =~ /start\//)
 
67
        return :running
 
68
      else
 
69
        return :stopped
 
70
      end
 
71
    end
 
72
  end
 
73
end