Skip to content

Instantly share code, notes, and snippets.

@rhossi
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhossi/03e5a07fef727786a33b to your computer and use it in GitHub Desktop.
Save rhossi/03e5a07fef727786a33b to your computer and use it in GitHub Desktop.
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