Created
June 16, 2009 03:04
-
-
Save Sutto/130503 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| def run_silently(command) | |
| IO.popen(command) { |f| f.read } | |
| end | |
| if ARGV.size < 2 | |
| puts "Usage: #{File.basename(__FILE__)} domain [path=/var/apps/#\{domain\}] [user=deployer] [--no-capistrano]" | |
| end | |
| TEMPLATE = <<-END | |
| <VirtualHost *:80> | |
| ServerName DOMAIN | |
| DocumentRoot PATH | |
| <Directory "PATH"> | |
| Options FollowSymLinks | |
| AllowOverride None | |
| Order allow,deny | |
| Allow from all | |
| </Directory> | |
| </VirtualHost> | |
| END | |
| capistrano = !ARGV.include?("--no-capistrano") | |
| domain = ARGV[0] | |
| path = File.expand_path(ARGV[1] || "/var/apps/#{domain}") | |
| user = ARGV[2] || "deployer" | |
| print "1. Creating directory w/ correct permissions" | |
| run_silently "mkdir -p '#{path}'" | |
| run_silently "chown -R #{user}:deploy '#{path}'" | |
| puts " [DONE]" | |
| print "2. Creating vhost file" | |
| vhost_file = "/etc/apache2/sites-available/#{domain}" | |
| full_path = File.join(path, (capistrano ? "current/public" : "public")) | |
| File.open(vhost_file, "w+") do |f| | |
| f.puts(TEMPLATE.gsub("DOMAIN", domain).gsub("PATH", full_path)) | |
| end | |
| run_silently "chown root '#{vhost_file}'" | |
| puts " [DONE]" | |
| print "3. Enabling the site" | |
| run_silently "a2ensite #{domain}" | |
| puts " [DONE]" | |
| print "4. Restarting Apache 2" | |
| run_silently "/etc/init.d/apache2 restart" | |
| puts " [DONE]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment