~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    service.  It is preferable to specify start, stop, and status commands,
8
8
    akin to how you would do so using ``init``.
9
9
 
10
 
  "
 
10
    "
11
11
 
12
12
    commands :kill => "kill"
13
13
 
19
19
    # parameter.
20
20
    def getpid
21
21
        unless @resource[:pattern]
22
 
            @resource.fail "Either a stop command or a pattern must be specified"
 
22
            @resource.fail "Either stop/status commands or a pattern must be specified"
23
23
        end
24
24
        ps = Facter["ps"].value
25
25
        unless ps and ps != ""
26
 
            @resource.fail(
27
 
                "You must upgrade Facter to a version that includes 'ps'"
28
 
            )
 
26
            @resource.fail "You must upgrade Facter to a version that includes 'ps'"
29
27
        end
30
28
        regex = Regexp.new(@resource[:pattern])
31
29
        self.debug "Executing '#{ps}'"
43
41
 
44
42
    # How to restart the process.
45
43
    def restart
46
 
        if @resource[:restart] or self.respond_to?(:restartcmd)
 
44
        if @resource[:restart] or restartcmd
47
45
            ucommand(:restart)
48
46
        else
49
47
            self.stop
51
49
        end
52
50
    end
53
51
 
 
52
    # There is no default command, which causes other methods to be used  
 
53
    def restartcmd
 
54
    end
 
55
 
54
56
    # Check if the process is running.  Prefer the 'status' parameter,
55
57
    # then 'statuscmd' method, then look in the process table.  We give
56
58
    # the object the option to not return a status command, which might
57
59
    # happen if, for instance, it has an init script (and thus responds to
58
60
    # 'statuscmd') but does not have 'hasstatus' enabled.
59
61
    def status
60
 
        if @resource[:status] or (
61
 
            self.respond_to?(:statuscmd) and self.statuscmd
62
 
        )
 
62
        if @resource[:status] or statuscmd
63
63
            # Don't fail when the exit status is not 0.
64
 
            output = ucommand(:status, false)
 
64
            ucommand(:status, false)
65
65
 
66
 
            if $? == 0
 
66
            # Expicitly calling exitstatus to facilitate testing
 
67
            if $?.exitstatus == 0
67
68
                return :running
68
69
            else
69
70
                return :stopped
76
77
        end
77
78
    end
78
79
 
 
80
    # There is no default command, which causes other methods to be used  
 
81
    def statuscmd
 
82
    end
 
83
    
79
84
    # Run the 'start' parameter command, or the specified 'startcmd'.
80
85
    def start
81
86
        ucommand(:start)
98
103
    # for the process in the process table.
99
104
    # This method will generally not be overridden by submodules.
100
105
    def stop
101
 
        if @resource[:stop] or self.respond_to?(:stopcmd)
 
106
        if @resource[:stop] or stopcmd
102
107
            ucommand(:stop)
103
108
        else
104
109
            pid = getpid
115
120
            return true
116
121
        end
117
122
    end
 
123
    
 
124
    # There is no default command, which causes other methods to be used  
 
125
    def stopcmd
 
126
    end
118
127
 
119
128
    # A simple wrapper so execution failures are a bit more informative.
120
129
    def texecute(type, command, fof = true)