This repository was archived by the owner on Dec 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathec2-init-services.sh
More file actions
64 lines (54 loc) · 1.88 KB
/
ec2-init-services.sh
File metadata and controls
64 lines (54 loc) · 1.88 KB
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
#! /bin/bash
set -x
#
# Init script for private cloud EC2 services instance.
#
# Mount the docker EBS volume
echo "UUID=$(blkid -s UUID -o value /dev/nvme1n1) /docker xfs defaults 0 2" >> /etc/fstab
mount /docker
systemctl restart docker
# Mount the data EBS volume
# First, wait for volume attachment
until lsblk /dev/nvme2n1 &>/dev/null; do sleep 1; done
mkdir /data
if file -s /dev/nvme2n1 | grep ": data"; then
mkfs -t xfs /dev/nvme2n1;
fi
echo "UUID=$(blkid -s UUID -o value /dev/nvme2n1) /data xfs defaults 0 2" >> /etc/fstab
mount /data
# Set es container user as elasticsearch dir owner if exists
mkdir -p /data/elasticsearch && chown -R 1000 /data/elasticsearch || true
# Mount EFS
{{#if capsuleCacheEfsId}}
mkdir /capsule-cache
echo "{{capsuleCacheEfsId}}:/ /capsule-cache efs _netdev,tls,iam 0 0" >> /etc/fstab
until mount /capsule-cache; do sleep 1; done
{{/if}}
mkdir /datasets
echo "{{datasetsEfsId}}:/ /datasets efs _netdev,tls,iam 0 0" >> /etc/fstab
until mount /datasets; do sleep 1; done
# Set the config bucket configuration
echo 'CONFIG_BUCKET="{{configBucketName}}"' >> /etc/default/codeocean
# Set the pulumi stack name
echo 'PULUMI_STACK_NAME="{{pulumiStackName}}"' >> /etc/default/codeocean
systemctl restart codeocean
# Set cloudwatch logs agent conf
cat << EOF > /tmp/cloudwatch-logs-config.json
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/messages",
"log_group_name": "/codeocean/{{pulumiStackName}}/instances"
}
]
}
},
"log_stream_name": "services/{instance_id}/{ip_address}"
}
}
EOF
# Sending /var/log/messages to cloud watch logs
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -s -c file:/tmp/cloudwatch-logs-config.json