Skip to content

Instantly share code, notes, and snippets.

@karthik20522
Last active May 24, 2019 03:41
Show Gist options
  • Save karthik20522/e0c25708e3a398b8462a1fca8a6e95dc to your computer and use it in GitHub Desktop.
Save karthik20522/e0c25708e3a398b8462a1fca8a6e95dc to your computer and use it in GitHub Desktop.
Trivial bash Script to restart services in AWS
#!/bin/bash
set -e
function usage {
echo >&2 "Usage: $0 [ -e environment -n service_name -a action ]"
exit 1
}
while getopts ":n:e:a:" FLAG; do
case $FLAG in
n) NAME=${OPTARG};;
e) ENV=${OPTARG};;
a) ACTION=${OPTARG};;
[?]) usage;;
esac
done
if [[ -z $NAME || -z $ENV || -z $ACTION ]]; then
usage
fi
for fid in $(aws ec2 describe-instances --filters \
"Name=tag:ServerEnv,Values=${ENV}" \
"Name=tag:SubSystem,Values=${NAME}" \
--query 'Reservations[*].Instances[*].PrivateIpAddress' --output text)
do
ssh -n $fid "sudo ${ACTION} ${NAME}; exit;"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment