This commit is contained in:
Gérard Collin 2024-08-30 14:53:04 +02:00 committed by GitHub
commit 2aaa0bdc4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 77 additions and 12 deletions

View file

@ -293,6 +293,7 @@ ynh_mongo_remove_db() {
}
# Install MongoDB and integrate MongoDB service in YunoHost
# It can upgrade / downgrade the desired mongo version to ensure a compatible one is installed
#
# usage: ynh_install_mongo [--mongo_version=mongo_version]
# | arg: -m, --mongo_version= - Version of MongoDB to install
@ -310,16 +311,48 @@ ynh_install_mongo() {
ynh_print_info --message="Installing MongoDB Community Edition ..."
local mongo_debian_release=$(ynh_get_debian_release)
if [[ "$(grep '^flags' /proc/cpuinfo | uniq)" != *"avx"* && "$mongo_version" != "4.4" ]]; then
if [[ "$(grep '^flags' /proc/cpuinfo | uniq)" != *"avx"* && "$mongo_version" != "4.4" ]]; then
ynh_print_warn --message="Installing Mongo 4.4 as $mongo_version is not compatible with your cpu (see https://docs.mongodb.com/manual/administration/production-notes/#x86_64)."
mongo_version="4.4"
fi
if [[ "$mongo_version" == "4.4" ]]; then
ynh_print_warn --message="Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release."
mongo_debian_release=buster
fi
if [[ "$mongo_version" == "4.4" ]]; then
ynh_print_warn --message="Switched to buster install as Mongo 4.4 is not compatible with $mongo_debian_release."
mongo_debian_release=buster
fi
ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" --package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" --key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc"
if [[ "$mongo_debian_release" == "bookworm" && "$mongo_version" != "7."* ]]; then
ynh_print_warn --message="Switched to Mongo v7 as $mongo_version is not compatible with $mongo_debian_release"
mongo_version = "7.0"
fi
# Check if MongoDB is already installed
local install_package=true
local current_version=$(ynh_package_version --package="mongodb-org-server")
# Focus only the major, minor versions
current_version=$(cut -c 1-3 <<< "$current_version")
if [[ "a$current_version" != "a" ]]; then
if (( $(bc <<< "$current_version < $mongo_version") )); then
if (( $(bc <<< "scale = 0 ; x = $mongo_version / 1 - $current_version / 1; x > 1.0" ))); then
# Mongo only support upgrading a major version to another
ynh_print_err --message="Upgrading Mongo from version $current_version to $mongo_version is not supported"
install_package=false
else
ynh_print_info --message="Upgrading Mongo from version $current_version to $mongo_version"
fi
else
if (( $(bc <<< "$current_version >= $mongo_version") )); then
ynh_print_warn --message="Mongo version $current_version is already installed and will be kept instead of requested version $mongo_version"
install_package=false
fi
fi
fi
if [[ "$install_package" = true ]]; then
ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" --package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" --key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc"
fi
mongodb_servicename=mongod
# Make sure MongoDB is started and enabled

View file

@ -214,6 +214,7 @@ ynh_mongo_remove_db() {
}
# Install MongoDB and integrate MongoDB service in YunoHost
# It can upgrade / downgrade the desired mongo version to ensure a compatible one is installed
#
# The installed version is defined by $mongo_version which should be defined as global prior to calling this helper
#
@ -235,22 +236,53 @@ ynh_install_mongo() {
mongo_debian_release=buster
fi
if [[ "$mongo_debian_release" == "bookworm" && "$mongo_version" != "7."* ]]; then
ynh_print_warn --message="Switched to Mongo v7 as $mongo_version is not compatible with $mongo_debian_release"
mongo_version = "7.0"
fi
# Check if MongoDB is already installed
local install_package=true
local current_version=$(ynh_package_version --package="mongodb-org-server")
# Focus only the major, minor versions
current_version=$(cut -c 1-3 <<< "$current_version")
if [[ "a$current_version" != "a" ]]; then
if (( $(bc <<< "$current_version < $mongo_version") )); then
if (( $(bc <<< "scale = 0 ; x = $mongo_version / 1 - $current_version / 1; x > 1.0" ))); then
# Mongo only support upgrading a major version to another
ynh_print_err --message="Upgrading Mongo from version $current_version to $mongo_version is not supported"
install_package=false
else
ynh_print_info --message="Upgrading Mongo from version $current_version to $mongo_version"
fi
else
if (( $(bc <<< "$current_version >= $mongo_version") )); then
ynh_print_warn --message="Mongo version $current_version is already installed and will be kept instead of requested version $mongo_version"
install_package=false
fi
fi
fi
if [[ "$install_package" = true ]]; then
ynh_apt_install_dependencies_from_extra_repository \
--repo="deb http://repo.mongodb.org/apt/debian $mongo_debian_release/mongodb-org/$mongo_version main" \
--package="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh" \
--key="https://www.mongodb.org/static/pgp/server-$mongo_version.asc"
mongodb_servicename=mongod
fi
mongodb_servicename=mongod
# Make sure MongoDB is started and enabled
systemctl enable $mongodb_servicename --quiet
systemctl daemon-reload --quiet
ynh_systemctl --service=$mongodb_servicename --action=restart --wait_until="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
systemctl enable $mongodb_servicename --quiet
systemctl daemon-reload --quiet
ynh_systemctl --service=$mongodb_servicename --action=restart --wait_until="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
# Integrate MongoDB service in YunoHost
yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log"
yunohost service add $mongodb_servicename --description="MongoDB daemon" --log="/var/log/mongodb/$mongodb_servicename.log"
# Store mongo_version into the config of this app
ynh_app_setting_set --key=mongo_version --value=$mongo_version
ynh_app_setting_set --key=mongo_version --value=$mongo_version
}
# Remove MongoDB