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

« back to all changes in this revision

Viewing changes to lib/puppet/type/cron.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:
3
3
require 'puppet/util/filetype'
4
4
 
5
5
Puppet::Type.newtype(:cron) do
6
 
    @doc = "Installs and manages cron jobs.  All fields except the command 
 
6
    @doc = "Installs and manages cron jobs.  All fields except the command
7
7
        and the user are optional, although specifying no periodic
8
8
        fields would result in the command being executed every
9
9
        minute.  While the name of the cron job is not part of the actual
10
10
        job, it is used by Puppet to store and retrieve it.
11
 
        
 
11
 
12
12
        If you specify a cron job that matches an existing job in every way
13
13
        except name, then the jobs will be considered equivalent and the
14
14
        new name will be permanently associated with that job.  Once this
15
15
        association is made and synced to disk, you can then manage the job
16
16
        normally (e.g., change the schedule of the job).
17
 
        
 
17
 
18
18
        Example::
19
 
            
 
19
 
20
20
            cron { logrotate:
21
21
                command => \"/usr/sbin/logrotate\",
22
22
                user => root,
89
89
        # or the first three letters of the word.
90
90
        def alphacheck(value, ary)
91
91
            tmp = value.downcase
92
 
            
 
92
 
93
93
            # If they specified a shortened version of the name, then see
94
94
            # if we can lengthen it (e.g., mon => monday).
95
95
            if tmp.length == 3
173
173
                return value
174
174
            end
175
175
 
 
176
            # Allow ranges + */2
 
177
            if value =~ /^[0-9]+-[0-9]+\/[0-9]+$/
 
178
                return value
 
179
            end
 
180
 
176
181
            if value == "*"
177
182
                return value
178
183
            end
211
216
            best to always provide a fully qualified command.  The user's
212
217
            profile is not sourced when the command is run, so if the
213
218
            user's environment is desired it should be sourced manually.
214
 
            
 
219
 
215
220
            All cron parameters support ``absent`` as a value; this will
216
221
            remove any existing values for that field."
217
222
 
218
 
        def retrieve 
 
223
        def retrieve
219
224
          return_value = super
220
225
          if return_value && return_value.is_a?(Array)
221
226
            return_value = return_value[0]
222
227
          end
223
 
            
 
228
 
224
229
          return return_value
225
230
        end
226
231
 
268
273
        def alpha
269
274
            %w{sunday monday tuesday wednesday thursday friday saturday}
270
275
        end
271
 
        self.boundaries = [0, 6]
 
276
        self.boundaries = [0, 7]
272
277
        desc "The weekday on which to run the command.
273
 
            Optional; if specified, must be between 0 and 6, inclusive, with
274
 
            0 being Sunday, or must be the name of the day (e.g., Tuesday)."
 
278
            Optional; if specified, must be between 0 and 7, inclusive, with
 
279
            0 (or 7) being Sunday, or must be the name of the day (e.g., Tuesday)."
275
280
    end
276
281
 
277
282
    newproperty(:month, :parent => CronParam) do
302
307
            job.  If you already have cron jobs with environment settings,
303
308
            then Puppet will keep those settings in the same place in the file,
304
309
            but will not associate them with a specific job.
305
 
            
 
310
 
306
311
            Settings should be specified exactly as they should appear in
307
312
            the crontab, e.g., ``PATH=/bin:/usr/bin:/usr/sbin``."
308
313
 
309
314
        validate do |value|
310
 
            unless value =~ /^\s*(\w+)\s*=\s*(.+)\s*$/ or value == :absent or value == "absent"
 
315
            unless value =~ /^\s*(\w+)\s*=\s*(.*)\s*$/ or value == :absent or value == "absent"
311
316
                raise ArgumentError, "Invalid environment setting %s" %
312
317
                    value.inspect
313
318
            end
322
327
        end
323
328
 
324
329
        def is_to_s(newvalue)
325
 
            if newvalue 
 
330
            if newvalue
326
331
                if newvalue.is_a?(Array)
327
332
                    newvalue.join(",")
328
333
                else
363
368
        desc "The user to run the command as.  This user must
364
369
            be allowed to run cron jobs, which is not currently checked by
365
370
            Puppet.
366
 
            
 
371
 
367
372
            The user defaults to whomever Puppet is running as."
368
373
 
369
374
        defaultto { Etc.getpwuid(Process.uid).name || "root" }