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
# Performs a mail merge based on the options hash that is passed in | |
# Example: text_block.merged_content({:site => @site, :user => @user}) | |
# will search text_block.content and find all instances of ::user.[method]:: | |
# and ::site.[method]:: and send the [method] to the associated object | |
# Chaining works as well (ex. ::site.organization.name:: yields 'TST Media') | |
def merged_content(content, options = {}) | |
merged = content | |
options.keys.each do |key| | |
obj = options[key] |
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
# proxy.rb.erb | |
require 'em-proxy' | |
# @emproxy_port - the port we want this process receiving traffic on (ex: 8080) | |
# @nginx_port - the port that normally processes traffic that we are now duplexing (ex: 81) | |
# @proxy_ip - the IP address we are duplexing to (ex: 10.10.10.10) | |
# @proxy_port - the port that we are duplexing to (ex: 80) | |
Proxy.start(:host => "0.0.0.0", :port => <%= @emproxy_port %>) do |conn| | |
conn.server :self, :host => '127.0.0.1', :port => <%= @nginx_port %> |
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
# /data/ngin/shared/proxy/proxy.rb | |
require 'em-proxy' | |
Proxy.start(:host => "0.0.0.0", :port => EMPROXY_PORT) do |conn| | |
conn.server :self, :host => '127.0.0.1', :port => NGINX_PORT | |
conn.server :proxy, :host => PROXY_IP, :port => PROXY_PORT | |
conn.on_data do |data| | |
data | |
end | |
conn.on_response do |server, resp| |
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
###################### | |
# proxy_up.sh.erb | |
#!/bin/bash | |
echo 'Starting emproxy...' | |
sudo monit start all -g emproxy_ngin | |
echo 'Sleeping for 5s before reloading haproxy...' | |
sleep 5 | |
echo 'Reloading haproxy...' | |
/data/ngin/shared/bin/haproxy_remove |
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
# proxy_up.sh | |
#!/bin/bash | |
echo 'Starting emproxy...' | |
sudo monit start all -g emproxy_ngin | |
echo 'Sleeping for 5s before reloading haproxy...' | |
sleep 5 | |
echo 'Reloading haproxy...' | |
/data/ngin/shared/bin/haproxy_remove | |
ssh -o StrictHostKeyChecking=no -i /home/deploy/.ssh/internal deploy@APP_MASTER "sudo sed -i -r 's/(HOSTNAME:81)/HOSTNAME:8080/g' /etc/haproxy.cfg" | |
/data/ngin/shared/bin/haproxy_add |
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
# proxy_down.sh | |
#!/bin/bash | |
echo 'Reloading haproxy...' | |
/data/ngin/shared/bin/haproxy_remove | |
ssh -o StrictHostKeyChecking=no -i /home/deploy/.ssh/internal deploy@APP_MASTER "sudo sed -i -r 's/(HOSTNAME:8080)/HOSTNAME:81/g' /etc/haproxy.cfg" | |
/data/ngin/shared/bin/haproxy_add | |
echo 'Sleeping for 5s before stopping emproxy...' | |
sleep 5 | |
echo 'Stopping emproxy...' | |
sudo monit stop all -g emproxy_ngin |
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
# haproxy_add | |
#!/bin/sh | |
# Add this instance back into haproxy on the app_master | |
ssh -o StrictHostKeyChecking=no -i /home/deploy/.ssh/internal deploy@APP_MASTER "sudo sed -i -r 's/^#*\s\sserver/ server/g' /etc/haproxy.cfg; sudo /etc/init.d/haproxy reload" |
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
# haproxy_remove | |
#!/bin/sh | |
# Remove this instance from haproxy on the app_master | |
ssh -o StrictHostKeyChecking=no -i /home/deploy/.ssh/internal deploy@APP_MASTER "sudo sed -i -r 's/(.*HOSTNAME)/#&/g' /etc/haproxy.cfg; sudo /etc/init.d/haproxy reload" |
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
# /data/ngin/shared/bin/emproxy/emproxy.sh | |
#!/bin/sh | |
# This script starts and stops the em-proxy | |
# This script belongs in /data/ngin/shared/bin | |
############################################################################### | |
export PATH=/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2 | |
############################################################################### | |
usage() { | |
echo "Usage: $0 <appname> {start, stop} [ssl]" |
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
# /etc/monit.d/emproxy.monitrc | |
check process emproxy_ngin | |
with pidfile /var/run/emproxy_ngin.pid | |
start program = "/data/ngin/shared/bin/emproxy ngin start" with timeout 30 seconds | |
stop program = "/data/ngin/shared/bin/emproxy ngin stop" with timeout 30 seconds | |
group emproxy_ngin |
OlderNewer