Last active
August 29, 2015 14:01
-
-
Save rhossi/03e5a07fef727786a33b 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
HTTPD_CONFD = "/etc/httpd/conf.d/" | |
HTTPD_WWW = "/var/www/" | |
def create_vhost(site) | |
vhost = <<-eos | |
<VirtualHost *:80> | |
\tDocumentRoot /var/www/#{site} | |
\tServerName #{site} | |
</VirtualHost> | |
eos | |
vhost_file = "#{HTTPD_CONFD}#{site}.conf" | |
File.open(vhost_file, "w") do |file| | |
file.puts(vhost) | |
file.close | |
end | |
vhost_dir = "#{HTTPD_WWW}#{site}" | |
Dir.mkdir(vhost_dir) | |
end | |
def create_sample_index(site) | |
vhost_dir = "#{HTTPD_WWW}#{site}" | |
sample_index_file = "#{vhost_dir}/index.html" | |
File.open(sample_index_file, "w") do |file| | |
file.puts("Hello from #{site}!") | |
file.close | |
end | |
end | |
def restart_httpd() | |
`service httpd restart` | |
end | |
exit if ARGV.length == 0 | |
site = ARGV[0] | |
create_vhost(site) | |
create_sample_index(site) | |
restart_httpd() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment