From 6033c2aeea20c77d6ba805236fcf8d14ce04ca62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Mon, 11 Jul 2022 08:26:57 +0200 Subject: [PATCH 1/3] Add Yarn --- scripts/install | 3 ++- scripts/restore | 1 + scripts/upgrade | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 4e0c649..6d89f34 100644 --- a/scripts/install +++ b/scripts/install @@ -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 @@ -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 #================================================= diff --git a/scripts/restore b/scripts/restore index dceea60..94cb8cd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -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 diff --git a/scripts/upgrade b/scripts/upgrade index 9025833..1c4b7f7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -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 @@ -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 #================================================= From 754bc88b3a9bf04dad856ec0acb1855a2cb2952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 12 Jul 2022 09:33:07 +0200 Subject: [PATCH 2/3] Mongod 4.4 --- scripts/_common.sh | 41 +++++++++++++++++++++++++++-------------- scripts/install | 8 ++++---- scripts/remove | 8 ++++---- scripts/restore | 8 ++++---- scripts/upgrade | 8 ++++---- 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 23fd4f7..c593977 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,12 +16,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 +317,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 +358,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" diff --git a/scripts/install b/scripts/install index 6d89f34..eac10b7 100644 --- a/scripts/install +++ b/scripts/install @@ -131,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 diff --git a/scripts/remove b/scripts/remove index 1a25eba..8dcfe39 100644 --- a/scripts/remove +++ b/scripts/remove @@ -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 diff --git a/scripts/restore b/scripts/restore index 94cb8cd..c8df5a2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,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 diff --git a/scripts/upgrade b/scripts/upgrade index 1c4b7f7..4ebd4e3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -125,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 From bf79bb29f0e0747349fd99583cf6df58112a1e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 12 Jul 2022 09:34:03 +0200 Subject: [PATCH 3/3] Update _common.sh --- scripts/_common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index c593977..ce634ac 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -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 #=================================================