-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path020-mongo
More file actions
executable file
·84 lines (59 loc) · 2.03 KB
/
020-mongo
File metadata and controls
executable file
·84 lines (59 loc) · 2.03 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Install MongoDB
source common
# Mongo versions to attempt
VERSION_SERVER=7.0.5
VERSION_SHELL=2.1.1
VERSION_COMPASS=1.41.0
INIT apt-remove --lazy --header "Remove existing Mongo installs" 'mongodb*'
INIT apt-install-url \
"https://repo.mongodb.org/apt/ubuntu/dists/jammy/mongodb-org/7.0/multiverse/binary-amd64/mongodb-org-server_${VERSION_SERVER}_amd64.deb" \
"https://downloads.mongodb.com/compass/mongodb-mongosh_${VERSION_SHELL}_amd64.deb" \
"https://downloads.mongodb.com/compass/mongodb-compass_${VERSION_COMPASS}_amd64.deb" \
"https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2004-x86_64-100.5.1.deb" \
INIT status "Cleaning up APT dependencies"
sudo apt install -fy
if [ -f "/etc/logrotate.d/mongodb" ]; then
INIT skip "Setup Logrotate (already exists)"
else
INIT status "Setup Logrotate for Mongo"
INIT apt-install --lazy logrotate
# Add logRotate option to reopen on rotate
INIT snap-install yq
yq '.systemLog.logRotate="reopen"' </etc/mongod.conf | sudo sponge /etc/mongod.conf
INIT file-set /etc/logrotate.d/mongodb <<EOF
/var/log/mongodb/mongod.log {
daily
size 128M
rotate 7
missingok
nocompress
notifempty
create 600 mongodb mongodb
sharedscripts
postrotate
/usr/bin/pkill -SIGUSR1 mongod
endscript
}
EOF
sudo systemctl restart logrotate
fi
INIT status "Disable Kernel hugepages"
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled >/dev/null
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag >/dev/null
INIT status "Disable Kernel hugepages (install into rc.local)"
INIT file-set /etc/rc.local <<EOF
#!/bin/sh -e
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
exit 0
EOF
sudo chmod +x /etc/rc.local
INIT status "Enable Mongo at startup"
sudo systemctl enable mongod
INIT status "Start Mongo service"
sudo systemctl start mongod
INIT status "Wait for Mongo service to come up"
sleep 3
INIT status "Disable Mongo monitoring"
/usr/bin/mongosh --eval 'db.disableFreeMonitoring()'