Skip to content

Commit

Permalink
smoother command workflow (fixes #54) (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
hiroTochigi and dogi authored Jul 25, 2024
1 parent 87a3f08 commit 386b1e3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/aws/dependencies/utilitiyFunction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ function makePortArray {

echo "${portArray[@]}"
}

function getState(){
local instanceId=$1
local state=$(aws ec2 describe-instances --instance-ids $instanceId | jq '.Reservations[].Instances[].State.Name')
echo $state
}
4 changes: 2 additions & 2 deletions src/aws/down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function down(){
instanceId=$(getValueByAttribute $balloonName instanceId)

if [ "$instanceId" = "null" ]; then
echo "$balloonName is already deleted"
exit 1
echo "$balloonName does not exist"
exit 0
fi

keyName=$(getValueByAttribute $balloonName key)
Expand Down
14 changes: 13 additions & 1 deletion src/aws/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ function start(){
instanceId=$(getValueByAttribute $balloonName instanceId)

if [ "$instanceId" = "null" ]; then
echo "$balloonName is already deleted"
echo "$balloonName does not exist"
exit 1
fi

oldPublicIp=$(getValueByAttribute $balloonName publicIp)

state=$(getState $instanceId)

if [ "$state" == "\"running\"" ]; then
echo "The instance is already running"
exit 0
fi

if [ "$state" == "\"stopping\"" ]; then
echo "The instance is stopping"
exit 1
fi

aws ec2 start-instances --instance-ids $instanceId

echo "get the new ip address. The procedure might take time for a while"
Expand Down
8 changes: 7 additions & 1 deletion src/aws/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ function stop(){
instanceId=$(getValueByAttribute $balloonName instanceId)

if [ "$instanceId" = "null" ]; then
echo "$balloonName is already deleted"
echo "$balloonName does not exist"
exit 1
fi

state=$(getState $instanceId)
if [[ "$state" == "\"stopped\"" || "$state" == "\"stopping\"" ]]; then
echo "The instance is already stopped"
exit 0
fi

groupName=$(getValueByAttribute $balloonName groupName)
storePortArrayString $groupName tcp $balloonName
storePortArrayString $groupName udp $balloonName
Expand Down

0 comments on commit 386b1e3

Please sign in to comment.