~ubuntu-branches/ubuntu/wily/puppet/wily

« back to all changes in this revision

Viewing changes to lib/puppet/type/cron.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-04-17 14:50:28 UTC
  • mfrom: (3.1.59 sid)
  • Revision ID: package-import@ubuntu.com-20140417145028-j3p3dwvp8ggpzvaf
Tags: 3.5.1-1
ImportedĀ upstreamĀ releaseĀ 3.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    Installs and manages cron jobs.  Every cron resource requires a command
8
8
    and user attribute, as well as at least one periodic attribute (hour,
9
9
    minute, month, monthday, weekday, or special).  While the name of the cron
10
 
    job is not part of the actual job, it is used by Puppet to store and
11
 
    retrieve it.
 
10
    job is not part of the actual job, the name is stored in a comment beginning with
 
11
    `# Puppet Name: `. These comments are used to match crontab entries created by
 
12
    Puppet with cron resources.
12
13
 
13
 
    If you specify a cron resource that duplicates the scheduling and command
14
 
    used by an existing crontab entry, then Puppet will take no action and
15
 
    defers to the existing crontab entry.  If the duplicate cron resource
16
 
    specifies `ensure => absent`, all existing duplicated crontab entries will
17
 
    be removed.  Specifying multiple duplicate cron resources with different
18
 
    `ensure` states will result in undefined behavior.
 
14
    If an existing crontab entry happens to match the scheduling and command of a
 
15
    cron resource that has never been synched, Puppet will defer to the existing
 
16
    crontab entry and will not create a new entry tagged with the `# Puppet Name: `
 
17
    comment.
19
18
 
20
19
    Example:
21
20
 
234
233
    end
235
234
 
236
235
    def munge(value)
237
 
      value.sub!(/^\s+/, '')
238
 
      value.sub!(/\s+$/, '')
239
 
      value
 
236
      value.strip
240
237
    end
241
238
  end
242
239
 
409
406
    }
410
407
  end
411
408
 
 
409
  validate do
 
410
    return true unless self[:special]
 
411
    return true if self[:special] == :absent
 
412
    # there is a special schedule in @should, so we don't want to see
 
413
    # any numeric should values
 
414
    [ :minute, :hour, :weekday, :monthday, :month ].each do |field|
 
415
      next unless self[field]
 
416
      next if self[field] == :absent
 
417
      raise ArgumentError, "#{self.ref} cannot specify both a special schedule and a value for #{field}"
 
418
    end
 
419
  end
 
420
 
412
421
  # We have to reorder things so that :provide is before :target
413
422
 
414
423
  attr_accessor :uid
415
424
 
 
425
  # Marks the resource as "being purged".
 
426
  #
 
427
  # @api public
 
428
  #
 
429
  # @note This overrides the Puppet::Type method in order to handle
 
430
  #   an edge case that has so far been observed during testig only.
 
431
  #   Without forcing the should-value for the user property to be
 
432
  #   identical to the original cron file, purging from a fixture
 
433
  #   will not work, because the user property defaults to the user
 
434
  #   running the test. It is not clear whether this scenario can apply
 
435
  #   during normal operation.
 
436
  #
 
437
  # @note Also, when not forcing the should-value for the target
 
438
  #   property, unpurged file content (such as comments) can end up
 
439
  #   being written to the default target (i.e. the current login name).
 
440
  def purging
 
441
    self[:target] = provider.property_hash[:target]
 
442
    self[:user] = provider.property_hash[:target]
 
443
    super
 
444
  end
 
445
 
416
446
  def value(name)
417
447
    name = name.intern
418
448
    ret = nil