Skip to content

Instantly share code, notes, and snippets.

@mdolian
Created March 31, 2009 23:44
Show Gist options
  • Save mdolian/88474 to your computer and use it in GitHub Desktop.
Save mdolian/88474 to your computer and use it in GitHub Desktop.
desc <<-DESC
Clean up old releases. By default, the last 5 releases are kept on each \
server (though you can change this with the keep_releases variable). All \
other deployed revisions are removed from the servers. By default, this \
will use sudo to clean up the old releases, but if sudo is not available \
for your environment, set the :use_sudo variable to false instead.
DESC
task :cleanup, :except => { :no_release => true } do
count = fetch(:keep_releases, 5).to_i
if count >= releases.length
logger.important "no old releases to clean up"
else
logger.info "keeping #{count} of #{releases.length} deployed releases"
directories = (releases - releases.last(count)).map { |release|
File.join(releases_path, release) }.join(" ")
try_sudo "rm -rf #{directories}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment