diff --git a/check_process b/check_process index b0ffe67..4206e96 100644 --- a/check_process +++ b/check_process @@ -8,7 +8,7 @@ password="password" ; Checks pkg_linter=1 - setup_sub_dir=0 + setup_sub_dir=1 setup_root=1 setup_nourl=0 setup_private=1 @@ -16,7 +16,7 @@ upgrade=1 #upgrade=1 from_commit=CommitHash backup_restore=1 - multi_instance=0 + multi_instance=1 change_url=1 ;;; Options Email= diff --git a/conf/config.json b/conf/config.json index 8ad5f72..a9d7d04 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,12 +1,21 @@ { - "url": "http://127.0.0.1:__PORT__", + "url": "https://__DOMAIN____PATH__", "secret": "__SECRET__", + "database": "postgres", "port": "__PORT__", - "database": "redis", + "trust_proxy": true, + "isCluster": false, "redis": { "host": "127.0.0.1", "port": "6379", "password": "", "database": "__REDIS_DB__" + }, + "postgres": { + "host": "localhost", + "port": "5432", + "username": "__DB_NAME__", + "password": "__DB_PWD__", + "database": "__DB_NAME__" } } diff --git a/conf/nginx.conf b/conf/nginx.conf index 689aaaa..0a6c5ae 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,5 @@ -location / { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { # Force usage of https if ($scheme = http) { diff --git a/manifest.json b/manifest.json index 4a045fe..a342dd3 100644 --- a/manifest.json +++ b/manifest.json @@ -24,7 +24,7 @@ "requirements": { "yunohost": ">> 4.2.4" }, - "multi_instance": false, + "multi_instance": true, "services": [ "nginx" ], @@ -35,6 +35,12 @@ "type": "domain", "example": "example.com" }, + { + "name": "path", + "type": "path", + "example": "/forum", + "default": "/forum" + }, { "name": "admin", "type": "user", diff --git a/scripts/_common.sh b/scripts/_common.sh index 88af633..3e71c50 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="redis-server" +pkg_dependencies="postgresql redis-server" nodejs_version=14 diff --git a/scripts/backup b/scripts/backup index bfc28b4..87f7c39 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,6 +30,10 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -62,6 +66,13 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# BACKUP THE POSTGRESQL DATABASE +#================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." + +ynh_psql_dump_db --database="$db_name" > db.sql + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index fad867c..c8096c6 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -107,7 +107,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 8ee67a3..7dd1e7d 100644 --- a/scripts/install +++ b/scripts/install @@ -22,7 +22,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN is_public=$YNH_APP_ARG_IS_PUBLIC -path_url="/" +path_url=$YNH_APP_ARG_PATH secret=$(ynh_string_random) password=$YNH_APP_ARG_PASSWORD admin=$YNH_APP_ARG_ADMIN @@ -88,6 +88,16 @@ ynh_script_progression --message="Configuring system user..." --weight=3 # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" +#================================================= +# CREATE A POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user=$db_name --db_name=$db_name + #================================================= # SPECIFIC SETUP #================================================= diff --git a/scripts/remove b/scripts/remove index b6064e5..5142d55 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # STANDARD REMOVE @@ -41,6 +43,14 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config +#================================================= +# REMOVE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2 + +# Remove a database if it exists, along with the associated user +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name + #================================================= # REMOVE DEPENDENCIES #================================================= diff --git a/scripts/restore b/scripts/restore index 72dd4cc..5cee76c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -31,6 +31,9 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -76,6 +79,15 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +#================================================= +# RESTORE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 + +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name + #================================================= # RESTORE SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6624daf..373a20c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,7 +21,9 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK VERSION