This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
mongodb-instance-template.jinja
87 lines (70 loc) · 3.23 KB
/
mongodb-instance-template.jinja
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
# Copyright 2016 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
resources:
- type: compute.v1.disk
name: {{ env["name"] }}-data
properties:
zone: {{ properties["zone"] }}
sizeGb: 500
type: projects/{{ env["project"] }}/zones/{{ properties["zone"] }}/diskTypes/pd-ssd
- type: compute.v1.instance
name: {{ env["name"] }}
properties:
zone: {{ properties["zone"] }}
machineType: zones/{{ properties["zone"] }}/machineTypes/{{ properties["machineType"] }}
disks:
- deviceName: boot
type: PERSISTENT
boot: true
autoDelete: true
initializeParams:
sourceImage: https://www.googleapis.com/compute/v1/projects/click-to-deploy-images/global/images/family/mongodb-cloud-manager-bootstrap
- deviceName: {{ env["name"] }}-data
type: PERSISTENT
autoDelete: false
source: $(ref.{{ env["name"] }}-data.selfLink)
networkInterfaces:
- network: global/networks/default
accessConfigs:
- name: External NAT
type: ONE_TO_ONE_NAT
metadata:
items:
- key: startup-script
value: |
#!/bin/bash
# change to /root
cd /root
# set transparent_hugepage/enabled and transparent_hugepage/defrag to never
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
# download the latest mongodb cloud manager agent
curl -OL https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb
# install the mongodb cloud manager agent
dpkg -i mongodb-mms-automation-agent-manager_latest_amd64.ubuntu1604.deb
# configure the agent with cloud manager mmsGroupId and mmsApiKey
sed -i '/mmsGroupId/c\mmsGroupId={{ properties["mmsGroupId"] }}' /etc/mongodb-mms/automation-agent.config
sed -i '/mmsApiKey/c\mmsApiKey={{ properties["mmsApiKey"] }}' /etc/mongodb-mms/automation-agent.config
# create filesystem on persistent storage
mkfs.xfs -f /dev/disk/by-id/google-{{ env["name"] }}-data
# create mongodb data directory
mkdir /data
# mount persistent disk
mount -o discard,defaults /dev/disk/by-id/google-{{ env["name"] }}-data /data
# set data directory ownership
chown mongodb:mongodb /data
# add an entry to /etc/fstab for persistent disk
echo '/dev/disk/by-id/google-{{ env["name"] }}-data /data xfs discard,defaults 1 1' | tee -a /etc/fstab
# start the mongodb cloud manager agent
systemctl start mongodb-mms-automation-agent.service
tags:
items:
- mongodb-cloud-manager-bootstrap