Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodejs 20 and mongodb 7 #4936

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

services:
mongodb:
image: mongo:6.0
image: mongo:7.0
options: >-
--health-cmd mongosh
--health-interval 10s
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:

services:
mongodb:
image: mongo:6.0
image: mongo:7.0
options: >-
--health-cmd mongosh
--health-interval 10s
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:

services:
mongodb:
image: mongo:6.0
image: mongo:7.0
options: >-
--health-cmd mongosh
--health-interval 10s
Expand Down Expand Up @@ -221,7 +221,7 @@ jobs:

services:
mongodb:
image: mongo:6.0
image: mongo:7.0
options: >-
--health-cmd mongosh
--health-interval 10s
Expand Down
4 changes: 2 additions & 2 deletions api/api.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ plugins.connectToAllDatabases().then(function() {
console.log("Successfully stored batch state");
}
catch (ex) {
console.log("Could not store batch state");
console.log("Could not store batch state", ex);
}
process.exit(code);
process.exit(typeof code === "number" ? code : 1);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion bin/countly.install_rhel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sudo dnf install -y alsa-lib.x86_64 atk.x86_64 cups-libs.x86_64 gtk3.x86_64 libX
sudo dnf update -y nss

#install nodejs
sudo dnf module install -y nodejs:18/common
sudo dnf module install -y nodejs:20/common

set +e
NODE_JS_CMD=$(which nodejs)
Expand Down
2 changes: 1 addition & 1 deletion bin/countly.install_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=18
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
Expand Down
10 changes: 5 additions & 5 deletions bin/scripts/mongodb.install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ if [ $# -eq 0 ]; then
exit 1
fi

echo "[mongodb-org-6.0]
echo "[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/6.0/x86_64/
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc" > /etc/yum.repos.d/mongodb-org-6.0.repo
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc" > /etc/yum.repos.d/mongodb-org-7.0.repo

yum install -y mongodb-org
elif [ -f /etc/lsb-release ]; then
Expand All @@ -359,8 +359,8 @@ gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc" > /etc/yum.repos.d/mon
exit 1
fi

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu ${UBUNTU_RELEASE}/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list ;
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
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 ;
apt-get update
DEBIAN_FRONTEND="noninteractive" apt-get install -y mongodb-org || (echo "Failed to install mongodb." ; exit)
else
Expand Down
131 changes: 131 additions & 0 deletions bin/upgrade/DEV/upgrade.mongo.70.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/bin/bash

#we have to check since we cannot continue unless
if [ -f /etc/redhat-release ]; then
CENTOS_MAJOR="$(cat /etc/redhat-release |awk -F'[^0-9]+' '{ print $2 }')"

if [[ "$CENTOS_MAJOR" != "8" && "$CENTOS_MAJOR" != "9" ]]; then
echo "Unsupported OS version, only support CentOS/RHEL 8 and 9."
exit 1
fi
fi

if [ -f /etc/lsb-release ]; then
UBUNTU_YEAR="$(lsb_release -sr | cut -d '.' -f 1)";
UBUNTU_RELEASE="$(lsb_release -cs)"

if [[ "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" ]]; then
echo "Unsupported OS version, only support Ubuntu 20 and 22."
exit 1
fi
fi

#check if authentication is required
isAuth=0
if grep -Eq '^\s*authorization\s*:\s*enabled' /etc/mongod.conf; then
isAuth=1
fi

#check if we have previous upgrade needed
FEATVER=$(mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ).featureCompatibilityVersion)" --quiet);
VER=$(mongod -version | grep "db version" | cut -d ' ' -f 3 | cut -d 'v' -f 2)

if [ "$isAuth" -eq "1" ]; then
echo "Since authentication is enabled, we cannot verify if you need to run this upgrade script"
echo ""
echo "Please run this command with authentication parameters:"
echo ""
echo "mongosh admin --eval \"db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 } )\""
echo ""
echo "and continue only if \"featureCompatibilityVersion\" is 6.0 "
echo ""
read -r -p "Is your \"featureCompatibilityVersion\" version is 6.0? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Continue upgrading"
else
echo "Stopping script"
exit 0;
fi

fi

if [ -x "$(command -v mongosh)" ]; then
if echo "$VER" | grep -q -i "7.0" ; then
if echo "$FEATVER" | grep -q -i "6.0" ; then
echo "run this command to upgrade to 7.0";
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"7.0\\\" } )\"";
else
echo "We already have version 7.0";
fi
exit 0;
elif echo "$VER" | grep -q -i "6.0" ; then
echo "Upgrading to MongoDB 7.0";
else
echo "Unsupported MongodB version $VER";
echo "Upgrade to MongoDB 6.0 first and then run this script";
exit 1;
fi

if [ -f /etc/redhat-release ]; then
#backup of systemd unit file and mongod.conf file
\cp /usr/lib/systemd/system/mongod.service /usr/lib/systemd/system/mongod.service.bak
\cp -f /etc/mongod.conf /etc/mongod.conf.bak
#uninstall mognodb
yum erase -y mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
fi

if [ -f /etc/lsb-release ]; then
#uninstall mognodb
apt-get remove -y mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
fi
fi

if [ -f /etc/redhat-release ]; then
#install latest mongodb
#select source based on release
echo "[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/${CENTOS_MAJOR}/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc" > /etc/yum.repos.d/mongodb-org-7.0.repo

yum install -y mongodb-org
\cp -f /etc/mongod.conf.bak /etc/mongod.conf
fi

if [ -f /etc/lsb-release ]; then
#install latest mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -

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 ;
apt-get update
#install mongodb
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y mongodb-org --force-yes || (echo "Failed to install mongodb." ; exit)
fi

if [ -f /etc/redhat-release ]; then
#Restoring systemd unit file
\cp -f /usr/lib/systemd/system/mongod.service.bak /usr/lib/systemd/system/mongod.service
systemctl daemon-reload
fi

#mongodb might need to be started
systemctl restart mongod || echo "mongodb systemctl job does not exist"

#nc not available on latest centos
#until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done
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++;}'

if [ "$isAuth" -eq "1" ]; then
echo "run this command with authentication to upgrade to 7.0"
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"7.0\\\" } )\""
elif ! mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ))" ; then
echo "Could not connect to MongodB, run this command when Mongo is up and running"
echo "mongosh admin --eval \"db.adminCommand( { setFeatureCompatibilityVersion: \\\"7.0\\\" } )\""
else
mongosh admin --eval "printjson(db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } ))"
mongosh admin --eval "db.adminCommand( { setFeatureCompatibilityVersion: \"7.0\" } )"
echo "Finished upgrading script"
fi
49 changes: 49 additions & 0 deletions bin/upgrade/DEV/upgrade.nodejs.20.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

#we have to check since we cannot continue unless
if [ -f /etc/redhat-release ]; then
CENTOS_MAJOR="$(cat /etc/redhat-release |awk -F'[^0-9]+' '{ print $2 }')"

if [[ "$CENTOS_MAJOR" != "8" && "$CENTOS_MAJOR" != "9" ]]; then
echo "Unsupported OS version, only support CentOS/RHEL 8 and 9."
exit 1
fi
fi

if [ -f /etc/lsb-release ]; then
UBUNTU_YEAR="$(lsb_release -sr | cut -d '.' -f 1)";

if [[ "$UBUNTU_YEAR" != "20" && "$UBUNTU_YEAR" != "22" ]]; then
echo "Unsupported OS version, only support Ubuntu 20 and 22."
exit 1
fi
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"

sudo npm install -g npm@latest;

if [[ -f /usr/local/bin/npm && -f /usr/bin/npm ]]; then
rm /usr/local/bin/npm
ln -s /usr/bin/npm /usr/local/bin/npm
fi

#upgrade nodejs
if [ -f /etc/redhat-release ]; then
curl -sL https://rpm.nodesource.com/setup_20.x | bash -
yum clean all
yum remove -y nodejs
yum install -y nodejs
fi

if [ -f /etc/lsb-release ]; then
wget -qO- https://deb.nodesource.com/setup_20.x | bash -
apt-get -y --force-yes install nodejs || (echo "Failed to install nodejs." ; exit)
fi

#remove previous dependencies, as they need to be rebuild for new nodejs version
rm -rf "$DIR/../node_modules"
rm -rf "$DIR/../plugins/hooks/node_modules"

(cd "$DIR/.." && sudo npm install --unsafe-perm && sudo npm install argon2 --build-from-source)
(cd "$DIR/../plugins/hooks" && sudo npm install --unsafe-perm)
Loading