mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-19 20:25:31 +00:00
32 lines
2.2 KiB
Bash
Executable File
32 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Enable sudo for user hudson for this script by adding the following to /etc/sudoers.d/hudsoncanlaunchec2instances:
|
|
# hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave
|
|
# hudson ALL = (root) NOPASSWD: /usr/local/bin/launchhudsonslave-java11
|
|
# hudson ALL = (root) NOPASSWD: /usr/local/bin/getLatestImageOfType.sh
|
|
AWS=/usr/bin/aws
|
|
REGION=eu-west-1
|
|
HUDSON_SLAVE_AMI_ID=$( /usr/local/bin/getLatestImageOfType.sh hudson-slave-11 )
|
|
echo Launching instance from AMI ${HUDSON_SLAVE_AMI_ID} ...
|
|
instanceid=`$AWS ec2 run-instances --image-id $HUDSON_SLAVE_AMI_ID --count 1 --instance-type c5d.4xlarge --key-name Axel --security-groups "Sailing Analytics App" --region $REGION --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=Hudson Ubuntu Slave Java 11}]' --instance-initiated-shutdown-behavior terminate | tee /tmp/slavelaunch.out | jq .Instances[0].InstanceId | sed -e 's/"//g'`
|
|
if [ "$instanceid" = "" ]; then
|
|
echo Error launching instance
|
|
exit 1
|
|
else
|
|
echo Instance ID is $instanceid
|
|
while [ "`$AWS ec2 describe-instances --region $REGION --instance-ids $instanceid | jq .Reservations[0].Instances[0].State.Name`" != "\"running\"" ]; do
|
|
echo Instance $instanceid not running yet\; trying again...
|
|
sleep 5
|
|
done
|
|
echo Instance $instanceid seems running now
|
|
private_ip=`$AWS ec2 describe-instances --region $REGION --instance-ids $instanceid | jq .Reservations[0].Instances[0].PrivateIpAddress | sed -e 's/"//g'`
|
|
echo Probing for SSH on private IP $private_ip
|
|
# Note: it's important to redirect stdin/stdout from/to /dev/null to ensure the Hudon master can properly connect stdin/stdout to the slave later
|
|
while ! su - hudson -c "ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no hudson@$private_ip mkdir -p /home/hudson/workspace/___test___\; rmdir /home/hudson/workspace/___test___ </dev/null >/dev/null 2>/dev/null"; do
|
|
echo SSH daemon not reachable yet. Trying again in a few seconds...
|
|
sleep 10
|
|
done
|
|
echo SSH daemon reached. State should be ready to connect to now.
|
|
su - hudson -c "ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no hudson@$private_ip \"/opt/sapjvm_8/bin/java -jar slave.jar; sudo /sbin/shutdown -h now\""
|
|
$AWS ec2 terminate-instances --instance-ids $instanceid
|
|
fi
|