Sha256: dc8f841fba385d4624b8ea5ad881dc2f0162f86688d6e9c75cefe9b8911db7a3

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 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\n"
      crontab << "# Cron environment\n"
      crontab << (Makesure.cron_env || "#   customize this by setting Makesure.cron_env in your Makesurefile")
      crontab << "\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.5 lib/makesure/cron.rb