User Tools

Site Tools


deploy_script_using_case

Deploy Script Using Case

This script is meant to be used for varnish, but can be adapted for anything.

#!/bin/bash
 
## deploy-varnish.sh
## deploy default.vcl and/or reload varnish daemon on all hosts
 
if [ $# -lt 1 ]
then
  echo "Usage : $0 {deploy|deployall|reload|reloadall}"
  exit 1
fi
 
case "$1" in
  deploy)
    while read -r host
      do
        cat conf/default.vcl | ssh $host 'sudo /bin/sh -c "cat > /etc/varnish/default.vcl"'
      done < <(head -n1 hosts)
      echo "deployed config to $host" 
  ;;
  deployall)
    while read -r host
      do
        cat conf/default.vcl | ssh $host 'sudo /bin/sh -c "cat > /etc/varnish/default.vcl"'
      done < hosts
      echo "deployed config to all hosts" 
  ;;  
  reload)
    while read -r host
      do
        ssh $host 'sudo /bin/sh -c "/etc/init.d/varnishd reload || /etc/init.d/varnish reload"'
        echo "reloaded varnishd on $host" 
      done < <(head -n1 hosts)
  ;;  
  reloadall)
    read -r -p "Are you sure? [Y/n] " response
    if [[ $response == "y" || $response == "Y" || $response == "yes" || $response == "Yes" ]]
    then
      while read -r host
        do
          ssh $host 'sudo /bin/sh -c "/etc/init.d/varnishd reload || /etc/init.d/varnish reload"'
        done < hosts
        echo "reloaded varnishd on all hosts" 
    else
      echo "Abort!"
    fi
  ;;  
 
esac
deploy_script_using_case.txt · Last modified: 2011/04/26 12:53 by jt