Skip to content

Instantly share code, notes, and snippets.

@terrafied
Created March 11, 2011 20:47
Show Gist options
  • Save terrafied/866537 to your computer and use it in GitHub Desktop.
Save terrafied/866537 to your computer and use it in GitHub Desktop.
deploy.rb
#!/usr/local/bin/ruby
if ARGV.length < 2
raise "Must have a path and a deployment name (i.e. deploy.rb /path/to/app theappname)"
end
p "Deploying for #{ARGV.join(",")}"
def listdir path
dirs = Dir.entries(path)
dirs.delete(".")
dirs.delete("..")
dirs
end
path = "/webapps/#{ARGV[1]}"
release_path = path + "/releases/" + Time.now.to_i.to_s
shared_path = path + "/shared"
old_releases = 2
# Clean releases directory
dirs = listdir("#{path}/releases").sort.reverse
dirs.delete(".")
dirs.delete("..")
system "rm -rf #{path}/releases/#{dirs.pop}" until dirs.length < old_releases + 1
system "/bin/mkdir -p #{release_path}"
system "/bin/rm -rf #{path}/current"
system "/bin/ln -sf #{release_path} #{path}/current"
system "/bin/cp -r #{ARGV[0]}/* #{release_path}"
%w(config log).each do |shared|
files = listdir(File.join("#{shared_path}","#{shared}"))
files.each do |file|
system "cp #{shared_path}/#{shared}/#{file} #{release_path}/#{shared}/#{file}"
end
end
system "touch #{release_path}/log/production.log"
system "touch #{release_path}/tmp/restart.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment