forked from awslabs/amazon-ebs-autoscale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
50 lines (39 loc) · 1.21 KB
/
uninstall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -x
BASEDIR=$(dirname $0)
. ${BASEDIR}/shared/utils.sh
initialize
MOUNTPOINT=$(get_config_value .mountpoint)
instance_id=$(get_metadata instance-id)
availability_zone=$(get_metadata placement/availability-zone)
region=${availability_zone%?}
# stop and uninstall the service
INIT_SYSTEM=$(detect_init_system 2>/dev/null)
case $INIT_SYSTEM in
upstart|systemd)
echo "$INIT_SYSTEM detected"
cd ${BASEDIR}/service/$INIT_SYSTEM
. ./uninstall.sh
;;
*)
echo "Could not uninstall EBS Autoscale - unsupported init system"
exit 1
esac
# unmount the file system
umount $MOUNTPOINT
# detach and delete volumes
attached_volumes=$(
aws ec2 describe-volumes \
--region $region \
--filters "Name=tag:source-instance,Values=$instance_id" \
--query 'Volumes[].VolumeId' \
--output text
)
for volume in $attached_volumes; do
aws ec2 detach-volume --region $region --volume-id $volume
aws ec2 wait volume-available --region $region --volume-ids $volume
echo "volume $volume detached"
aws ec2 delete-volume --region $region --volume-id $volume
aws ec2 wait volume-deleted --region $region --volume-ids $volume
echo "volume $volume deleted"
done