1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pgadmin_ynh.git synced 2024-09-03 19:56:38 +02:00

Merge branch 'full_package_upgrade' into testing

This commit is contained in:
Josué Tille 2019-07-30 11:05:56 +02:00
commit e9fe3698db
No known key found for this signature in database
GPG key ID: 716A6C99B04194EF
12 changed files with 284 additions and 296 deletions

View file

@ -18,16 +18,7 @@
port_already_use=0 port_already_use=0
change_url=1 change_url=1
;;; Levels ;;; Levels
Level 1=auto Level 5=auto
Level 2=auto
Level 3=auto
Level 4=0
Level 5=0
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options ;;; Options
Email= Email=
Notification=none Notification=none

View file

@ -1,6 +1,6 @@
location __PATH__ { location __PATH__ {
include uwsgi_params; include uwsgi_params;
uwsgi_pass unix:///run/uwsgi/app/pgadmin/socket; uwsgi_pass unix:///var/run/__NAME__/app.socket;
uwsgi_read_timeout 180; uwsgi_read_timeout 180;
uwsgi_send_timeout 180; uwsgi_send_timeout 180;

View file

@ -14,7 +14,7 @@
"email": "josue@tille.ch" "email": "josue@tille.ch"
}, },
"requirements": { "requirements": {
"yunohost": ">= 3.3.1" "yunohost": ">= 3.5.2.2"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [

View file

@ -6,25 +6,18 @@ app=$YNH_APP_INSTANCE_NAME
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
pgadmin_user="pgadmin" pgadmin_user="pgadmin"
python_version="3.5" 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" ]] && \ if [[ -e "../settings/manifest.json" ]] || [[ -e "../manifest.json" ]]; then
APP_VERSION=$(ynh_app_upstream_version) APP_VERSION=$(ynh_app_upstream_version)
app_main_version=$(echo $APP_VERSION | cut -d'-' -f1) app_main_version=$(echo $APP_VERSION | cut -d'-' -f1)
app_sub_version=$(echo $APP_VERSION | cut -d'-' -f2) app_sub_version=$(echo $APP_VERSION | cut -d'-' -f2)
fi
#================================================= #=================================================
# DEFINE ALL COMMON FONCTIONS # 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() { setup_dir() {
# Create empty dir for pgadmin # Create empty dir for pgadmin
mkdir -p /var/lib/pgadmin mkdir -p /var/lib/pgadmin
@ -35,7 +28,7 @@ setup_dir() {
install_source() { install_source() {
if [ -n "$(uname -m | grep arm)" ] if [ -n "$(uname -m | grep arm)" ]
then then
ynh_setup_source $final_path/ "armv7_stretch" ynh_setup_source --dest_dir $final_path/ --source_id "armv7_stretch"
else else
# Install virtualenv if it don't exist # Install virtualenv if it don't exist
test -e $final_path/bin/python3 || python3 -m venv $final_path test -e $final_path/bin/python3 || python3 -m venv $final_path
@ -60,15 +53,6 @@ set_permission() {
config_pgadmin() { config_pgadmin() {
cp ../conf/config_local.py $final_path/lib/python$python_version/site-packages/pgadmin4/config_local.py 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 --match_string __USER__ --replace_string $pgadmin_user --target_file $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 __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
}

View file

@ -15,21 +15,31 @@ source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
# LOAD SETTINGS # LOAD SETTINGS
final_path=$(ynh_app_setting_get $app final_path) ynh_script_progression --message="Loading installation settings..."
domain=$(ynh_app_setting_get $app domain) final_path=$(ynh_app_setting_get --app $app --key final_path)
db_name=$(ynh_app_setting_get $app db_name) domain=$(ynh_app_setting_get --app $app --key domain)
db_name=$(ynh_app_setting_get --app $app --key db_name)
#================================================= #=================================================
# STANDARD BACKUP STEPS # STANDARD BACKUP STEPS
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # 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"
# Backup config # Backup config
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Backing configuration..."
ynh_backup "/etc/uwsgi/apps-enabled/pgadmin.ini" 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 # Backup Data and LOG
ynh_backup "/var/lib/pgadmin" ynh_script_progression --message="Backing up data..."
ynh_backup "/var/log/pgadmin" ynh_backup --src_path "/var/lib/pgadmin"
ynh_script_progression --message="Backing up 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

View file

@ -15,31 +15,36 @@ source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# Retrive arguments # Retrive arguments
ynh_script_progression --message="Loading installation settings..."
old_domain=$YNH_APP_OLD_DOMAIN old_domain=$YNH_APP_OLD_DOMAIN
domain=$YNH_APP_NEW_DOMAIN domain=$YNH_APP_NEW_DOMAIN
path_url=$(ynh_normalize_url_path ${YNH_APP_NEW_PATH:-'/'}) path_url=$(ynh_normalize_url_path $YNH_APP_NEW_PATH)
http_port=$(ynh_app_setting_get "$app" http_port)
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
ynh_script_progression --message="Updating configuration..."
# Update nginx config # Update nginx config
if [ "$old_domain" != "$domain" ] if [ "$old_domain" != "$domain" ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
ynh_delete_file_checksum "/etc/nginx/conf.d/$old_domain.d/$app.conf" ynh_delete_file_checksum --file "/etc/nginx/conf.d/$old_domain.d/$app.conf"
mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf" mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
# Store file checksum for the new config file location # Store file checksum for the new config file location
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_store_file_checksum --file "/etc/nginx/conf.d/$domain.d/$app.conf"
fi fi
ynh_add_nginx_config ynh_add_nginx_config
# Update UWSGI Config # Update UWSGI Config
config_uwsgi ynh_add_uwsgi_service 'pgadmin_user python_version'
# Reload services # Reload services
ynh_script_progression --message="Reloading services..."
sudo systemctl reload nginx.service sudo systemctl reload nginx.service
sudo systemctl restart uwsgi.service ynh_systemd_action --service_name "uwsgi-app@$app.service" --action restart \
--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" --last

View file

@ -1,206 +1,129 @@
#================================================= #=================================================
# 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 ...;" # usage: ynh_check_global_uwsgi_config
# example: ynh_psql_connect_as 'user' 'pass' < /path/to/file.sql ynh_check_global_uwsgi_config () {
# uwsgi --version || ynh_die --message "You need to add uwsgi (and appropriate plugin) as a dependency"
# usage: ynh_psql_connect_as user pwd [db]
# | arg: user - the user name to connect as cat > /etc/systemd/system/uwsgi-app@.service <<EOF
# | arg: pwd - the user password [Unit]
# | arg: db - the database to connect to Description=%i uWSGI app
ynh_psql_connect_as() { After=syslog.target
user="$1"
pwd="$2" [Service]
db="$3" RuntimeDirectory=%i
su --command="PGUSER=\"${user}\" PGPASSWORD=\"${pwd}\" psql \"${db}\"" postgres ExecStart=/usr/bin/uwsgi \
--ini /etc/uwsgi/apps-available/%i.ini \
--socket /var/run/%i/app.socket \
--logto /var/log/uwsgi/%i/%i.log
User=%i
Group=www-data
Restart=on-failure
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
} }
# # Execute a command as root user # Create a dedicated uwsgi ini file to use with generic uwsgi service
# #
# usage: ynh_psql_execute_as_root sql [db] # This will use a template in ../conf/uwsgi.ini
# | arg: sql - the SQL command to execute # and will replace the following keywords with
# | arg: db - the database to connect to # global variables that should be defined before calling
ynh_psql_execute_as_root () { # this helper :
sql="$1" #
su --command="psql" postgres <<< "$sql" # __APP__ by $app
# __PATH__ by $path_url
# __FINALPATH__ by $final_path
#
# And dynamic variables (from the last example) :
# __PATH_2__ by $path_2
# __PORT_2__ by $port_2
#
# To be able to customise the settings of the systemd unit you can override the rules with the file "conf/uwsgi-app@override.service".
# This file will be automatically placed on the good place
#
# usage: ynh_add_uwsgi_service
#
# to interact with your service: `systemctl <action> 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] # usage: ynh_remove_uwsgi_service
# | arg: file - the file containing SQL commands ynh_remove_uwsgi_service () {
# | arg: db - the database to connect to local finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
ynh_psql_execute_file_as_root() { if [ -e "$finaluwsgiini" ]; then
file="$1" systemctl disable "uwsgi-app@$app.service"
db="$2" yunohost service remove "uwsgi-app@$app"
su -c "psql $db" postgres < "$file"
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 # OTHERS HELPERS
#================================================= #=================================================
# Read the value of a key in a ynh manifest file
#
# usage: ynh_read_manifest manifest key
# | 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'])"
}
# Read the upstream version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number before ~ynh
# In the last example it return 4.3-2
#
# usage: ynh_app_upstream_version
ynh_app_upstream_version () {
manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi
version_key=$(ynh_read_manifest "$manifest_path" "version")
echo "${version_key/~ynh*/}"
}
# Read package version from the manifest
# The version number in the manifest is defined by <upstreamversion>~ynh<packageversion>
# For example : 4.3-2~ynh3
# This include the number after ~ynh
# In the last example it return 3
#
# usage: ynh_app_package_version
ynh_app_package_version () {
manifest_path="../manifest.json"
if [ ! -e "$manifest_path" ]; then
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
fi
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
}

View file

@ -14,83 +14,100 @@ ynh_abort_if_errors
source ./experimental_helper.sh source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
ynh_script_progression --message="Validating installation parameters..."
# RETRIEVE ARGUMENTS FROM THE MANIFEST # RETRIEVE ARGUMENTS FROM THE MANIFEST
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH) path_url=$(ynh_normalize_url_path $YNH_APP_ARG_PATH)
admin=$YNH_APP_ARG_ADMIN admin=$YNH_APP_ARG_ADMIN
admin_pwd=$YNH_APP_ARG_ADMIN_PASSWORD
db_user="pgadmin" 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 # 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
# Register (book) web path # 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 # 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 ]] if [[ -z $email ]]
then 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 fi
# Build user password # Build user password
db_pwd=$(ynh_string_random 30) ynh_script_progression --message="Defining db password..."
ynh_print_OFF
# Reserch an opened porf for pgadmin db_pwd=$(ynh_string_random --length 30)
port=$(ynh_find_port 5050) ynh_print_ON
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
ynh_app_setting_set $app domain $domain ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set $app path $path_url ynh_app_setting_set --app $app --key domain --value $domain
ynh_app_setting_set $app pgadmin_port $port ynh_app_setting_set --app $app --key path --value $path_url
ynh_app_setting_set $app admin $admin ynh_app_setting_set --app $app --key admin --value $admin
ynh_app_setting_set $app admin_pwd "$admin_pwd" ynh_app_setting_set --app $app --key db_user --value "$db_user"
ynh_app_setting_set $app db_user "$db_user" ynh_app_setting_set --app $app --key final_path --value $final_path
ynh_app_setting_set $app db_pwd "$db_pwd" 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 # STANDARD MODIFICATIONS
#================================================= #=================================================
# Install dependance # Install dependance
install_dependance ynh_script_progression --message="Installing dependencies..." --weight=7
ynh_install_app_dependencies $dependances
# Create user # Create user
ynh_system_user_create $pgadmin_user /var/lib/pgadmin ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username $pgadmin_user --home_dir /var/lib/$app
# DOWNLOAD, CHECK AND UNPACK SOURCE
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_script_progression --message="Installing sources files..." --weight=10
setup_dir setup_dir
install_source install_source
ynh_script_progression --message="Configuring application..."
# CONFIGURE PGADMIN # CONFIGURE PGADMIN
config_pgadmin config_pgadmin
# Config uwsgi # Config uwsgi
config_uwsgi ynh_add_uwsgi_service 'pgadmin_user python_version'
# Create a dedicated nginx config # Create a dedicated nginx config
ynh_add_nginx_config ynh_add_nginx_config
ynh_script_progression --message="Configuring sqlite database..."
# initialisation sqlite database for pgadmin # initialisation sqlite database for pgadmin
chmod +x ../conf/setup.exp chmod +x ../conf/setup.exp
PS1="" PS1=""
source $final_path/bin/activate 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" ../conf/setup.exp "$final_path/bin/python3" "$final_path/lib/python$python_version/site-packages/pgadmin4/setup.py" "$email"
# POPULATE THE DATABASE # POPULATE THE DATABASE
ynh_script_progression --message="Configuring Postgresql database..."
ynh_psql_test_if_first_run 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 # 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" $final_path/bin/python3 config_database.py "$db_user" "$db_pwd"
ynh_print_ON
deactivate deactivate
#================================================= #=================================================
@ -98,13 +115,20 @@ deactivate
#================================================= #=================================================
# Set permission after initialisation # Set permission after initialisation
ynh_script_progression --message="Protecting directory"
set_permission set_permission
# Restrict access to admin only # Restrict access to admin only
ynh_script_progression --message="Configuring permissions"
yunohost app addaccess --users=$admin $app yunohost app addaccess --users=$admin $app
# Configuration de logrotate # Configuration de logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate /var/log/pgadmin ynh_use_logrotate /var/log/pgadmin
# reload uwsgi # 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

View file

@ -15,40 +15,50 @@ source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# LOAD SETTINGS # LOAD SETTINGS
domain=$(ynh_app_setting_get $app domain) ynh_script_progression --message="Loading installation settings..."
db_name=$(ynh_app_setting_get $app db_name) domain=$(ynh_app_setting_get --app $app --key domain)
db_user="pgadmin" db_name=$(ynh_app_setting_get --app $app --key db_name)
db_user="$app"
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# Stop service
ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop
# Remove db user # Remove db user
ynh_script_progression --message="Cleaning the PostgreSQL database..."
ynh_psql_drop_user $db_user ynh_psql_drop_user $db_user
# Remove depandance # Remove depandance
ynh_script_progression --message="Removing dependencies..." --weight=10
ynh_remove_app_dependencies || true ynh_remove_app_dependencies || true
# Remove the app directory securely # 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 # Remove app data
ynh_secure_remove /var/lib/pgadmin ynh_secure_remove --file=/var/lib/$app
# Remove logrotate # Remove logrotate
ynh_script_progression --message="Removing logrotate configuration..."
ynh_remove_logrotate ynh_remove_logrotate
# Remove logs # 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 # Remove the dedicated nginx config
ynh_script_progression --message="Removing configuration..."
ynh_remove_nginx_config ynh_remove_nginx_config
# Remove uwsgi config # Remove uwsgi config
ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini ynh_remove_uwsgi_service
# Delete a system user # Delete a system user
ynh_script_progression --message="Removing the dedicated system user..."
ynh_system_user_delete $app ynh_system_user_delete $app
# reload uwsgi ynh_script_progression --message="Removal of $app completed" --last
systemctl restart uwsgi

View file

@ -15,44 +15,66 @@ source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
# LOAD SETTINGS # LOAD SETTINGS
domain=$(ynh_app_setting_get $app domain) ynh_script_progression --message="Loading settings..."
path_url=$(ynh_app_setting_get $app path) domain=$(ynh_app_setting_get --app $app --key domain)
admin=$(ynh_app_setting_get $app admin) path_url=$(ynh_app_setting_get --app $app --key path)
final_path=$(ynh_app_setting_get $app final_path) admin=$(ynh_app_setting_get --app $app --key admin)
db_name=$(ynh_app_setting_get $app db_name) final_path=$(ynh_app_setting_get --app $app --key final_path)
db_user=$(ynh_app_setting_get $app db_user) db_name=$(ynh_app_setting_get --app $app --key db_name)
db_pwd=$(ynh_app_setting_get $app db_pwd) 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 # STANDARD RESTORATION STEPS
#================================================= #=================================================
# Install dependance # Install dependance
install_dependance ynh_script_progression --message="Reinstalling dependencies..." --weight=5
ynh_install_app_dependencies $dependances
# Create user # 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 # Restore all config and data
ynh_script_progression --message="Restoring files..." --weight=5
ynh_restore ynh_restore
# POPULATE THE DATABASE # POPULATE THE DATABASE
ynh_script_progression --message="Reconfiguring Postgresql database..."
ynh_psql_test_if_first_run 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 # GENERIC FINALIZATION
#================================================= #=================================================
# Set the permission # Set the permission
ynh_script_progression --message="Protecting directory..."
set_permission set_permission
# Restrict access to admin only # Restrict access to admin only
ynh_script_progression --message="Configuring permissions..."
yunohost app addaccess --users=$admin $app yunohost app addaccess --users=$admin $app
# Configuration de logrotate # Configuration de logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate /var/log/pgadmin ynh_use_logrotate /var/log/pgadmin
# reload uwsgi and nginx # reload uwsgi and nginx
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"
systemctl reload nginx systemctl reload nginx
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -15,41 +15,60 @@ source ./experimental_helper.sh
source ./_common.sh source ./_common.sh
# LOAD SETTINGS # LOAD SETTINGS
domain=$(ynh_app_setting_get $app domain) ynh_script_progression --message="Loading installation settings..."
path_url=$(ynh_normalize_url_path $(ynh_app_setting_get $app path)) domain=$(ynh_app_setting_get --app $app --key domain)
admin=$(ynh_app_setting_get $app admin) 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 # 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_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () { ynh_clean_setup () {
ynh_restore_upgradebackup # restore it if the upgrade fails ynh_restore_upgradebackup # restore it if the upgrade fails
} }
ynh_systemd_action --service_name "uwsgi-app@$app.service" --action stop
#================================================= #=================================================
# STANDARD UPGRADE STEPS # STANDARD UPGRADE STEPS
#================================================= #=================================================
# Install dependance # 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 # Download, check integrity, uncompress and patch the source from app.src
ynh_script_progression --message="Upgrading source files..." --weight=6
install_source install_source
# CONFIGURE PGADMIN # CONFIGURE PGADMIN
ynh_script_progression --message="Configuring application..."
config_pgadmin config_pgadmin
# Config uwsgi # Config uwsgi
config_uwsgi ynh_add_uwsgi_service 'pgadmin_user python_version'
# Create a dedicated nginx config
ynh_add_nginx_config
# Clean old uwsgi config
ynh_secure_remove /etc/uwsgi/apps-enabled/pgadmin.ini
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
# Set permission after initialisation # Set permission after initialisation
ynh_script_progression --message="Protecting directory..."
set_permission set_permission
# Create a dedicated nginx config # Configuration de logrotate
ynh_add_nginx_config ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate /var/log/pgadmin --nonappend
# reload uwsgi # 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