Class: Sites
- Inherits:
-
StationModule
- Object
- StationModule
- Sites
- Defined in:
- lib/vagrant/conductor/modules/sites/sites.rb
Instance Attribute Summary collapse
-
#installing ⇒ Object
Returns the value of attribute installing.
-
#path ⇒ Object
Returns the value of attribute path.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_site_queue(site) ⇒ Object
- #commands_exec(commands, path) ⇒ Object
- #create_db(db) ⇒ Object
- #env_vars(vars) ⇒ Object
- #git_clone(name, url, path) ⇒ Object
-
#initialize(config, args, module_path, station) ⇒ Sites
constructor
A new instance of Sites.
- #provision ⇒ Object
- #sites_available(site) ⇒ Object
Constructor Details
#initialize(config, args, module_path, station) ⇒ Sites
Returns a new instance of Sites.
5 6 7 8 9 10 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 5 def initialize(config, args, module_path, station) super @path = "#{File.dirname(__FILE__)}" @installing = ENV.has_key?('INSTALL') @variables = {} end |
Instance Attribute Details
#installing ⇒ Object
Returns the value of attribute installing.
3 4 5 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 3 def installing @installing end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 3 def path @path end |
#variables ⇒ Object
Returns the value of attribute variables.
3 4 5 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 3 def variables @variables end |
Instance Method Details
#add_site_queue(site) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 144 def add_site_queue(site) Station.module('supervisor').create_config( site["map"], { :command => "php #{site['root']}/artisan queue:work --daemon --env=local --sleep=5 --queue=#{site['queue']}", :directory => site["root"], :log_path => site["root"] + '/app/storage/logs' } ) end |
#commands_exec(commands, path) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 109 def commands_exec(commands, path) path = commands.find?('path', path) if installing # install commands commands.find?('install', []).each do |cmd| Station.module('commands').execute(cmd, path, @variables) end else # update commands commands.find?('update', []).each do |cmd| Station.module('commands').execute(cmd, path, @variables) end end # always commands commands.find?('always', []).each do |cmd| Station.module('commands').execute(cmd, path, @variables) end end |
#create_db(db) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 132 def create_db(db) case db.find?('type', '') when "mysql" Station.module('mysql').create(db) when "postgresql" Station.module('postgresql').create(db) else Station.module('mysql').create(db) Station.module('postgresql').create(db) end end |
#env_vars(vars) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 89 def env_vars(vars) config.vm.provision 'shell' do |s| s.inline = "if [ ! -f #{env_path} ]; then touch #{env_path} ; else echo '' > #{env_path} ; fi" end shell_provision( "if [ ! -f #{env_path} ]; then touch #{env_path} ; else echo '' > #{env_path} ; fi" ) unless vars.empty? vars.each do |key, value| shell_provision( "echo \"$1 = '$2'\" >> #{env_path}", [key, value] ) end end end |
#git_clone(name, url, path) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 75 def git_clone(name, url, path) # Set installing var as true @installing = true if Dir.exists?(path) # Clone the site shell_provision( "bash #{scripts}/clone.sh $1 \"$2\" $3", [name, url, path] ) end |
#provision ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 157 def provision args.find?('sites', []).each do |site| base_path = site.find?('git-clone.path', site["to"]) # install configured nginx sites sites_available(site) # install/clone git repository url = site.find?('git-clone.url') if url git_clone(site.find?('git-clone.name', ''), url, base_path) end # Add site db db = site.find?('db') if db create_db(db) end # Run commands in installed site commands_exec(site.find?('commands', {}), base_path) # Add git config variables Station.module('git-config').fill(site.find?('git-config', {},), false, base_path) # Add ssl cert Station.module('ssl').generate(site["map"], {}) # Add queues add_site_queue(site) end end |
#sites_available(site) ⇒ Object
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 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 |
# File 'lib/vagrant/conductor/modules/sites/sites.rb', line 12 def sites_available(site) # compile fastcgi params hhvm_restart = '' if site.find?('hhvm', false) && site['hhvm'] === true hhvm_restart = 'service hhvm restart;' fastcgi = args["defaults"]["fastcgi-hhvm"] else fastcgi = args["defaults"]["fastcgi-server"] end if site.has_key?("fastcgi") && !site["fastcgi"].empty? fastcgi = fastcgi.deep_merge(site["fastcgi"]) end # compile php value overrides php_values = args["defaults"]["php-values"] ||= {} if site.has_key?("php-values") && !site["php-values"].empty? php_values = php_values.deep_merge(site["php-values"]) end # add xdebug values site.find?('xdebug', []).each do |key, value| php_values["xdebug.#{key}"] = value end # add environment variables variables = args["defaults"]["variables"] ||= {} if site.has_key?("variables") && !site["variables"].empty? variables = variables.deep_merge(site["variables"]) end @variables = variables if site.has_key?('dotenv') && site["dotenv"] === true template = File.read(path + "/templates/dotenv-array.erb") result = ERB.new(template, nil, '>').result(binding) shell_provision( "bash #{@scripts}/dotenv.sh $1 \"$2\"", [site.find?('root', site["to"]) + '/.env.local.php', result] ) end # Create the server template template = File.read(path + "/templates/server.erb") result = ERB.new(template).result(binding) # Add site to nginx script = %{ echo "#{result}" > "/etc/nginx/sites-available/#{site["map"]}"; ln -fs "/etc/nginx/sites-available/#{site["map"]}" "/etc/nginx/sites-enabled/#{site["map"]}"; service nginx restart; service php5-fpm restart; #{hhvm_restart} } shell_provision(script) end |