This repository was archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from alphagov/persistent-storage
Persistent storage
- Loading branch information
Showing
7 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
terraform/projects/app-ecs-instances/instance-user-data.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
#!/bin/bash | ||
# Attach EBS volume to instance | ||
echo "[$(date '+%H:%M:%S %d-%m-%Y')] installing dependencies for volume attaching" | ||
sudo yum install -y aws-cli wget | ||
|
||
echo 'ECS_CLUSTER=${cluster_name}' >> /etc/ecs/ecs.config | ||
REGION="${region}" | ||
DEVICE="xvdf" | ||
VOLUME_ID="${volume_id}" | ||
|
||
echo "[$(date '+%H:%M:%S %d-%m-%Y')] finding current instance ID" | ||
INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`" | ||
|
||
echo "[$(date '+%H:%M:%S %d-%m-%Y')] attaching volume" | ||
aws ec2 attach-volume --volume-id $VOLUME_ID --instance-id $INSTANCE_ID --device /dev/$DEVICE --region $REGION | ||
|
||
# Waiting for volume to finish attaching | ||
x=0 | ||
while [[ $x -lt 15 ]]; do | ||
if ! [[ -e /dev/$DEVICE ]] ; then | ||
sleep 1 | ||
else | ||
break | ||
fi | ||
x=$((x+1)) | ||
done | ||
|
||
# Format and mount volume | ||
if file -s /dev/$DEVICE | grep -q "/dev/$DEVICE: data"; then | ||
echo "[$(date '+%H:%M:%S %d-%m-%Y')] attach-volume: /dev/$DEVICE does not contain any partition, beginning to format disk" | ||
mkfs -t ext4 /dev/$DEVICE | ||
else | ||
echo "[$(date '+%H:%M:%S %d-%m-%Y')] attach-volume: /dev/$DEVICE is already formatted: $(file -s /dev/$DEVICE)" | ||
fi | ||
|
||
# Allow prometheus container user access to read/write/execute within container | ||
mkdir -p /ecs/prometheus_data | ||
mount /dev/$DEVICE /ecs/prometheus_data | ||
chmod 777 /ecs/prometheus_data | ||
|
||
# Set any ECS agent configuration options | ||
echo 'ECS_CLUSTER=${cluster_name}' >> /etc/ecs/ecs.config | ||
yum install -y ecs-init | ||
start ecs | ||
service docker start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters