Last active
May 24, 2019 03:41
-
-
Save karthik20522/e0c25708e3a398b8462a1fca8a6e95dc to your computer and use it in GitHub Desktop.
Trivial bash Script to restart services in AWS
This file contains hidden or 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
#!/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