diff --git a/conf/nginx.conf b/conf/nginx.conf index 94cf9b3..bcd94f2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,6 +1,6 @@ location __PATH__ { include uwsgi_params; - uwsgi_pass unix:///run/uwsgi/app/pgadmin/socket; + uwsgi_pass unix:///var/run/__NAME__/app.socket; uwsgi_read_timeout 180; uwsgi_send_timeout 180; diff --git a/conf/pgadmin.ini b/conf/uwsgi.ini similarity index 100% rename from conf/pgadmin.ini rename to conf/uwsgi.ini diff --git a/scripts/_common.sh b/scripts/_common.sh index 50dd5de..4d8c8d0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,6 +6,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=/opt/yunohost/$app pgadmin_user="pgadmin" python_version="3.5" +dependances="python3-pip build-essential python3-dev python3-venv postgresql uwsgi uwsgi-plugin-python3 expect libpq-dev" [[ -e "../settings/manifest.json" ]] || [[ -e "../manifest.json" ]] && \ APP_VERSION=$(ynh_app_upstream_version) @@ -16,15 +17,6 @@ app_sub_version=$(echo $APP_VERSION | cut -d'-' -f2) # DEFINE ALL COMMON FONCTIONS #================================================= -install_dependance() { - ynh_install_app_dependencies python3-pip build-essential python3-dev python3-venv postgresql uwsgi uwsgi-plugin-python3 expect libpq-dev -} - -psql_create_admin() { - ynh_psql_execute_as_root \ - "CREATE USER ${1} WITH PASSWORD '${2}';" -} - setup_dir() { # Create empty dir for pgadmin mkdir -p /var/lib/pgadmin @@ -35,7 +27,7 @@ setup_dir() { install_source() { if [ -n "$(uname -m | grep arm)" ] then - ynh_setup_source $final_path/ "armv7_stretch" + ynh_setup_source --dest_dir $final_path/ --source_id "armv7_stretch" else # Install virtualenv if it don't exist test -e $final_path/bin/python3 || python3 -m venv $final_path @@ -60,15 +52,6 @@ set_permission() { config_pgadmin() { cp ../conf/config_local.py $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string __USER__ $pgadmin_user $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py - ynh_replace_string __DOMAIN__ $domain $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py + ynh_replace_string --match_string __USER__ --replace_string $pgadmin_user --target_file $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py + ynh_replace_string --match_string __DOMAIN__ --replace_string $domain --target_file $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py } - -config_uwsgi() { - cp ../conf/pgadmin.ini /etc/uwsgi/apps-enabled/ - ynh_replace_string __USER__ $pgadmin_user /etc/uwsgi/apps-enabled/pgadmin.ini - ynh_replace_string __FINALPATH__ $final_path /etc/uwsgi/apps-enabled/pgadmin.ini - ynh_replace_string __PATH__ $path_url /etc/uwsgi/apps-enabled/pgadmin.ini - ynh_replace_string __PYTHON_VERSION__ $python_version /etc/uwsgi/apps-enabled/pgadmin.ini -} - diff --git a/scripts/backup b/scripts/backup index 463c493..28a94f8 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,21 +15,31 @@ source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # LOAD SETTINGS -final_path=$(ynh_app_setting_get $app final_path) -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) +ynh_script_progression --message="Loading installation settings..." +final_path=$(ynh_app_setting_get --app $app --key final_path) +domain=$(ynh_app_setting_get --app $app --key domain) +db_name=$(ynh_app_setting_get --app $app --key db_name) #================================================= # STANDARD BACKUP STEPS #================================================= # BACKUP THE APP MAIN DIR -ynh_backup "$final_path" +ynh_script_progression --message="Backing up the main app directory..." +ynh_backup --src_path "$final_path" --is_big # Backup config -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup "/etc/uwsgi/apps-enabled/pgadmin.ini" +ynh_script_progression --message="Backing configuration..." +ynh_backup --src_path "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path "/etc/uwsgi/apps-available/$app.ini" +ynh_backup --src_path "/etc/systemd/system/uwsgi-app@.service" # Backup Data and LOG -ynh_backup "/var/lib/pgadmin" -ynh_backup "/var/log/pgadmin" +ynh_script_progression --message="Backing up synapse data..." +ynh_backup --src_path "/var/lib/pgadmin" +ynh_script_progression --message="Backing up synapse log..." +ynh_backup --src_path "/var/log/pgadmin" +ynh_backup --src_path "/var/log/uwsgi/$app" + +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last + diff --git a/scripts/change_url b/scripts/change_url index 9c7c398..c39af3e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -15,15 +15,16 @@ source ./experimental_helper.sh source ./_common.sh # Retrive arguments +ynh_script_progression --message="Loading installation settings..." old_domain=$YNH_APP_OLD_DOMAIN domain=$YNH_APP_NEW_DOMAIN -path_url=$(ynh_normalize_url_path ${YNH_APP_NEW_PATH:-'/'}) -http_port=$(ynh_app_setting_get "$app" http_port) +path_url=$(ynh_normalize_url_path $(ynh_app_setting_get --app $app --key path)) #================================================= # STANDARD MODIFICATIONS #================================================= +ynh_script_progression --message="Updating configuration..." # Update nginx config if [ "$old_domain" != "$domain" ] then @@ -38,8 +39,12 @@ fi ynh_add_nginx_config # Update UWSGI Config -config_uwsgi +ynh_add_uwsgi_service 'pgadmin_user python_version' # Reload services +ynh_script_progression --message="Reloading services..." sudo systemctl reload nginx.service -sudo systemctl restart uwsgi.service \ No newline at end of file +ynh_systemd_action --service_name "uwsgi-app@$app.service" \ + --line_match "WSGI app 0 (mountpoint='$path_url') ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log" + +ynh_script_progression --message="Change of URL completed for $app" --time --last diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index 4cfc732..190d993 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -1,151 +1,128 @@ #================================================= -# POSTGRES HELPERS +# UWSGI HELPERS #================================================= -# Open a connection as a user +# Check if system wide templates are available and correcly configured # -# example: ynh_psql_connect_as 'user' 'pass' <<< "UPDATE ...;" -# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql -# -# usage: ynh_psql_connect_as user pwd [db] -# | arg: user - the user name to connect as -# | arg: pwd - the user password -# | arg: db - the database to connect to -ynh_psql_connect_as() { - user="$1" - pwd="$2" - db="$3" - su --command="PGUSER=\"${user}\" PGPASSWORD=\"${pwd}\" psql \"${db}\"" postgres +# usage: ynh_check_global_uwsgi_config +ynh_check_global_uwsgi_config () { + uwsgi --version || ynh_die --message "You need to add uwsgi (and appropriate plugin) as a dependency" + + cat > /etc/systemd/system/uwsgi-app@.service < uwsgi-app@app` +ynh_add_uwsgi_service () { + ynh_check_global_uwsgi_config + + local others_var=${1:-} + local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + + # www-data group is needed since it is this nginx who will start the service + usermod --append --groups www-data "$app" || ynh_die --message "It wasn't possible to add user $app to group www-data" + + ynh_backup_if_checksum_is_different "$finaluwsgiini" + cp ../conf/uwsgi.ini "$finaluwsgiini" + + # To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable. + # Substitute in a nginx config file only if the variable is not empty + if test -n "${final_path:-}"; then + ynh_replace_string --match_string "__FINALPATH__" --replace_string "$final_path" --target_file "$finaluwsgiini" + fi + if test -n "${path_url:-}"; then + ynh_replace_string --match_string "__PATH__" --replace_string "$path_url" --target_file "$finaluwsgiini" + fi + if test -n "${app:-}"; then + ynh_replace_string --match_string "__APP__" --replace_string "$app" --target_file "$finaluwsgiini" + fi + + # Replace all other variable given as arguments + for var_to_replace in $others_var + do + # ${var_to_replace^^} make the content of the variable on upper-cases + # ${!var_to_replace} get the content of the variable named $var_to_replace + ynh_replace_string --match_string "__${var_to_replace^^}__" --replace_string "${!var_to_replace}" --target_file "$finaluwsgiini" + done + + ynh_store_file_checksum --file "$finaluwsgiini" + + chown $app:root "$finaluwsgiini" + + # make sure the folder for logs exists and set authorizations + mkdir -p /var/log/uwsgi/$app + chown $app:root /var/log/uwsgi/$app + chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app + + # Setup specific Systemd rules if necessary + test -e ../conf/uwsgi-app@override.service && \ + mkdir /etc/systemd/system/uwsgi-app@$app.service.d && \ + cp ../conf/uwsgi-app@override.service /etc/systemd/system/uwsgi-app@$app.service.d/override.conf + + systemctl daemon-reload + systemctl enable "uwsgi-app@$app.service" + + # Add as a service + yunohost service add "uwsgi-app@$app" --log "/var/log/uwsgi/$app/$app.log" } -# Execute a command from a file as root user +# Remove the dedicated uwsgi ini file # -# usage: ynh_psql_execute_file_as_root file [db] -# | arg: file - the file containing SQL commands -# | arg: db - the database to connect to -ynh_psql_execute_file_as_root() { - file="$1" - db="$2" - su -c "psql $db" postgres < "$file" +# usage: ynh_remove_uwsgi_service +ynh_remove_uwsgi_service () { + local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" + if [ -e "$finaluwsgiini" ]; then + systemctl disable "uwsgi-app@$app.service" + yunohost service remove "uwsgi-app@$app" + + ynh_secure_remove --file="$finaluwsgiini" + ynh_secure_remove --file="/var/log/uwsgi/$app" + ynh_secure_remove --file="/etc/systemd/system/uwsgi-app@$app.service.d" + fi } -# Create a database, an user and its password. Then store the password in the app's config -# -# After executing this helper, the password of the created database will be available in $db_pwd -# It will also be stored as "psqlpwd" into the app settings. -# -# usage: ynh_psql_setup_db user name [pwd] -# | arg: user - Owner of the database -# | arg: name - Name of the database -# | arg: pwd - Password of the database. If not given, a password will be generated -ynh_psql_setup_db () { - db_user="$1" - app="$1" - db_name="$2" - new_db_pwd=$(ynh_string_random) # Generate a random password - # If $3 is not given, use new_db_pwd instead for db_pwd. - db_pwd="${3:-$new_db_pwd}" - ynh_psql_create_db "$db_name" "$db_user" "$db_pwd" # Create the database - ynh_app_setting_set "$app" psqlpwd "$db_pwd" # Store the password in the app's config -} - -# Create a database and grant optionnaly privilegies to a user -# -# usage: ynh_psql_create_db db [user [pwd]] -# | arg: db - the database name to create -# | arg: user - the user to grant privilegies -# | arg: pwd - the user password -ynh_psql_create_db() { - db="$1" - user="$2" - pwd="$3" - ynh_psql_create_user "$user" "$pwd" - su --command="createdb --owner=\"${user}\" \"${db}\"" postgres -} - -# Drop a database -# -# usage: ynh_psql_drop_db db user -# | arg: db - the database name to drop -# | arg: user - the user to drop -ynh_psql_remove_db() { - db="$1" - user="$2" - su --command="dropdb \"${db}\"" postgres - ynh_psql_drop_user "${user}" -} - -# Dump a database -# -# example: ynh_psql_dump_db 'roundcube' > ./dump.sql -# -# usage: ynh_psql_dump_db db -# | arg: db - the database name to dump -# | ret: the psqldump output -ynh_psql_dump_db() { - db="$1" - su --command="pg_dump \"${db}\"" postgres -} - - -# Create a user -# -# usage: ynh_psql_create_user user pwd [host] -# | arg: user - the user name to create -ynh_psql_create_user() { - user="$1" - pwd="$2" - su --command="psql -c\"CREATE USER ${user} WITH PASSWORD '${pwd}'\"" postgres -} - -# Drop a user -# -# usage: ynh_psql_drop_user user -# | arg: user - the user name to drop -ynh_psql_drop_user() { - user="$1" - su --command="dropuser \"${user}\"" postgres -} - - -ynh_psql_test_if_first_run() { - if [ -f /etc/yunohost/psql ]; - then - echo "PostgreSQL is already installed, no need to create master password" - else - pgsql=$(ynh_string_random) - pg_hba="" - echo "$pgsql" >> /etc/yunohost/psql - - if [ -e /etc/postgresql/9.4/ ] - then - pg_hba=/etc/postgresql/9.4/main/pg_hba.conf - elif [ -e /etc/postgresql/9.6/ ] - then - pg_hba=/etc/postgresql/9.6/main/pg_hba.conf - else - ynh_die "postgresql shoud be 9.4 or 9.6" - fi - - systemctl start postgresql - su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres - # we can't use peer since YunoHost create users with nologin - sed -i '/local\s*all\s*all\s*peer/i \ - local all all password' "$pg_hba" - systemctl enable postgresql - systemctl reload postgresql - fi -} #================================================= # OTHERS HELPERS @@ -157,9 +134,9 @@ ynh_psql_test_if_first_run() { # | arg: manifest - Path of the manifest to read # | arg: key - Name of the key to find ynh_read_manifest () { - manifest="$1" - key="$2" - python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])" + manifest="$1" + key="$2" + python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])" } # Read the upstream version from the manifest @@ -193,14 +170,3 @@ ynh_app_package_version () { version_key=$(ynh_read_manifest "$manifest_path" "version") echo "${version_key/*~ynh/}" } - -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} \ No newline at end of file diff --git a/scripts/install b/scripts/install index 15e9e4a..73b71bf 100644 --- a/scripts/install +++ b/scripts/install @@ -14,83 +14,102 @@ ynh_abort_if_errors source ./experimental_helper.sh source ./_common.sh +ynh_script_progression --message="Validating installation parameters..." + # RETRIEVE ARGUMENTS FROM THE MANIFEST domain=$YNH_APP_ARG_DOMAIN path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) admin=$YNH_APP_ARG_ADMIN -admin_pwd=$YNH_APP_ARG_ADMIN_PASSWORD db_user="pgadmin" +ynh_print_OFF +admin_pwd=$YNH_APP_ARG_ADMIN_PASSWORD +ynh_print_ON # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -test ! -e "$final_path" || ynh_die "This path already contains a folder" +test ! -e "$final_path" || ynh_die --message "This path already contains a folder" # Check web path availability -ynh_webpath_available $domain $path_url +ynh_webpath_available --domain $domain --path_url $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app $app --domain $domain --path_url $path_url # Get user email and check that the user exist -email=$(ynh_user_get_info $admin 'mail') +email=$(ynh_user_get_info --username $admin --key 'mail') if [[ -z $email ]] then - ynh_die "Can't get user email, check that the user exist or that the user have an email" + ynh_die --message "Can't get user email, check that the user exist or that the user have an email" fi # Build user password -db_pwd=$(ynh_string_random 30) - -# Reserch an opened porf for pgadmin -port=$(ynh_find_port 5050) +ynh_script_progression --message="Defining db password..." +ynh_print_OFF +db_pwd=$(ynh_string_random --length 30) +ynh_print_ON # STORE SETTINGS FROM MANIFEST -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app pgadmin_port $port -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app admin_pwd "$admin_pwd" -ynh_app_setting_set $app db_user "$db_user" -ynh_app_setting_set $app db_pwd "$db_pwd" +ynh_script_progression --message="Storing installation settings..." +ynh_app_setting_set --app $app --key domain --value $domain +ynh_app_setting_set --app $app --key path --value $path_url +ynh_app_setting_set --app $app --key admin --value $admin +ynh_app_setting_set --app $app --key db_user --value "$db_user" +ynh_app_setting_set --app $app --key final_path --value $final_path +ynh_print_OFF +ynh_app_setting_set --app $app --key admin_pwd --value "$admin_pwd" +ynh_app_setting_set --app $app --key db_pwd --value "$db_pwd" +ynh_print_ON #================================================= # STANDARD MODIFICATIONS #================================================= # Install dependance -install_dependance +ynh_script_progression --message="Installing dependencies..." --weight=7 +ynh_install_app_dependencies $dependances # Create user -ynh_system_user_create $pgadmin_user /var/lib/pgadmin - -# DOWNLOAD, CHECK AND UNPACK SOURCE -ynh_app_setting_set $app final_path $final_path +ynh_script_progression --message="Configuring system user..." +ynh_system_user_create --username $pgadmin_user --home_dir /var/lib/$app # Download, check integrity, uncompress and patch the source from app.src +ynh_script_progression --message="Installing sources files..." --weight=10 setup_dir install_source +ynh_script_progression --message="Configuring application..." + # CONFIGURE PGADMIN config_pgadmin # Config uwsgi -config_uwsgi +ynh_add_uwsgi_service 'pgadmin_user python_version' # Create a dedicated nginx config ynh_add_nginx_config +ynh_script_progression --message="Configuring sqlite database..." + # initialisation sqlite database for pgadmin chmod +x ../conf/setup.exp PS1="" source $final_path/bin/activate -ynh_replace_special_string "__ADMIN_PASSWORD__" "$admin_pwd" "../conf/setup.exp" +ynh_print_OFF +ynh_replace_special_string --match_string "__ADMIN_PASSWORD__" --replace_string "$admin_pwd" --target_file "../conf/setup.exp" +ynh_print_ON ../conf/setup.exp "$final_path/bin/python3" "$final_path/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email" # POPULATE THE DATABASE +ynh_script_progression --message="Configuring Postgresql database..." ynh_psql_test_if_first_run -su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION\"" postgres +ynh_print_OFF +ynh_psql_execute_as_root \ + --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_print_ON # Add Server In PGadmin database -ynh_replace_string "__PYTHON_VERSION__" "$python_version" config_database.py +ynh_replace_string --match_string "__PYTHON_VERSION__" --replace_string "$python_version" --target_file config_database.py +ynh_print_OFF $final_path/bin/python3 config_database.py "$db_user" "$db_pwd" +ynh_print_ON deactivate #================================================= @@ -98,13 +117,20 @@ deactivate #================================================= # Set permission after initialisation +ynh_script_progression --message="Protecting directory" set_permission # Restrict access to admin only +ynh_script_progression --message="Configuring permissions" yunohost app addaccess --users=$admin $app # Configuration de logrotate +ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate /var/log/pgadmin # reload uwsgi -systemctl restart uwsgi +ynh_script_progression --message="Starting pgadmin services..." --weight=3 +ynh_systemd_action --service_name "uwsgi-app@$app.service" \ + --line_match "WSGI app 0 (mountpoint='$path_url') ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log" + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index d1676ea..2a27209 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,40 +15,50 @@ source ./experimental_helper.sh source ./_common.sh # LOAD SETTINGS -domain=$(ynh_app_setting_get $app domain) -db_name=$(ynh_app_setting_get $app db_name) -db_user="pgadmin" +ynh_script_progression --message="Loading installation settings..." +domain=$(ynh_app_setting_get --app $app --key domain) +db_name=$(ynh_app_setting_get --app $app --key db_name) +db_user="$app" #================================================= # STANDARD REMOVE #================================================= +# Stop service +ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop + # Remove db user +ynh_script_progression --message="Cleaning the PostgreSQL database" ynh_psql_drop_user $db_user # Remove depandance +ynh_script_progression --message="Removing dependencies" --weight=10 ynh_remove_app_dependencies || true # Remove the app directory securely -ynh_secure_remove "$final_path" +ynh_script_progression --message="Removing app main directory" --weight=4 +ynh_secure_remove --file="$final_path" # Remove app data -ynh_secure_remove /var/lib/pgadmin +ynh_secure_remove --file=/var/lib/$app # Remove logrotate +ynh_script_progression --message="Removing logrotate configuration" ynh_remove_logrotate # Remove logs -ynh_secure_remove /var/log/pgadmin +ynh_script_progression --message="Removing logs" +ynh_secure_remove --file=/var/log/$app # Remove the dedicated nginx config +ynh_script_progression --message="Removing configuration" ynh_remove_nginx_config # Remove uwsgi config -ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini +ynh_remove_uwsgi_service # Delete a system user +ynh_script_progression --message="Removing the dedicated system user" ynh_system_user_delete $app -# reload uwsgi -systemctl restart uwsgi \ No newline at end of file +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index cf1a70d..bd2d5fa 100644 --- a/scripts/restore +++ b/scripts/restore @@ -15,44 +15,65 @@ source ../settings/scripts/experimental_helper.sh source ../settings/scripts/_common.sh # LOAD SETTINGS -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -final_path=$(ynh_app_setting_get $app final_path) -db_name=$(ynh_app_setting_get $app db_name) -db_user=$(ynh_app_setting_get $app db_user) -db_pwd=$(ynh_app_setting_get $app db_pwd) +ynh_script_progression --message="Loading settings..." +domain=$(ynh_app_setting_get --app $app --key domain) +path_url=$(ynh_app_setting_get --app $app --key path) +admin=$(ynh_app_setting_get --app $app --key admin) +final_path=$(ynh_app_setting_get --app $app --key final_path) +db_name=$(ynh_app_setting_get --app $app --key db_name) +db_user=$(ynh_app_setting_get --app $app --key db_user) +ynh_print_OFF +db_pwd=$(ynh_app_setting_get --app $app --key db_pwd) +ynh_print_ON #================================================= # STANDARD RESTORATION STEPS #================================================= # Install dependance -install_dependance +ynh_script_progression --message="Reinstalling dependencies..." --weight=5 +ynh_install_app_dependencies $dependances # Create user -ynh_system_user_create $pgadmin_user /var/lib/pgadmin +ynh_script_progression --message="Recreating the dedicated system user..." +ynh_system_user_create --username $pgadmin_user --home_dir /var/lib/$app # Restore all config and data +ynh_script_progression --message="Restoring files..." --weight=5 ynh_restore # POPULATE THE DATABASE +ynh_script_progression --message="Reconfiguring Postgresql database..." ynh_psql_test_if_first_run -su --command="psql -c\"CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION\"" postgres +ynh_print_OFF +ynh_psql_execute_as_root \ + --sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION" +ynh_print_ON + +# Restore systemd configuration +ynh_script_progression --message="Reconfiguring application..." +systemctl daemon-reload +systemctl enable "uwsgi-app@$app.service" #================================================= # GENERIC FINALIZATION #================================================= # Set the permission +ynh_script_progression --message="Protecting directory" set_permission # Restrict access to admin only +ynh_script_progression --message="Configuring permissions" yunohost app addaccess --users=$admin $app # Configuration de logrotate +ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate /var/log/pgadmin # reload uwsgi and nginx -systemctl restart uwsgi +ynh_systemd_action --service_name "uwsgi-app@$app.service" \ + --line_match "WSGI app 0 (mountpoint='$path_url') ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log" systemctl reload nginx + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 77551d8..b059428 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,41 +15,57 @@ source ./experimental_helper.sh source ./_common.sh # LOAD SETTINGS -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_normalize_url_path $(ynh_app_setting_get $app path)) -admin=$(ynh_app_setting_get $app admin) +ynh_script_progression --message="Loading installation settings..." +domain=$(ynh_app_setting_get --app $app --key domain) +path_url=$(ynh_normalize_url_path $(ynh_app_setting_get --app $app --key path)) +admin=$(ynh_app_setting_get --app $app --key admin) # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 ynh_backup_before_upgrade # Backup the current version of the app ynh_clean_setup () { ynh_restore_upgradebackup # restore it if the upgrade fails } +ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop + #================================================= # STANDARD UPGRADE STEPS #================================================= # Install dependance -install_dependance +ynh_script_progression --message="Upgrading dependencies..." +ynh_install_app_dependencies $dependances # Download, check integrity, uncompress and patch the source from app.src +ynh_script_progression --message="Upgrading source files..." --weight=6 install_source # CONFIGURE PGADMIN +ynh_script_progression --message="Configuring application..." config_pgadmin # Config uwsgi -config_uwsgi +ynh_add_uwsgi_service 'pgadmin_user python_version' + +# Create a dedicated nginx config +ynh_add_nginx_config #================================================= # GENERIC FINALIZATION #================================================= # Set permission after initialisation +ynh_script_progression --message="Protecting directory" set_permission -# Create a dedicated nginx config -ynh_add_nginx_config +# Configuration de logrotate +ynh_script_progression --message="Configuring log rotation..." +ynh_use_logrotate /var/log/pgadmin --nonappend # reload uwsgi -systemctl restart uwsgi +ynh_script_progression --message="Restarting pgadmin services..." --weight=3 +ynh_systemd_action --service_name "uwsgi-app@$app.service" \ + --line_match "WSGI app 0 (mountpoint='$path_url') ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log" + +ynh_script_progression --message="Upgrade of $app completed" --last