Last active
August 29, 2015 13:56
-
-
Save vbatts/9279505 to your computer and use it in GitHub Desktop.
vhost proxypass migration
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 oo-ruby | |
=begin | |
Author: Vincent Batts <[email protected]> | |
Data: Fri Feb 28 15:42:09 EST 2014 | |
Description: Migration script for https://trello.com/c/q1ro2vDB/408-3-use-proxy-pass-for-virtual-hosts-plugin-instead-of-mod-rewrite | |
NOTE: this only applies to setups that are using the vhost plugin, namely OSE | |
=end | |
require "find" | |
require "json" | |
require "tempfile" | |
NODE_CONF="/etc/openshift/node.conf" | |
# this is likely a symlink, so add the / so we can find on it | |
OPENSHIFT_HTTP_CONF_DIR=`source #{NODE_CONF} && echo $OPENSHIFT_HTTP_CONF_DIR`.chomp + "/" | |
BACKUP_SUFFIX=".bak.#{$$}" | |
Find.find(OPENSHIFT_HTTP_CONF_DIR) do |path| | |
next unless FileTest.file?(path) && path.end_with?("element-.conf") | |
tfh = Tempfile.new("oo_proxypass") | |
fh = File.open(path, "a+") | |
fh.seek(0) | |
line = fh.readline() | |
tfh.puts(line) | |
data = JSON.load(line.split("ELEMENT: ").last()) | |
puts "#{ARGV[0]}: found #{path}" | |
# data is like: | |
# ["", "127.1.244.1:8080", {"websocket"=>true, "protocols"=>["http", "ws"]}] | |
tpath = data[0].length > 0 ? data[0] : "/" | |
data.last["protocols"].each do |proto| | |
next if proto == "ws" # httpd doesn't do 'ws' | |
tfh.puts("ProxyPass #{tpath} #{proto}://#{data[1]}/") | |
end | |
# finish copying/assembling the tempfile | |
loop do | |
begin | |
line = fh.readline() | |
rescue EOFError | |
break | |
end | |
next if line =~ /^RewriteRule/ # skip these | |
tfh.puts(line) | |
end | |
tfh.close() | |
fh.close() | |
backup_path="#{fh.path}#{BACKUP_SUFFIX}" | |
IO.copy_stream(fh.path, backup_path) | |
puts "#{ARGV[0]}: backed up to #{backup_path}" | |
IO.copy_stream(tfh.path, fh.path) | |
puts "#{ARGV[0]}: wrote new data to #{fh.path}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment