Sha256: bbb5f93c308e9df4f4caf6da63d34ab4206b9114d9180183c2e4ffad54a50d16

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 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
      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 << "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 << "makesure-runner verify #{s.name} #{v.name}\n"
        end
        # TODO summarizes
      end
      crontab
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
makesure-0.0.2 lib/makesure/cron.rb
makesure-0.0.1 lib/makesure/cron.rb