Skip to content

Commit 79dcfcc

Browse files
Merge pull request #5633 from Countly/mongodb8
MongoDB 8
2 parents f2b4d27 + e57b96a commit 79dcfcc

File tree

7 files changed

+177
-461
lines changed

7 files changed

+177
-461
lines changed

.github/workflows/main.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464

6565
services:
6666
mongodb:
67-
image: mongo:7.0
67+
image: mongo:8.0
6868
options: >-
6969
--health-cmd mongosh
7070
--health-interval 10s
@@ -121,7 +121,7 @@ jobs:
121121

122122
services:
123123
mongodb:
124-
image: mongo:7.0
124+
image: mongo:8.0
125125
options: >-
126126
--health-cmd mongosh
127127
--health-interval 10s
@@ -173,7 +173,7 @@ jobs:
173173

174174
services:
175175
mongodb:
176-
image: mongo:7.0
176+
image: mongo:8.0
177177
options: >-
178178
--health-cmd mongosh
179179
--health-interval 10s
@@ -231,7 +231,7 @@ jobs:
231231

232232
services:
233233
mongodb:
234-
image: mongo:7.0
234+
image: mongo:8.0
235235
options: >-
236236
--health-cmd mongosh
237237
--health-interval 10s
@@ -313,7 +313,7 @@ jobs:
313313

314314
services:
315315
mongodb:
316-
image: mongo:6.0
316+
image: mongo:8.0
317317
options: >-
318318
--health-cmd mongosh
319319
--health-interval 10s

bin/scripts/mongodb.install.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ if [ $# -eq 0 ]; then
341341
exit 1
342342
fi
343343

344-
echo "[mongodb-org-7.0]
344+
echo "[mongodb-org-8.0]
345345
name=MongoDB Repository
346-
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/7.0/x86_64/
346+
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/8.0/x86_64/
347347
gpgcheck=1
348348
enabled=1
349-
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc" > /etc/yum.repos.d/mongodb-org-7.0.repo
349+
gpgkey=https://pgp.mongodb.com/server-8.0.asc" > /etc/yum.repos.d/mongodb-org-8.0.repo
350350

351351
yum install -y mongodb-org
352352
elif [ -f /etc/lsb-release ]; then
@@ -359,12 +359,12 @@ gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc" > /etc/yum.repos.d/mon
359359
exit 1
360360
fi
361361

362-
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
363-
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/7.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list ;
362+
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
363+
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
364364
apt-get update
365365
DEBIAN_FRONTEND="noninteractive" apt-get install -y mongodb-org || (echo "Failed to install mongodb." ; exit)
366366
else
367-
echo "Unsupported OS or version, only CentOS/RHEL 8 or 9 and Ubuntu 20 or 22."
367+
echo "Unsupported OS or version, only CentOS/RHEL 8 or 9 and Ubuntu 20 or 22 or 24."
368368
exit 1
369369
fi
370370

bin/upgrade/DEV/upgrade.mongo.80.sh

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
#we have to check since we cannot continue unless
4+
if [ -f /etc/redhat-release ]; then
5+
CENTOS_MAJOR="$(cat /etc/redhat-release |awk -F'[^0-9]+' '{ print $2 }')"
6+
7+
if [[ "$CENTOS_MAJOR" != "8" && "$CENTOS_MAJOR" != "9" ]]; then
8+
echo "Unsupported OS version, only support CentOS/RHEL 8 and 9."
9+
exit 1
10+
fi
11+
fi
12+
13+
if [ -f /etc/lsb-release ]; then
14+
UBUNTU_YEAR="$(lsb_release -sr | cut -d '.' -f 1)";
15+
UBUNTU_RELEASE="$(lsb_release -cs)"
16+
17+
if [[ "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" && "$UBUNTU_YEAR" != "24" ]]; then
18+
echo "Unsupported OS version, only support Ubuntu 20 and 22 and 24."
19+
exit 1
20+
fi
21+
fi
22+
23+
#check if authentication is required
24+
isAuth=0
25+
if grep -Eq '^\s*authorization\s*:\s*enabled' /etc/mongod.conf; then
26+
isAuth=1
27+
fi
28+
29+
#check if we have previous upgrade needed
30+
FEATVER=$(mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ).featureCompatibilityVersion)" --quiet);
31+
VER=$(mongod -version | grep "db version" | cut -d ' ' -f 3 | cut -d 'v' -f 2)
32+
33+
if [ "$isAuth" -eq "1" ]; then
34+
echo "Since authentication is enabled, we cannot verify if you need to run this upgrade script"
35+
echo ""
36+
echo "Please run this command with authentication parameters:"
37+
echo ""
38+
echo "mongosh admin --eval \"db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 } )\""
39+
echo ""
40+
echo "and continue only if \"featureCompatibilityVersion\" is 7.0 "
41+
echo ""
42+
read -r -p "Is your \"featureCompatibilityVersion\" version is 7.0? [y/N] " response
43+
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
44+
then
45+
echo "Continue upgrading"
46+
else
47+
echo "Stopping script"
48+
exit 0;
49+
fi
50+
51+
fi
52+
53+
if [ -x "$(command -v mongosh)" ]; then
54+
if echo "$VER" | grep -q -i "8.0" ; then
55+
if echo "$FEATVER" | grep -q -i "7.0" ; then
56+
echo "run this command to upgrade to 8.0";
57+
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"8.0\\\", confirm: true } )\"";
58+
else
59+
echo "We already have version 8.0";
60+
fi
61+
exit 0;
62+
elif echo "$VER" | grep -q -i "7.0" ; then
63+
if echo "$FEATVER" | grep -q -i "6.0" ; then
64+
echo "run this command before upgrading to 8.0 and rerunning this script";
65+
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"7.0\\\", confirm: true } )\"";
66+
exit 0;
67+
else
68+
echo "Upgrading to MongoDB 8.0";
69+
fi
70+
else
71+
echo "Unsupported MongodB version $VER";
72+
echo "Upgrade to MongoDB 7.0 first and then run this script";
73+
exit 1;
74+
fi
75+
76+
if [ -f /etc/redhat-release ]; then
77+
#backup of systemd unit file and mongod.conf file
78+
\cp /usr/lib/systemd/system/mongod.service /usr/lib/systemd/system/mongod.service.bak
79+
\cp -f /etc/mongod.conf /etc/mongod.conf.bak
80+
#uninstall mognodb
81+
yum erase -y mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
82+
fi
83+
84+
if [ -f /etc/lsb-release ]; then
85+
#uninstall mognodb
86+
apt-get remove -y mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
87+
fi
88+
fi
89+
90+
if [ -f /etc/redhat-release ]; then
91+
#install latest mongodb
92+
#select source based on release
93+
echo "[mongodb-org-8.0]
94+
name=MongoDB Repository
95+
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/8.0/x86_64/
96+
gpgcheck=1
97+
enabled=1
98+
gpgkey=https://pgp.mongodb.com/server-8.0.asc" > /etc/yum.repos.d/mongodb-org-8.0.repo
99+
100+
yum install -y mongodb-org
101+
\cp -f /etc/mongod.conf.bak /etc/mongod.conf
102+
fi
103+
104+
if [ -f /etc/lsb-release ]; then
105+
#install latest mongodb
106+
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
107+
108+
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
109+
apt-get update
110+
#install mongodb
111+
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y mongodb-org --force-yes || (echo "Failed to install mongodb." ; exit)
112+
fi
113+
114+
if [ -f /etc/redhat-release ]; then
115+
#Restoring systemd unit file
116+
\cp -f /usr/lib/systemd/system/mongod.service.bak /usr/lib/systemd/system/mongod.service
117+
systemctl daemon-reload
118+
fi
119+
120+
#mongodb might need to be started
121+
systemctl restart mongod || echo "mongodb systemctl job does not exist"
122+
123+
#nc not available on latest centos
124+
#until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done
125+
mongosh --nodb --eval 'var conn; print("Waiting for MongoDB connection on port 27017. Exit if incorrect port"); var cnt = 0; while(!conn && cnt <= 300){try{conn = new Mongo("localhost:27017");}catch(Error){}sleep(1000);cnt++;}'
126+
127+
if [ "$isAuth" -eq "1" ]; then
128+
echo "run this command with authentication to upgrade to 8.0"
129+
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\8.0\\\", confirm: true } )\""
130+
elif ! mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ))" ; then
131+
echo "Could not connect to MongodB, run this command when Mongo is up and running"
132+
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"8.0\\\", confirm: true } )\""
133+
else
134+
mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ))"
135+
mongosh admin --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"8.0\", confirm: true } )"
136+
echo "Finished upgrading script"
137+
fi

0 commit comments

Comments
 (0)