forked from wri/carbon-budget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2_launch_template_startup_instructions.TXT
92 lines (74 loc) · 3.82 KB
/
ec2_launch_template_startup_instructions.TXT
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
yum install -y rsync git nano htop tmux
#######################################
# Mount the ephemeral SSD storage.
# If four volumes exist, merge them and mount jointly.
# If only two volumes exist, merge them and mount jointly.
# If only one volume exists, just mount that.
# Regardless of how many volumes there are, the name of the folder they are mounted to is the same.
#######################################
# Name of the second volume (if it exists)
SSD2=nvme2n1
# Name of the fourth volume (if it exists)
SSD4=nvme4n1
# Checks if the second volume exists
CHECK2=$(lsblk -l | grep $SSD2)
# Checks if the fourth volume exists
CHECK4=$(lsblk -l | grep $SSD4)
# Checks for four volumes first, then for two volumes
if [[ $CHECK4 ]]
then
# Fourth SSD volume found
# Follows https://objectivefs.com/howto/how-to-raid-ec2-instance-stores
sudo mdadm --create --verbose /dev/md0 --level=0 --name=MY_RAID --chunk=64 --raid-devices=4 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1 #requires superuser status to use sudo, and doesn't work without sudo
sudo mkfs.ext4 -L MY_RAID /dev/md0 #requires sudo to determine file system size
sudo mkdir -p /mnt/ext # doesn’t need sudo but adding for consistency
sudo mount -t ext4 /dev/md0 /mnt/ext # needs sudo because only root can use --types option
elif [[ $CHECK2 ]]
then
# Second SSD volume found
# Follows https://objectivefs.com/howto/how-to-raid-ec2-instance-stores
sudo mdadm --create --verbose /dev/md0 --level=0 --name=MY_RAID --chunk=64 --raid-devices=2 /dev/nvme1n1 /dev/nvme2n1 #requires superuser status to use sudo, and doesn't work without sudo
sudo mkfs.ext4 -L MY_RAID /dev/md0 #requires sudo to determine file system size
sudo mkdir -p /mnt/ext # doesn’t need sudo but adding for consistency
sudo mount -t ext4 /dev/md0 /mnt/ext # needs sudo because only root can use --types option
else
# Only one SSD volume
mkfs.ext4 /dev/nvme1n1
mkdir -p /mnt/ext
mount -t ext4 /dev/nvme1n1 /mnt/ext
fi
# make temp directory for containers usage
# should be used in the Batch job definition (MountPoints)
mkdir /mnt/ext/tmp
rsync -avPHSX /tmp/ /mnt/ext/tmp/
mkdir -p /var/lib/docker
mkdir -p /mnt/ext/docker
# modify fstab to mount /tmp on the new storage.
sed -i '$ a /mnt/ext/tmp /tmp none bind 0 0' /etc/fstab
sed -i '$ a /mnt/ext/docker /var/lib/docker none bind 0 0' /etc/fstab
mount -a
# make /tmp usable by everyone
chmod 777 /mnt/ext/tmp
#######################################
# Install docker and docker-compose, per https://acloudxpert.com/how-to-install-docker-compose-on-amazon-linux-ami/
#######################################
yum install -y docker
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` | sudo tee /usr/local/bin/docker-compose > /dev/null
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
#############################
# Clone latest flux model repo to the home folder
# clone command suggested by Logan Byers. It resolves the problem of not being able to pull the repo after it was cloned, which was conflicting with not being able to SSH into the machine more than ~1 minute after it was created.
# This formulation of git clone makes ec2-user the cloner, rather than root. It's no longer necessary to change ownership (chown) of the repo because carbon-budget will already be owned by ec2-user, not root.
#############################
cd /home/ec2-user
su ec2-user -c "git clone https://github.com/wri/carbon-budget"
#######################################
# Starts the docker service
#######################################
sudo service docker start
# Replaces htop config file with my preferred configuration
mkdir -p /home/ec2-user/.config/htop/
cp /home/ec2-user/carbon-budget/htoprc /home/ec2-user/.config/htop/htoprc