1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rocketchat_ynh.git synced 2024-09-03 20:16:25 +02:00

Merge pull request #133 from YunoHost-Apps/5.0

mongodb 4.4
This commit is contained in:
Éric Gaspar 2022-07-12 14:09:25 +02:00 committed by GitHub
commit e318fe57ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 32 deletions

View file

@ -9,6 +9,8 @@ nodejs_version=14
# dependencies used by the app
pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graphicsmagick"
YNH_MONGO_VERSION=4.4
#=================================================
# PERSONAL HELPERS
#=================================================
@ -16,12 +18,12 @@ pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graph
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#!/bin/bash
MONGO_CE_SERVICENAME="mongod"
MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh"
MONGO_CE_CONFIG="/etc/mongod.conf"
MONGO_CE_REPO="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main"
MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-5.0.asc"
readonly YNH_DEFAULT_MONGO_VERSION=4.4
# Declare the actual MongoDB version to use: 4.4 ; 5.0
# A packager willing to use another version of MongoDB can override the variable into its _common.sh.
YNH_MONGO_VERSION=${YNH_MONGO_VERSION:-$YNH_DEFAULT_MONGO_VERSION}
# Execute a mongo command
#
@ -317,20 +319,33 @@ ynh_mongo_remove_db() {
# 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_script_progression --message="Installing MongoDB Community Edition..."
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY"
mongodb_servicename=$MONGO_CE_SERVICENAME
# 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}"
ynh_print_info --message="Installing MongoDB Community Edition..."
ynh_install_extra_app_dependencies --repo="deb http://repo.mongodb.org/apt/debian buster/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
systemctl is-enabled $mongodb_servicename -q || 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 enable $mongodb_servicename --quiet
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
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
@ -345,7 +360,7 @@ ynh_remove_mongo() {
if ! ynh_package_is_installed --package="mongodb*"
then
ynh_print_info --message="Removing MongoDB service..."
mongodb_servicename=$MONGO_CE_SERVICENAME
mongodb_servicename=mongod
# Remove the mongodb service
yunohost service remove $mongodb_servicename
ynh_secure_remove --file="/var/lib/mongodb"

View file

@ -80,6 +80,7 @@ ynh_script_progression --message="Installing dependencies..." --weight=20
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_mongo
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# CREATE DEDICATED USER
@ -130,11 +131,11 @@ ynh_add_nginx_config
#=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
ynh_exec_warn_less systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval
@ -147,7 +148,7 @@ ynh_script_progression --message="Building $app... (this will take some time and
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --unsafe-perm
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm
popd
#=================================================

View file

@ -56,11 +56,11 @@ ynh_remove_logrotate
#=================================================
ynh_script_progression --message="Removing the MongoDB database..." --weight=3
ynh_replace_string --match_string="engine: wiredTiger" --replace_string="# engine:" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="replication:" --replace_string="#replication:" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string=" replSetName: rs01" --replace_string="" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="engine: wiredTiger" --replace_string="# engine:" --target_file="/etc/mongod.conf"
ynh_replace_string --match_string="replication:" --replace_string="#replication:" --target_file="/etc/mongod.conf"
ynh_replace_string --match_string=" replSetName: rs01" --replace_string="" --target_file="/etc/mongod.conf"
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections"
# Remove a database if it exists, along with the associated user
ynh_mongo_remove_db --db_user=$db_user --db_name=$db_name

View file

@ -73,6 +73,7 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=1
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_mongo
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# RESTORE THE NGINX CONFIGURATION
@ -95,11 +96,11 @@ ynh_mongo_restore_db --database="$db_name" < ./dump.bson
#=================================================
ynh_script_progression --message="Configuring mongod..." --weight=3
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
ynh_exec_warn_less systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval

View file

@ -108,6 +108,7 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=7
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_exec_warn_less ynh_install_mongo
ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
#=================================================
# NGINX CONFIGURATION
@ -124,11 +125,11 @@ ynh_add_nginx_config
#=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file=$MONGO_CE_CONFIG
ynh_replace_string --match_string="# engine:" --replace_string=" engine: wiredTiger" --target_file="/etc/mongod.conf"
ynh_replace_string --match_string="#replication:" --replace_string="replication:\n replSetName: rs01" --target_file="/etc/mongod.conf"
ynh_exec_warn_less systemctl enable $MONGO_CE_SERVICENAME --quiet
ynh_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.log --line_match="Waiting for connections"
ynh_exec_warn_less systemctl enable mongod --quiet
ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections"
if ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_exec_warn_less ynh_mongo_exec --command="printjson(rs.initiate())" --eval
@ -141,7 +142,7 @@ ynh_script_progression --message="Building $app... (this will take some time and
pushd $final_path/programs/server
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH npm install --unsafe-perm
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm
popd
#=================================================