1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/overleaf_ynh.git synced 2024-09-03 19:56:27 +02:00

Update mongodb helper

This commit is contained in:
Thomas 2023-11-20 10:19:31 +01:00 committed by GitHub
parent 049d94ec34
commit b062426228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,16 +14,10 @@ nodejs_version=18
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================
#!/bin/bash readonly YNH_DEFAULT_MONGO_VERSION=4.4
# Declare the actual MongoDB version to use: 4.4 ; 5.0 ; 6.0
MONGO_DEBIAN_SERVICENAME="mongodb" # A packager willing to use another version of MongoDB can override the variable into its _common.sh.
MONGO_CE_SERVICENAME="mongod" YNH_MONGO_VERSION=${YNH_MONGO_VERSION:-$YNH_DEFAULT_MONGO_VERSION}
MONGO_DEBIAN_DEPENDENCIES="mongodb mongodb-server mongo-tools"
MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools"
MONGO_DEBIAN_CONFIG="/etc/mongodb.conf"
MONGO_CE_CONFIG="/etc/mongod.conf"
MONGO_CE_REPO="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main"
MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-4.4.asc"
# Execute a mongo command # Execute a mongo command
# #
@ -109,7 +103,7 @@ ynh_mongo_exec() {
database="" database=""
fi fi
mongo --quiet $user $password $authenticationdatabase $host $port <<EOF mongosh --quiet --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port <<EOF
$database $database
${command} ${command}
quit() quit()
@ -123,7 +117,7 @@ EOF
database="" database=""
fi fi
mongo --quiet $database $user $password $authenticationdatabase $host $port --eval="$command" mongosh --quiet $database --username $user --password $password --authenticationDatabase $authenticationdatabase --host $host --port $port --eval="$command"
fi fi
} }
@ -319,31 +313,44 @@ ynh_mongo_remove_db() {
# Install MongoDB and integrate MongoDB service in YunoHost # Install MongoDB and integrate MongoDB service in YunoHost
# #
# usage: ynh_install_mongo # usage: ynh_install_mongo [--mongo_version=mongo_version]
# | arg: -m, --mongo_version= - Version of MongoDB to install
# #
# #
ynh_install_mongo() { ynh_install_mongo() {
ynh_print_info --message="Installing MongoDB..." # Declare an array to define the options of this helper.
local legacy_args=m
local -A args_array=([m]=mongo_version=)
local mongo_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
mongo_version="${mongo_version:-$YNH_MONGO_VERSION}"
# Define Mongo Service Name
if dpkg --compare-versions $(cat /etc/debian_version) ge 10.0
then
ynh_print_info --message="Installing MongoDB Community Edition ..." ynh_print_info --message="Installing MongoDB Community Edition ..."
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY" local mongo_debian_release=$(ynh_get_debian_release)
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else if [[ $(cat /proc/cpuinfo) != *"avx"* && "$mongo_version" != "4.4" ]]; then
ynh_print_info --message="Installing MongoDB Debian..." 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)."
ynh_install_app_dependencies $MONGO_DEBIAN_DEPENDENCIES mongo_version="4.4"
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi fi
mongodb_servicename=$MONGODB_SERVICENAME if [[ "$mongo_version" == "4.4" && "$mongo_debian_release" != "buster" ]]; 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"
mongodb_servicename=mongod
# Make sure MongoDB is started and enabled # Make sure MongoDB is started and enabled
systemctl is-enabled $MONGODB_SERVICENAME -q || systemctl enable $MONGODB_SERVICENAME --quiet systemctl enable $mongodb_servicename --quiet
systemctl is-active $MONGODB_SERVICENAME -q || ynh_systemd_action --service_name=$MONGODB_SERVICENAME --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$MONGODB_SERVICENAME.log" systemctl daemon-reload --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart --line_match="aiting for connections" --log_path="/var/log/mongodb/$mongodb_servicename.log"
# Integrate MongoDB service in YunoHost # 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 --app=$app --key=mongo_version --value=$mongo_version
} }
# Remove MongoDB # Remove MongoDB
@ -358,19 +365,14 @@ ynh_remove_mongo() {
if ! ynh_package_is_installed --package="mongodb*" if ! ynh_package_is_installed --package="mongodb*"
then then
ynh_print_info --message="Removing MongoDB service..." ynh_print_info --message="Removing MongoDB service..."
# Define Mongo Service Name mongodb_servicename=mongod
if [ "$(lsb_release --codename --short)" = "buster" ]; then
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME
else
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
# Remove the mongodb service # Remove the mongodb service
yunohost service remove $MONGODB_SERVICENAME yunohost service remove $mongodb_servicename
# ynh_secure_remove --file=$MONGO_ROOT_PWD_FILE ynh_secure_remove --file="/var/lib/mongodb"
ynh_secure_remove --file="/var/log/mongodb"
fi fi
} }
#================================================= #=================================================
# FUTURE OFFICIAL HELPERS # FUTURE OFFICIAL HELPERS
#================================================= #=================================================