My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

The goal of this small ruby program is to generate dozen of apache vhost with snippets.

Each vhost can go on many web server ( with load-balancing by example ).

1) A config file with your different servers configuration and parameters

$ cat config.rb 
@servers=
{
'server01' => {
	'HTTP_PORT' 		=> '80',
	'HTTPS_PORT'		=> '443',
	'SERVER_NAME' 		=> 'web1',
	'SERVER_IP'		=> '192.168.0.100'
	},
'server02' => {
        'HTTP_PORT'             => '80',
        'HTTPS_PORT'            => '443',
        'SERVER_NAME'            => 'web2',
	'SERVER_IP'             => '192.168.0.101'
        }
}

2) Define some snippets

$ cat snippet/aliases 
Alias 	/css	/usr/local/share/#{project}/css
Alias   /js     /usr/local/share/#{project}/js

3) Define some vhosts using previous definitions

$ cat src/project01
#setconfig:project=mywebsite
<VirtualHost #{SERVER_IP}:#{HTTP_PORT}>
    ServerName www.#{project}.com
    ServerAlias #{SERVER_NAME}.#{project}.com
#{snippet:aliases}
</VirtualHost>

$ cat src/project02
#setconfig:project=anotherwebsite
<VirtualHost #{SERVER_IP}:#{HTTP_PORT}>
    ServerName www.#{project}.com
    ServerAlias #{SERVER_NAME}.#{project}.com
#{snippet:aliases}
</VirtualHost>

4) Launch atpl

$ ./atpl.rb 
 * server01
..
 * server02
..

5) Use the result in your servers

$ cat generated/server01/project01 
# Generated by atpl - https://code.google.com/p/atpl/
# Mon Dec 07 22:59:32 +0100 2009
<VirtualHost 192.168.0.100:80>
    ServerName www.mywebsite.com
    ServerAlias web1.mywebsite.com
Alias 	/css	/usr/local/share/mywebsite/css
Alias   /js     /usr/local/share/mywebsite/js

</VirtualHost>

$ cat generated/server01/project02
# Generated by atpl - https://code.google.com/p/atpl/
# Mon Dec 07 22:59:32 +0100 2009
<VirtualHost 192.168.0.100:80>
    ServerName www.anotherwebsite.com
    ServerAlias web1.anotherwebsite.com
Alias 	/css	/usr/local/share/anotherwebsite/css
Alias   /js     /usr/local/share/anotherwebsite/js

</VirtualHost>

$ cat generated/server02/project01 
# Generated by atpl - https://code.google.com/p/atpl/
# Mon Dec 07 22:59:32 +0100 2009
<VirtualHost 192.168.0.101:80>
    ServerName www.mywebsite.com
    ServerAlias web2.mywebsite.com
Alias 	/css	/usr/local/share/mywebsite/css
Alias   /js     /usr/local/share/mywebsite/js

</VirtualHost>

$ cat generated/server02/project02
# Generated by atpl - https://code.google.com/p/atpl/
# Mon Dec 07 22:59:32 +0100 2009
<VirtualHost 192.168.0.101:80>
    ServerName www.anotherwebsite.com
    ServerAlias web2.anotherwebsite.com
Alias 	/css	/usr/local/share/anotherwebsite/css
Alias   /js     /usr/local/share/anotherwebsite/js

</VirtualHost>
Powered by Google Project Hosting