apacheconf
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
def mongrel_thin(config_file)
  require 'yaml'
  config = YAML.load_file(config_file)
  ip = config['address'] || '127.0.0.1'
  servers = config['servers'] || 1
  ports = port_range = config['port']..(config['port'] + servers - 1)
  ports.each do |port|
    puts "BalancerMember http://#{ip}:#{port}"
  end
end
case ARGV.first
when 'mongrel'
  mongrel_thin(File.dirname(__FILE__) + "/../config/mongrel_cluster.yml")
when 'thin'
  mongrel_thin(File.dirname(__FILE__) + "/../config/thin.yml")
when 'virtualhosts'
  require File.dirname(__FILE__) + '/../config/environment'
  Environment.all.each do |environment|
    domains = environment.domains.sort do |domain|
      domain.is_default ? 0 : 1
    end
    if domains.empty?
      domains << Domain.new(:name => 'localhost')
    end
    puts "# #{environment.name}"
    puts "<VirtualHost *:80>"
    server_directive = 'ServerName'
    domains.each do |domain|
      puts "  #{server_directive} #{domain.name}"
      server_directive = 'ServerAlias'
    end
    puts "  Include /etc/noosfero/apache/virtualhost.conf"
    puts "</VirtualHost>"
  end
  puts "# vim: ft=apache"
else
  puts "usage: %s mongrel|thin|virtualhosts" % $PROGRAM_NAME
  exit 1
end