Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chef recipes: proxy_up, proxy_down, haproxy_add, haproxy_remove
######################
# 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
ssh -o StrictHostKeyChecking=no -i /home/deploy/.ssh/internal deploy@<%= @app_master %> "sudo sed -i -r 's/(<%= @private_hostname %>:81)/<%= @private_hostname %>:8080/g' /etc/haproxy.cfg"
/data/ngin/shared/bin/haproxy_add
echo 'Done'
######################
# proxy_down.sh.erb
#!/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/(<%= @private_hostname %>:8080)/<%= @private_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
echo 'Done'
######################
# 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"
######################
# 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/(.*<%= @private_hostname %>)/#&/g' /etc/haproxy.cfg; sudo /etc/init.d/haproxy reload"
######################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment