IMPORTANTE:
1 - Se configurar isso em uma instância da Amazon, garanta(seu animal), que uma das instâncias desligadas NÃO SEJA a que gerencia o processo;
2 - Se trabalhares com regiões distintas deverás fazer condições no loop;
3 - Precisará o pacote da AWS de gerenciamento de cloud;
4 - Esqueci.
Para ligar:
#!/bin/bash # Description: Program to start AWS instances # --- Props vars --- # # System EC2_HOME=/opt/aws/apitools/ec2 JAVA_HOME=/usr/lib/jvm/jre export EC2_HOME JAVA_HOME # Rest vars x=0 # Instances instances=( "i-f32131" "i-0fc2435" "i-33213312" "i-f535324649" "i-98d74324329" ) # Keys AWS awsaccesskey="1234567890ABC" awssecretkey="1234315154364213357389460345ABC" # Program echo "|INIT Agent|" ; /bin/date while [ $x != ${#instances[@]} ] do echo "Start instance ${instances[$x]} ..." if [ ${instances[$x]} == "i-0fc2435" ] || [ ${instances[$x]} == "i-33213312" ] ; then # DC São Paulo /opt/aws/bin/ec2-start-instances -O ${awsaccesskey} -W ${awssecretkey} --region=sa-east-1 ${instances[$x]} fi # DC Virginia /opt/aws/bin/ec2-start-instances -O ${awsaccesskey} -W ${awssecretkey} ${instances[$x]} let "x = x +1" done echo "|FINISH Agent|" ; /bin/date
Para desligar:
#!/bin/bash # Description: Program to stop AWS instances # --- Props vars --- # # System EC2_HOME=/opt/aws/apitools/ec2 JAVA_HOME=/usr/lib/jvm/jre export EC2_HOME JAVA_HOME # Rest vars x=0 # Instances instances=( "i-f32131" "i-0fc2435" "i-33213312" "i-f535324649" "i-98d74324329" ) # Keys AWS awsaccesskey="1234567890ABC" awssecretkey="1234315154364213357389460345ABC" # Program echo "|INIT Agent|" ; /bin/date while [ $x != ${#instances[@]} ] do echo "Stop instance ${instances[$x]} ..." if [ ${instances[$x]} == "i-0fc2435" ] || [ ${instances[$x]} == "i-33213312" ] ; then # DC São Paulo /opt/aws/bin/ec2-stop-instances -O ${awsaccesskey} -W ${awssecretkey} --region=sa-east-1 ${instances[$x]} fi # DC Virginia /opt/aws/bin/ec2-stop-instances -O ${awsaccesskey} -W ${awssecretkey} ${instances[$x]} let "x = x +1" done echo "|FINISH Agent|" ; /bin/date
Nenhum comentário:
Postar um comentário