diff --git a/check_process b/check_process index bdf0be3..bfb23ce 100644 --- a/check_process +++ b/check_process @@ -2,8 +2,8 @@ ; Manifest domain="domain.tld" path="/path" - admin="john" is_public=1 + admin="john" password="1Strong-Password" ; Checks pkg_linter=1 @@ -17,12 +17,8 @@ upgrade=1 from_commit=9280c034e8843e7e69622f0daa02ee74c916faa1 backup_restore=1 multi_instance=1 + port_already_use=0 change_url=1 ;;; Options Email= Notification=none -;;; Upgrade options - ; commit=9280c034e8843e7e69622f0daa02ee74c916faa1 - name=Testing (#118) - manifest_arg=domain=DOMAIN&path=PATH&admin=USER&is_public=1&password=pass&port=666& - \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index c187424..8649aa8 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -24,4 +24,4 @@ location /.well-known/matrix/ { proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; -} \ No newline at end of file +} diff --git a/manifest.json b/manifest.json index 04db668..31da8e4 100644 --- a/manifest.json +++ b/manifest.json @@ -21,15 +21,15 @@ "name": "eric_G", "email": "" }, + "requirements": { + "yunohost": ">> 4.3.2" + }, "multi_instance": true, "services": [ "nginx" ], - "requirements": { - "yunohost": ">> 4.3.2" - }, "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -40,14 +40,6 @@ "example": "/rocketchat", "default": "/rocketchat" }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - }, { "name": "is_public", "type": "boolean", @@ -56,6 +48,14 @@ "fr": "Si cette case est cochée, Rocket.Chat sera accessible aux personnes n’ayant pas de compte. Vous pourrez changer ceci plus tard via la webadmin." }, "default": true + }, + { + "name": "admin", + "type": "user" + }, + { + "name": "password", + "type": "password" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index 3644475..6aa07b7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,11 +17,8 @@ pkg_dependencies="apt-transport-https build-essential gzip curl fontconfig graph # EXPERIMENTAL HELPERS #================================================= -MONGO_DEBIAN_SERVICENAME="mongodb" MONGO_CE_SERVICENAME="mongod" -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_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" @@ -32,14 +29,14 @@ MONGO_CE_KEY="https://www.mongodb.org/static/pgp/server-5.0.asc" # example: ynh_mongo_exec --command="db.getMongo().getDBNames().indexOf(\"wekan\")" # # usage: ynh_mongo_exec [--user=user] [--password=password] [--authenticationdatabase=authenticationdatabase] [--database=database] [--host=host] [--port=port] --command="command" [--eval] -# | arg: -u, --user= - The user name to connect as -# | arg: -p, --password= - The user password -# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to -# | arg: -d, --database= - The database to connect to -# | arg: -h, --host= - The host to connect to -# | arg: -P, --port= - The port to connect to -# | arg: -c, --command= - The command to evaluate -# | arg: -e, --eval - Evaluate instead of execute the command. +# | arg: -u, --user= - The user name to connect as +# | arg: -p, --password= - The user password +# | arg: -d, --authenticationdatabase= - The authenticationdatabase to connect to +# | arg: -d, --database= - The database to connect to +# | arg: -h, --host= - The host to connect to +# | arg: -P, --port= - The port to connect to +# | arg: -c, --command= - The command to evaluate +# | arg: -e, --eval - Evaluate instead of execute the command. # # ynh_mongo_exec() { @@ -110,7 +107,7 @@ ynh_mongo_exec() { database="" fi - mongo --quiet $user $password $authenticationdatabase $host $port </dev/null + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm install --unsafe-perm popd #================================================= @@ -135,21 +155,6 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Configuring a mongod..." --weight=1 - -sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf -sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf - -ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet -ynh_systemd_action --service_name=$mongodb_servicename --action=restart - -sleep 10 - -ynh_mongo_exec --command="printjson(rs.initiate())" --eval - #================================================= # GENERIC FINALIZATION #================================================= @@ -165,33 +170,25 @@ ynh_use_logrotate #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" - -#================================================= -# START MONGO SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a MongoDB service..." --weight=2 - -# Start a mongod service -ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet -ynh_systemd_action --service_name=$mongodb_servicename --action="restart" +yunohost service add $app --description="Team collaboration communication platform" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=2 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -sleep 60 +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="SERVER RUNNING" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -# Make app public if necessary or protect it +# Make app public if necessary if [ $is_public -eq 1 ] then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi diff --git a/scripts/remove b/scripts/remove index 1c9299b..38d4ad6 100644 --- a/scripts/remove +++ b/scripts/remove @@ -28,19 +28,13 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +# 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 then - ynh_script_progression --message="Removing $app service..." --weight=1 + ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi -if ynh_exec_warn_less yunohost service status "$mongodb_servicename" >/dev/null -then - ynh_script_progression --message="Removing $mongodb_servicename service integration..." - yunohost service remove "$mongodb_servicename" -fi - #================================================= # STOP AND REMOVE SERVICE #================================================= @@ -48,7 +42,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -ynh_remove_systemd_config --service=$mongodb_servicename #================================================= # REMOVE LOGROTATE CONFIGURATION @@ -63,19 +56,15 @@ ynh_remove_logrotate #================================================= ynh_script_progression --message="Removing the MongoDB database..." +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_systemd_action --service_name=$MONGO_CE_SERVICENAME --action=restart --log_path=/var/log/mongodb/$MONGO_CE_SERVICENAME.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 -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies -ynh_remove_nodejs -ynh_remove_mongo - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -96,6 +85,16 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=1 + +# Remove metapackage and its dependencies +ynh_remove_app_dependencies +ynh_remove_nodejs +ynh_remove_mongo + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 8162414..dceea60 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,7 @@ #!/bin/bash +#================================================= +# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -13,8 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -37,23 +38,18 @@ db_user=$db_name #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RECREATE THE DEDICATED USER #================================================= ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR @@ -74,10 +70,16 @@ chown -R $app:$app "$final_path" ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies - +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_install_mongo +ynh_exec_warn_less ynh_install_mongo + +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the NGINX web server configuration..." + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE MONGODB DATABASE @@ -89,19 +91,19 @@ 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 #================================================= -# MODIFY A CONFIG FILE +# CONFIGURE MONGOD #================================================= -ynh_script_progression --message="Configuring a mongod..." --weight=3 +ynh_script_progression --message="Configuring mongod..." --weight=3 -sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf -sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf +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_exec_warn_less systemctl enable $mongodb_servicename --quiet -ynh_systemd_action --service_name=$mongodb_servicename --action=restart +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" -sleep 10 - -ynh_mongo_exec --command="printjson(rs.initiate())" --eval +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 +fi #================================================= # RESTORE SYSTEMD @@ -123,24 +125,14 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" - -#================================================= -# START MONGO SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a MongoDB service..." --weight=2 - -# Start a mongod service -ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet -ynh_systemd_action --service_name=$mongodb_servicename --action="restart" +yunohost service add $app --description="Team collaboration communication platform" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=5 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -sleep 60 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 5c20a5b..9025833 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,6 +29,7 @@ email=$(ynh_app_setting_get --app=$app --key=email) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -40,12 +41,22 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -64,15 +75,6 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" - #================================================= # CREATE DEDICATED USER #================================================= @@ -98,6 +100,15 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +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 + #================================================= # NGINX CONFIGURATION #================================================= @@ -107,13 +118,21 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES +# SPECIFIC UPGRADE #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=7 +# CONFIGURE MONGOD +#================================================= +ynh_script_progression --message="Configuring mongod..." --weight=1 -ynh_install_app_dependencies $pkg_dependencies -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_install_mongo +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_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" + +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 +fi #============================================== # INSTALL ROCKETCHAT @@ -121,8 +140,8 @@ ynh_install_mongo ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20 pushd $final_path/programs/server - ynh_use_nodejs - ynh_exec_as $app env $ynh_node_load_PATH npm install --unsafe-perm 2>/dev/null + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH npm install --unsafe-perm popd #================================================= @@ -134,20 +153,7 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=2 ynh_add_systemd_config #================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Configuring a mongod..." --weight=1 - -sed -i "s/^# engine:/ engine: wiredTiger/" /etc/mongod.conf -sed -i "s/^#replication:/replication:\n replSetName: rs01/" /etc/mongod.conf - -ynh_exec_warn_less systemctl enable $mongodb_servicename --quiet -ynh_systemd_action --service_name=$mongodb_servicename --action="restart" - -sleep 10 - -mongo --eval "printjson(rs.initiate())" - +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= @@ -161,16 +167,14 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="Team collaboration communication platform" --log="/var/log/$app/$app.log" +yunohost service add $app --description="Team collaboration communication platform" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=10 -ynh_systemd_action --service_name=$mongodb_servicename --action="restart" --log_path="systemd" -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -sleep 60 +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="SERVER RUNNING" #================================================= # RELOAD NGINX