Created
August 2, 2013 11:25
-
-
Save kikyous/6139206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pathname' | |
NGINX_ROOT = Pathname.new('/opt/nginx') | |
SERVER_EXT = 'dev' | |
projects=Pathname.glob(::File.expand_path('../*/config.ru', __FILE__)).map(&:dirname) | |
dev_conf_dir="#{NGINX_ROOT.join('conf',SERVER_EXT)}" | |
`[ -d #{dev_conf_dir} ] || mkdir #{dev_conf_dir}` | |
projects.each do |p| | |
url="#{p.basename}.#{SERVER_EXT}" | |
puts "process #{p.basename} ... " | |
`sed -i '/#{p.basename}/d' /etc/hosts` | |
`echo '127.0.0.1 #{url}' >> /etc/hosts` | |
config="server { | |
listen 80; | |
server_name #{url}; | |
root #{p.join('public')}; | |
rails_env development; | |
passenger_enabled on; }" | |
Dir.chdir(NGINX_ROOT.join('conf',SERVER_EXT)){ | |
`echo "#{config}" > "#{url}.conf"` | |
} | |
puts "ok, http://#{url}" | |
end | |
`sed -i 's#include.*conf#include #{SERVER_EXT}/*.conf#' #{NGINX_ROOT.join('conf','nginx.conf')}` | |
puts 'reload nginx...' | |
`#{NGINX_ROOT.join('sbin','nginx')} -s reload` | |
puts 'ok' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment