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

switching to ynh_mongo_db__2

This commit is contained in:
yalh76 2022-06-26 20:53:36 +02:00
parent 4c6bc2cd5a
commit dfa72bfa00
4 changed files with 24 additions and 42 deletions

View file

@ -17,11 +17,8 @@ pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graph
# EXPERIMENTAL HELPERS # EXPERIMENTAL HELPERS
#================================================= #=================================================
MONGO_DEBIAN_SERVICENAME="mongodb"
MONGO_CE_SERVICENAME="mongod" MONGO_CE_SERVICENAME="mongod"
MONGO_DEBIAN_DEPENDENCIES="mongodb mongodb-server mongo-tools" MONGO_CE_DEPENDENCIES="mongodb-org mongodb-org-server mongodb-org-tools mongodb-mongosh"
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_CONFIG="/etc/mongod.conf"
MONGO_CE_REPO="deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" 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" MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-5.0.asc"
@ -110,7 +107,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()
@ -124,7 +121,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
} }
@ -324,26 +321,16 @@ ynh_mongo_remove_db() {
# #
# #
ynh_install_mongo() { ynh_install_mongo() {
ynh_script_progression --message="Installing MongoDB..." --weight=5 ynh_print_info --message="Installing MongoDB Community Edition..."
# Define Mongo Service Name
if $(dpkg --compare-versions $(cat /etc/debian_version) gt "10.0")
then
ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY" ynh_install_extra_app_dependencies --repo="$MONGO_CE_REPO" --package="$MONGO_CE_DEPENDENCIES" --key="$MONGO_CE_KEY"
MONGODB_SERVICENAME=$MONGO_CE_SERVICENAME mongodb_servicename=$MONGO_CE_SERVICENAME
else
ynh_print_info --message="Installing MongoDB Debian..."
ynh_install_app_dependencies $MONGO_DEBIAN_DEPENDENCIES
MONGODB_SERVICENAME=$MONGO_DEBIAN_SERVICENAME
fi
mongodb_servicename=$MONGODB_SERVICENAME
# 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 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 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"
# 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"
} }
# Remove MongoDB # Remove MongoDB
@ -357,15 +344,10 @@ ynh_remove_mongo() {
# Only remove the mongodb service if it is not installed. # Only remove the mongodb service if it is not installed.
if ! ynh_package_is_installed --package="mongodb*" if ! ynh_package_is_installed --package="mongodb*"
then then
ynh_script_progression --message="Removing MongoDB service..." --weight=2 ynh_print_info --message="Removing MongoDB service..."
# Define Mongo Service Name mongodb_servicename=$MONGO_CE_SERVICENAME
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=$MONGO_ROOT_PWD_FILE
fi fi
} }

View file

@ -38,6 +38,12 @@ email=$(ynh_user_get_info --username=$admin --key=mail)
#================================================= #=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1 ynh_script_progression --message="Validating installation parameters..." --weight=1
# Check machine architecture (in particular, we don't support ARM and 32bit machines)
if [ $YNH_ARCH == "i386" ] || [ $YNH_ARCH == "armel" ] || [ $YNH_ARCH == "armhf" ]
then
ynh_die --message="Sorry, but this app can only be installed on a x86, 64 bits machine :("
fi
final_path=/var/www/$app final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
@ -139,16 +145,14 @@ ynh_add_systemd_config
#================================================= #=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1 ynh_script_progression --message="Configuring mongod..." --weight=1
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf sed -i "s/^# engine:/ engine: wiredTiger/" $MONGO_CE_CONFIG
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf sed -i "s/^#replication:/replication:\n replSetName: rs01/" $MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart ynh_systemd_action --service_name=$mongodb_servicename --action=restart
sleep 10 sleep 10
ynh_mongo_exec --command="printjson(rs.initiate())" --eval
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================

View file

@ -94,16 +94,14 @@ ynh_mongo_restore_db --database="$db_name" < ./dump.bson
#================================================= #=================================================
ynh_script_progression --message="Configuring mongod..." --weight=3 ynh_script_progression --message="Configuring mongod..." --weight=3
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf sed -i "s/^# engine:/ engine: wiredTiger/" $MONGO_CE_CONFIG
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf sed -i "s/^#replication:/replication:\n replSetName: rs01/" $MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart ynh_systemd_action --service_name=$mongodb_servicename --action=restart
sleep 10 sleep 10
ynh_mongo_exec --command="printjson(rs.initiate())" --eval
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================

View file

@ -142,16 +142,14 @@ ynh_add_systemd_config
#================================================= #=================================================
ynh_script_progression --message="Configuring mongod..." --weight=1 ynh_script_progression --message="Configuring mongod..." --weight=1
sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf sed -i "s/^# engine:/ engine: wiredTiger/" $MONGO_CE_CONFIG
sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf sed -i "s/^#replication:/replication:\n replSetName: rs01/" $MONGO_CE_CONFIG
ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet
ynh_systemd_action --service_name=$mongodb_servicename --action=restart ynh_systemd_action --service_name=$mongodb_servicename --action=restart
sleep 10 sleep 10
ynh_mongo_exec --command="printjson(rs.initiate())" --eval
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================