Class: Bonethug::Configurator

Inherits:
Object
  • Object
show all
Includes:
Digest, FileUtils
Defined in:
lib/bonethug/configurator.rb

Class Method Summary collapse

Class Method Details

.hosts(vh_cnf) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/bonethug/configurator.rb', line 17

def self.hosts(vh_cnf)
  hosts = "127.0.0.1 #{vh_cnf.get('server_name')}\n"
  aliases = vh_cnf.get('server_aliases')
  if aliases
    aliases.each do |index, server_alias|
      hosts += "127.0.0.1 #{server_alias}\n"
    end
  end
  hosts
end

.vhost(vh_cnf, base_path, is_remote = false) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bonethug/configurator.rb', line 28

def self.vhost(vh_cnf, base_path, is_remote = false)

  # server aliases
  server_aliases = ''
  aliases = vh_cnf.get('server_aliases')
  if aliases
    aliases.each do |index, server_alias|
      server_aliases += 'ServerAlias ' + server_alias + "\n"
    end
  end

  # environment variables
  env_vars = ''
  vars = vh_cnf.get('env_vars')
  if vars
    vars.each do |k, v|
      env_vars += 'SetEnv ' + k + ' ' + v + "\n"
    end
  end

  # server admin
  admin = vh_cnf.get('server_admin')
  server_admin = admin ? 'ServerAdmin ' + admin : ''      

  # paths
  shared_path = is_remote ? '/shared' : ''
  current_path = is_remote ? '/current' : ''

  case vh_cnf.get('type')

  when "nginx"

    vh = ""

  else # apache

    access = vh_cnf.get('version').to_f >= 2.4 ? "Require all granted" : "Order allow,deny\nAllow from all"

    vh = "
      <VirtualHost *:80>

        ServerName  #{vh_cnf.get('server_name')}
        #{server_aliases}

        #{server_admin}

        DocumentRoot #{base_path + current_path}/public

        #{env_vars}
        PassEnv PATH

        CustomLog #{base_path + shared_path}/log/bytes.log bytes
        CustomLog #{base_path + shared_path}/log/combined.log combined
        ErrorLog  #{base_path + shared_path}/log/error.log

        <Directory #{base_path + current_path}/public>

          Options Indexes MultiViews FollowSymLinks
          AllowOverride All
          #{access}

        </Directory>

      </VirtualHost>
    "
  end

  vh

end