Sha256: 2acba204914bb8af00c576fe27fc66a2c919d0cdc61c934a11391b435c263ecf

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

#!/bin/bash

USAGE="Uso: app_stop_instances_by_role.sh <RAILS_ENV> <ROLE>"

RAILS_ENV=$1
ROLE=$2

if [ -z $RAILS_ENV ]  || [ -z $ROLE ]; then
  echo "Argumentos RAILS_ENV e ROLE são obrigatórios."
  echo $USAGE
  exit
fi

if [ $RAILS_ENV != 'staging' ]  && [ $RAILS_ENV != 'production' ]; then
  echo "Valores permitidos para o argumento RAILS_ENV são: staging, production."
  echo $USAGE
  exit
fi

if [ $RAILS_ENV = 'production' ]; then
  REGION="us-east-1"
else
  REGION="us-west-2"
fi

# get instance ids
instance_ids=$(aws ec2 describe-instances --region $REGION --output text --filter "Name=tag:Name,Values=<%= @app_name %>*" "Name=tag:Env,Values=$RAILS_ENV" "Name=tag:Role,Values=$ROLE" "Name=instance-state-name,Values=running" | grep INSTANCES | awk '{if ($18 == "ebs") print $9}')

# stop instances
if [ -n "$instance_ids" ]
then
  aws ec2 stop-instances --region $REGION --instance-ids $instance_ids
else
  echo "Nenhuma instância do ROLE '$ROLE' encontrada no ambiente '$RAILS_ENV'."
fi

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws_stack_builder-0.1.0 lib/generators/aws_stack_builder/templates/aws/scripts/app_stop_instances_by_role.sh.template