mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
added error handling
This commit is contained in:
parent
6172f98eab
commit
0e2d71c303
1 changed files with 42 additions and 14 deletions
|
|
@ -5,13 +5,32 @@
|
|||
function deploy_node() {
|
||||
# get AMI, security group and subnet ID
|
||||
AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile $PROFILE)
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "aws session manager find ami failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SECURITY_GROUP=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 Name=group-name,Values=default --query 'SecurityGroups[*].[GroupId]' --output text --profile $PROFILE)
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "aws session manager find security group failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE)
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "aws session manager find subnet ID failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# launch EC2 instance and get instance ID
|
||||
aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "Launching EC2 instance failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INSTANCE_ID=$(jq '.Instances | .[0] |.InstanceId' config.json | tr -d '"')
|
||||
echo "Instance ID: " $INSTANCE_ID
|
||||
echo "Launched EC2 instance with Instance ID: " $INSTANCE_ID
|
||||
}
|
||||
|
||||
function initialize_featurebase() {
|
||||
|
|
@ -19,10 +38,17 @@ function initialize_featurebase() {
|
|||
for i in {0..24}
|
||||
do
|
||||
IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE)
|
||||
if [ -n "$IP" ]; then
|
||||
if [ -n "$IP" ]; then
|
||||
echo "Public IP for EC2 instance: " $IP
|
||||
break
|
||||
fi
|
||||
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "aws cli describe-instances command failed"
|
||||
terminate_node
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 5
|
||||
done
|
||||
|
||||
|
|
@ -30,17 +56,26 @@ function initialize_featurebase() {
|
|||
|
||||
# copy featurebase binary and files to ec2 instance
|
||||
scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:.
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "scp of featurebase binary, service and config files to EC2 instance failed"
|
||||
terminate_node
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# execute script to configure featurebase on the EC2 node
|
||||
aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region $REGION
|
||||
if [[ $? > 0 ]]; then
|
||||
echo "aws cli session manager command failed"
|
||||
terminate_node
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function terminate_node() {
|
||||
aws ec2 terminate-instances --instance-ids $INSTANCE_ID
|
||||
aws ec2 terminate-instances --instance-ids $INSTANCE_ID --profile $PROFILE
|
||||
}
|
||||
|
||||
# Pass variables to shell script
|
||||
|
||||
PROFILE=$1
|
||||
shift
|
||||
|
||||
|
|
@ -51,17 +86,10 @@ REGION="us-east-2"
|
|||
# get AMI, security group and subnet for EC2 instance,
|
||||
# launch instance, save instance Id and run cloud-init to set up node env
|
||||
deploy_node
|
||||
if [[ $? > 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get IP for instance, scp featurebase binary, config and service files;
|
||||
# set up featurebase config in node
|
||||
initialize_featurebase
|
||||
if [[ $? > 0 ]]; then
|
||||
terminate_node
|
||||
exit 1
|
||||
else
|
||||
terminate_node
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# terminate node
|
||||
terminate_node
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue