This shows you the differences between two versions of the page.
deploy_script_using_case [2011/04/26 16:53] jt created |
deploy_script_using_case [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Deploy Script Using Case ====== | ||
- | This script is meant to be used for varnish, but can be adapted for anything. | ||
- | |||
- | <code bash> | ||
- | #!/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 | ||
- | |||
- | </code> |