From 1838024e42ef3319a6571df80ff4c70a292a9748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Tue, 30 Jan 2024 17:20:58 +0100 Subject: [PATCH] handle psql user differently --- manifest.toml | 4 ++-- scripts/install | 2 +- scripts/remove | 7 ------- scripts/restore | 3 +-- scripts/upgrade | 5 ++--- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/manifest.toml b/manifest.toml index 3d8cbf3..4a57f2c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -67,5 +67,5 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen [resources.apt] packages = "python3-pip, build-essential, python3-dev, python3-venv, postgresql, uwsgi, uwsgi-plugin-python3, expect, libpq-dev, libkrb5-dev" - # [resources.database] - # type = "postgresql" + [resources.database] + type = "postgresql" diff --git a/scripts/install b/scripts/install index 2438a40..75c299f 100644 --- a/scripts/install +++ b/scripts/install @@ -44,7 +44,7 @@ chmod +x "$install_dir/setup.exp" # Postgresql superuser #================================================= ynh_script_progression --message="Configuring Postgresql superuser..." -ynh_psql_execute_as_root --sql "CREATE USER $db_user WITH PASSWORD '$db_pwd' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_psql_execute_as_root --sql "ALTER USER $app WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" # Add Server In PGadmin database ynh_add_config --template="setup_database.py" --destination "$install_dir/setup_database.py" diff --git a/scripts/remove b/scripts/remove index 08ad141..d7dcf48 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,13 +27,6 @@ ynh_remove_logrotate # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# CONFIGURE POSTGRESQL -#================================================= -ynh_script_progression --message="Removing the Postgresql superuser..." - -ynh_psql_drop_user "$db_user" - #================================================= # SPECIFIC REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index 6b492a3..4c08d5f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -27,8 +27,7 @@ chown -R "$app:www-data" "$install_dir" # RESTORE THE POSTGRESQL SUPERUSER #================================================= ynh_script_progression --message="Restoring the Postgresql superuser..." --weight=1 - -ynh_psql_execute_as_root --sql "CREATE USER $db_user WITH PASSWORD '$db_pwd' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_psql_execute_as_root --sql "ALTER USER $db_user WITH SUPERUSER CREATEDB CREATEROLE REPLICATION" #================================================= # REINSTALL DEPENDENCIES diff --git a/scripts/upgrade b/scripts/upgrade index c6e7fc8..d694fe8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,9 +26,8 @@ fi #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -if ! grep -q "$install_dir" /etc/passwd; then - sed --in-place -r "s@$app\:x\:([[:digit:]]+\:[[:digit:]]+)\:\:/.*/$app\:/usr/sbin/nologin@$app\:x\:\1\:\:$install_dir\:/usr/sbin/nologin@g" /etc/passwd -fi +# Set the proper home directory +usermod -d "$install_dir" "$app" # Clean old uwsgi config ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini