module CapistranoCrontab def uninstall run <<-CMD if crontab -l > /dev/null 2>&1; then TEMP_CRONTAB=`mktemp` && crontab -l | sed '/^#{crontab_header}\\s*$/,/^#{crontab_footer}\\s*$/d' > $TEMP_CRONTAB && crontab $TEMP_CRONTAB && rm $TEMP_CRONTAB; fi CMD end def install run <<-CMD cd #{release_path} && TEMP_CRONTAB=`mktemp` && TEMP_CRONTAB2=`mktemp` && if crontab -l > /dev/null 2>&1; then crontab -l >> $TEMP_CRONTAB; fi && echo >> $TEMP_CRONTAB && echo "#{crontab_header}" >> $TEMP_CRONTAB && cat config/crontab >> $TEMP_CRONTAB && echo "#{crontab_footer}" >> $TEMP_CRONTAB && cat $TEMP_CRONTAB | sed '/./,/^$/!d' > $TEMP_CRONTAB2 && crontab $TEMP_CRONTAB2 && rm $TEMP_CRONTAB $TEMP_CRONTAB2 CMD end def update uninstall install end def crontab_header "\# #{application}" end def crontab_footer "\# end #{application}" end end Capistrano.plugin :crontab, CapistranoCrontab