From be565011a21932abae53edb208bb44c257610c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:01:46 +0200 Subject: [PATCH] cleaning --- .gitignore | 3 ++ conf/systemd.service | 4 +-- manifest.toml | 3 +- scripts/_common.sh | 11 +------ scripts/backup | 25 +++++--------- scripts/change_url | 28 ++++++---------- scripts/install | 60 ++++++++++++++++------------------ scripts/remove | 43 +++++++++++-------------- scripts/restore | 63 ++++++++++++++++-------------------- scripts/upgrade | 77 +++++++++++++++++++------------------------- 10 files changed, 131 insertions(+), 186 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f144f3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.sw[op] +.DS_Store diff --git a/conf/systemd.service b/conf/systemd.service index f1072c5..6c3ce20 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,8 +8,8 @@ User=__APP__ Group=__APP__ Environment="NODE_ENV=production" WorkingDirectory=__INSTALL_DIR__/ -Environment="__YNH_NODE_LOAD_PATH__" -ExecStart=__YNH_NODE__ __INSTALL_DIR__/main.js +Environment="PATH=__PATH_WITH_NODEJS__" +ExecStart=__NODEJS_DIR__/node __INSTALL_DIR__/main.js SyslogIdentifier=__APP__ Environment=MONGO_URL=mongodb://localhost:27017/__APP__?replicaSet=rs01 Environment=MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01 diff --git a/manifest.toml b/manifest.toml index 1258a19..f1f60ab 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,8 @@ userdoc = "https://docs.rocket.chat/guides/user-guides" code = "https://github.com/RocketChat/Rocket.Chat" [integration] -yunohost = ">= 11.2.27" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64"] multi_instance = true diff --git a/scripts/_common.sh b/scripts/_common.sh index cbfb40d..cfeaf5d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,18 +1,9 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= nodejs_version=14 mongo_version=6.0 - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - diff --git a/scripts/backup b/scripts/backup index 062b1be..06650f4 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,45 +1,36 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE MONGODB DATABASE #================================================= -ynh_print_info --message="Backing up the MongoDB database..." +ynh_print_info "Backing up the MongoDB database..." -ynh_mongo_dump_db --database="$db_name" > ./dump.bson +ynh_mongo_dump_db > ./dump.bson #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 9779393..02913c8 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,49 +1,39 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS #================================================= -ynh_script_progression --message="Updating systemd service..." --weight=1 +ynh_script_progression "Updating systemd service..." -ynh_replace_string --match_string="Environment=ROOT_URL=https://$old_domain" --replace_string="Environment=ROOT_URL=https://$new_domain" --target_file="/etc/systemd/system/$app.service" +ynh_replace --match="Environment=ROOT_URL=https://$old_domain" --replace="Environment=ROOT_URL=https://$new_domain" --file="/etc/systemd/system/$app.service" systemctl daemon-reload -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=16 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" +ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index a08e12a..54b249d 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -20,39 +14,39 @@ email=$(ynh_user_get_info --username=$admin --key=mail) # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set --app=$app --key=password --value="$password" -ynh_app_setting_set --app=$app --key=email --value=$email +ynh_app_setting_set --key=password --value="$password" +ynh_app_setting_set --key=email --value=$email #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=48 +ynh_script_progression "Installing dependencies..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version +ynh_nodejs_install +ynh_hide_warnings ynh_install_mongo #================================================= # CREATE A MONGODB DATABASE #================================================= -ynh_script_progression --message="Creating a MongoDB database..." --weight=5 +ynh_script_progression "Creating a MongoDB database..." db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_app_setting_set --key=db_name --value=$db_name ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=10 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" mkdir "/tmp/ufs" -chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" chown -R $app:$app "/tmp/ufs" #================================================= @@ -60,52 +54,52 @@ chown -R $app:$app "/tmp/ufs" #================================================= # CONFIGURE MONGOD #================================================= -ynh_script_progression --message="Configuring MongoDB..." --weight=10 +ynh_script_progression "Configuring MongoDB..." -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_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf" +ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf" -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" +ynh_hide_warnings systemctl enable mongod --quiet +ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="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 +if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then + ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())" fi #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd # Use logrotate to manage application logfile(s) -ynh_use_logrotate +ynh_config_add_logrotate yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" #============================================== # INSTALL ROCKETCHAT #============================================== -ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=29 +ynh_script_progression "Building $app... (this will take some time and resources!)" pushd $install_dir/programs/server - ynh_use_nodejs - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm + + ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --unsafe-perm popd #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=29 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="SERVER RUNNING" +ynh_systemctl --service=$app --action="start" --log_path=systemd --wait_until="SERVER RUNNING" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index e9c8154..949ffb6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,72 +1,67 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression "Loading installation settings..." -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_name=$(ynh_app_setting_get --key=db_name) db_user=$db_name #================================================= # REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE SYSTEMD SERVICE +# REMOVE SYSTEMD SERVICE + #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=1 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate if [ -d "/tmp/ufs" ]; then - ynh_secure_remove --file="/tmp/ufs" + ynh_safe_rm "/tmp/ufs" fi # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx # Remove metapackage and its dependencies -ynh_remove_nodejs +ynh_nodejs_remove #================================================= # REMOVE THE MONGODB DATABASE #================================================= -ynh_script_progression --message="Removing the MongoDB database..." --weight=11 +ynh_script_progression "Removing the MongoDB database..." -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_replace --match="engine: wiredTiger" --replace="# engine:" --file="/etc/mongod.conf" +ynh_replace --match="replication:" --replace="#replication:" --file="/etc/mongod.conf" +ynh_replace --match=" replSetName: rs01" --replace="" --file="/etc/mongod.conf" -ynh_systemd_action --service_name=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --line_match="Waiting for connections" +ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="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 # Remove mongod service yunohost service remove mongod -ynh_secure_remove --file="/var/lib/mongodb" +ynh_safe_rm "/var/lib/mongodb" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 77d59f5..b50c683 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,54 +7,53 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression "Loading installation settings..." db_user=$db_name -mongo_version=$(ynh_app_setting_get --app=$app --key=mongo_version) +mongo_version=$(ynh_app_setting_get --key=mongo_version) #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" +ynh_restore "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=40 +ynh_script_progression "Reinstalling dependencies..." # Define and install dependencies -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version +ynh_nodejs_install +ynh_hide_warnings ynh_install_mongo #================================================= # RESTORE THE MONGODB DATABASE #================================================= -ynh_script_progression --message="Restoring the MongoDB database..." --weight=10 +ynh_script_progression "Restoring the MongoDB database..." -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +db_pwd=$(ynh_app_setting_get --key=db_pwd) ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mongo_restore_db --database="$db_name" < ./dump.bson +ynh_mongo_restore_db < ./dump.bson #================================================= # CONFIGURE MONGOD #================================================= -ynh_script_progression --message="Configuring mongod..." --weight=7 +ynh_script_progression "Configuring mongod..." -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_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf" +ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf" -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" +ynh_hide_warnings systemctl enable mongod --quiet +ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="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 +if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then + ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())" fi #================================================= @@ -68,30 +61,28 @@ fi #================================================= # RESTORE THE PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" +ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index c9a8b65..ea08215 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,115 +1,104 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_script_progression "Loading installation settings..." -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -password=$(ynh_app_setting_get --app=$app --key=password) -email=$(ynh_app_setting_get --app=$app --key=email) -mongo_version=$(ynh_app_setting_get --app=$app --key=mongo_version) +db_name=$(ynh_app_setting_get --key=db_name) +password=$(ynh_app_setting_get --key=password) +email=$(ynh_app_setting_get --key=email) +mongo_version=$(ynh_app_setting_get --key=mongo_version) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" +ynh_systemctl --service=$app --action="stop" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # If mongo_version doesn't exist, create it if [ -z "$mongo_version" ]; then mongo_version="$(mongod --version | grep -oP 'db version v\K.{0,3}')" - ynh_app_setting_set --app=$app --key=mongo_version --value=$mongo_version + ynh_app_setting_set --key=mongo_version --value=$mongo_version fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading source files..." --weight=22 +ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --full_replace=1 - -chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" +ynh_setup_source --dest_dir="$install_dir" --full_replace +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=7 +ynh_script_progression "Upgrading dependencies..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_exec_warn_less ynh_install_mongo --mongo_version=$mongo_version +ynh_nodejs_install +ynh_hide_warnings ynh_install_mongo -#================================================= -# SPECIFIC UPGRADE #================================================= # CONFIGURE MONGOD #================================================= -ynh_script_progression --message="Configuring mongod..." --weight=1 +ynh_script_progression "Configuring mongod..." -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_replace --match="# engine:" --replace=" engine: wiredTiger" --file="/etc/mongod.conf" +ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs01" --file="/etc/mongod.conf" -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" +ynh_hide_warnings systemctl enable mongod --quiet +ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="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 +if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then + ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())" fi #============================================== # INSTALL ROCKETCHAT #============================================== -ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=29 +ynh_script_progression "Building $app... (this will take some time and resources!)" pushd $install_dir/programs/server - ynh_use_nodejs - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --unsafe-perm + + ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --unsafe-perm popd #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_config_add_logrotate yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=19 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" +ynh_systemctl --service=$app --action="start" --log_path="systemd" --wait_until="SERVER RUNNING" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"