From e24453ff65a4b7101e57f7cee433c3d0efab9a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 20 Dec 2018 19:58:44 +0100 Subject: [PATCH 1/7] Fix restore script --- scripts/restore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/restore b/scripts/restore index c3d4fc8..c58b91d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -44,6 +44,8 @@ ynh_package_install python3-pip python3-virtualenv # Restore sources & data sudo cp -a ./sources $final_path +# Create user +useradd $app -d $final_path || echo "User already exists" # Set permissions sudo chown -R www-data:www-data $final_path @@ -66,6 +68,7 @@ sudo chgrp -R www-data /var/log/$app # Reload Nginx sudo service nginx reload +systemctl daemon-reload sudo systemctl start $app sudo systemctl enable $app sudo yunohost service add $app -l /var/log/gunicorn/$app.log From 1bcea9bb36352c910ea28dd5f4970565f0985caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 20 Dec 2018 22:52:51 +0100 Subject: [PATCH 2/7] Fix install --- scripts/install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c2aab89..5adc56a 100644 --- a/scripts/install +++ b/scripts/install @@ -98,13 +98,14 @@ function configure_gunicorn() sudo cp ../conf/gunicorn.service /etc/systemd/system/$app.service sudo systemctl daemon-reload sudo cp ../conf/gunicorn_config.py /opt/$app/ + chown $app:www-data /opt/$app/gunicorn_config.py } function configure_nginx_and_ssowat() { # Reload Nginx and regenerate SSOwat conf sudo yunohost app addaccess $app -u $admin - + # Modify Nginx configuration file and copy it to Nginx conf directory sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf From 1efb077f70111fc273a77c79476bd4e0fe947d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 20 Dec 2018 22:55:17 +0100 Subject: [PATCH 3/7] Remove postgresql helper, use it from upstream --- scripts/future.sh | 87 ----------------------------------------------- scripts/remove | 3 +- 2 files changed, 1 insertion(+), 89 deletions(-) diff --git a/scripts/future.sh b/scripts/future.sh index d827d1d..7652ee3 100644 --- a/scripts/future.sh +++ b/scripts/future.sh @@ -237,90 +237,3 @@ ynh_exit_if_up_to_date () { exit 0 fi } - -# Open a connection as a user -# -# 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() { - ynh_die "ynh_psql_connect_as is not yet implemented" -} - -# # Execute a command as root user -# -# usage: ynh_psql_execute_as_root sql [db] -# | arg: sql - the SQL command to execute -# | arg: db - the database to connect to -ynh_psql_execute_as_root () { - sudo su -c "psql" - postgres <<< ${1} -} - -# Execute a command from a file as root user -# -# 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() { - ynh_die "ynh_psql_execute_file_as_root is not yet implemented" -} - -# 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 password to identify user by -ynh_psql_create_db() { - db=$1 - # grant all privilegies to user - if [[ $# -gt 1 ]]; then - ynh_psql_create_user ${2} "${3}" - sudo su -c "createdb -O ${2} $db" - postgres - else - sudo su -c "createdb $db" - postgres - fi - -} - -# Drop a database -# -# usage: ynh_psql_drop_db db -# | arg: db - the database name to drop -ynh_psql_drop_db() { - sudo su -c "dropdb ${1}" - postgres -} - -# 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() { - ynh_die "ynh_psql_dump_db is not yet implemented" -} - - -# Create a user -# -# usage: ynh_psql_create_user user pwd [host] -# | arg: user - the user name to create -# | arg: pwd - the password to identify user by -ynh_psql_create_user() { - ynh_psql_execute_as_root \ - "CREATE USER ${1} WITH PASSWORD '${2}';" -} - -# Drop a user -# -# usage: ynh_psql_drop_user user -# | arg: user - the user name to drop -ynh_psql_drop_user() { - sudo su -c "dropuser ${1}" - postgres -} diff --git a/scripts/remove b/scripts/remove index 3a445c1..b69c04b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,8 +15,7 @@ DOMAIN=$(ynh_app_setting_get "$APP" domain) # Add tests that stuff actually exists before removing them # Remove mysql table -ynh_psql_drop_db $app -ynh_psql_drop_user $app +ynh_psql_remove_db $app $app # Remove dependencies ynh_remove_app_dependencies From f9bdeba4a54d7b694eae9db29a95501bc3a9647c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 20 Dec 2018 23:05:20 +0100 Subject: [PATCH 4/7] Backup and restore database --- scripts/backup | 3 +++ scripts/common.sh | 4 +--- scripts/restore | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/backup b/scripts/backup index eb5832a..1a6d84d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -18,3 +18,6 @@ ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" # Copy Gunicorn pool configuration ynh_backup "/etc/systemd/system/$app.service" "gunicorn.service" + +# Backup database +ynh_psql_dump_db "$app" > ${YNH_CWD}/dump.sql diff --git a/scripts/common.sh b/scripts/common.sh index 3ecf90c..87e10a8 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -7,9 +7,7 @@ function install_dependencies() function init_db() { - sed -i '/local\s*all\s*all\s*peer/i \ -local all coin password' /etc/postgresql/9.*/main/pg_hba.conf - service postgresql reload + ynh_psql_test_if_first_run # Generate random password db_name=$app db_user=$app diff --git a/scripts/restore b/scripts/restore index c58b91d..dd1a52d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -17,6 +17,7 @@ email=$(ynh_app_setting_get "$app" email) isp_name=$(ynh_app_setting_get "$app" isp_name) isp_site=$(ynh_app_setting_get "$app" isp_site) secret=$(ynh_app_setting_get "$app" secret) +db_pwd=$(ynh_app_setting_get "$app" psqlpassword) # Check domain/path availability sudo yunohost app checkurl $domain$path -a $app \ @@ -61,6 +62,13 @@ if ynh_user_exists $admin; then sudo yunohost app addaccess $app -u $admin fi +# Restore database +ynh_psql_test_if_first_run +db_name=$app +db_user=$app +ynh_psql_create_db $db_name $db_user $db_pwd +ynh_psql_execute_file_as_root "${YNH_CWD}/dump.sql" "$db_name" + # Log folder sudo mkdir -p /var/log/$app sudo chown -R $app /var/log/$app From 14fea28970710316e28250969e70bb949f04a5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 21 Dec 2018 17:12:23 +0100 Subject: [PATCH 5/7] Fix dependence in restore script --- scripts/restore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index dd1a52d..c7e4ec8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -8,6 +8,7 @@ app=$YNH_APP_INSTANCE_NAME # Source YunoHost helpers . /usr/share/yunohost/helpers +source ../settings/scripts/common.sh # Retrieve old app settings domain=$(ynh_app_setting_get "$app" domain) @@ -40,7 +41,7 @@ if [ -f $gunicorn_path ]; then fi # Dependences -ynh_package_install python3-pip python3-virtualenv +install_dependencies # Restore sources & data sudo cp -a ./sources $final_path From acc0c55766f6fcde5f5d6cc4ed925b6861512400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 21 Dec 2018 18:25:59 +0100 Subject: [PATCH 6/7] Fix owner in restoration --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index c7e4ec8..902cb6b 100644 --- a/scripts/restore +++ b/scripts/restore @@ -50,7 +50,7 @@ sudo cp -a ./sources $final_path useradd $app -d $final_path || echo "User already exists" # Set permissions -sudo chown -R www-data:www-data $final_path +sudo chown -R $app:www-data $final_path # Restore conf files sudo cp -a ./nginx.conf $conf From 1117b49a1a74c6b1f01400bec7129ebee3991a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 21 Dec 2018 22:15:29 +0100 Subject: [PATCH 7/7] Update version --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 8f93fb8..8059b7f 100644 --- a/manifest.json +++ b/manifest.json @@ -16,7 +16,7 @@ "requirements": { "yunohost": ">> 3.0" }, - "version": "20180817~ynh3", + "version": "20180817~ynh4", "multi_instance": false, "services": [ "nginx"