Sha256: a4b57b4af9470e0a27a57c82b0f47e1a951ab5ecf8d6fa60ed3980af03f23b16

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

module Makesure

  class Cron
    
    # specify a file (or directory containing files) to load system specifications from
    def initialize(opts = {})
      opts = {
        :cron_path => "/etc/cron.d/makesure.cron"
      }.merge(opts)
      
      Makesure.log "updating '#{opts[:cron_path]}'"
      
      cron_file = File.expand_path(opts[:cron_path])
      crontab = build_crontab_output
      Makesure.debug "#{cron_file}:\n#{crontab}"
      
      File.open(cron_file, "w") do |f|
        f.write(crontab)
      end
    end

    def build_crontab_output
      chdir = Makesure.chdir || File.dirname(Makesure.makesurefile)
      crontab = ""
      crontab << "# Autogenerated by makesure: you probably don't want to edit this file\n"
      Makesure.systems.each do |s|
        uid = s.uid || Makesure.uid
        crontab << "\n"
        crontab << "## Tasks for '#{s.name}'\n"
        crontab << "# Commands\n"
        s.cmds.each do |c|
          crontab << "#{c.cron}\t"
          crontab << "#{uid} " if uid
          crontab << "cd #{chdir} && "
          crontab << "makesure-runner run #{c.command.inspect}\n"
        end
        crontab << "# Verification\n"
        s.verifies.each do |v|
          crontab << "#{v.cron}\t"
          crontab << "#{uid} " if uid
          crontab << "cd #{chdir} && "
          crontab << "makesure-runner verify #{s.name} #{v.name}\n"
        end
        # TODO summarizes
      end
      crontab
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
makesure-0.0.4 lib/makesure/cron.rb