No commit activity in last 3 years
No release in over 3 years
Crontab DSL for Capistrano.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3.0

Runtime

>= 1.2
 Project Readme

Capistrano::Crontab

Gem Version GitHub license

This capistrano plugin is inspired by fab_deploy.crontab and allows you to add, remove and update cronjobs in your crontab.

Requirements

  • capistrano >= 3.0
  • sshkit >= 1.2

Installation

Add this to your Gemfile:

group :development do
  gem "capistrano"
  gem "capistrano-crontab"
end

And then:

$ bundle install

Setup

Add this line to Capfile:

require "capistrano/crontab"

DSL usage

on roles(:all) do
  # output the content of your crontab using `puts`
  crontab_puts_content

  #
  # Crontab:
  #   30 7 * * * start -q anacron || :
  #

  # get the content of your crontab
  crontab = crontab_get_content

  #
  # Crontab:
  #   30 7 * * * start -q anacron || :
  #

  # add a new cronjob to your crontab and mark it with "date"
  crontab_add_line("*/5 * * * * date >> /tmp/date", "date")

  #
  # Crontab:
  #   30 7 * * * start -q anacron || :
  #   */5 * * * * data >> /tmp/date # MARKER:date
  #

  # update an existing cronjob in your crontab, which is marked with "date"
  crontab_update_line("*/2 * * * * date >> /tmp/date", "date")

  #
  # Crontab:
  #   30 7 * * * start -q anacron || :
  #   */2 * * * * date >> /tmp/date # MARKER:date
  #

  # ensure that a cronjob exists in your crontab, and mark it with "snapshot"
  crontab_update_line("0 * * * * create_snapshot", "snapshot")

  #
  # Crontab
  #   30 7 * * * start -q anacron || :
  #   */2 * * * * date >> /tmp/date # MARKER:date
  #   0 * * * * create_snapshot # MARKER:snapshot
  #

  # remove the cronjob, which is marked with "date"
  crontab_remove_line("date")

  #
  # Crontab:
  #   30 7 * * * start -q anacron || :
  #   0 * * * * create_snapshot # MARKER:snapshot
  #

  # overwrite the whole crontab
  crontab_set_content("* * 1 * * send_invoices_to_customers")

  #
  # Crontab:
  #   * * 1 * * send_invoices_to_customers
  #
end

TODOs

  • Update DSL to look more like fab_deploy.crontab (e.g. crontab.add_line)