1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/coin_ynh.git synced 2024-09-03 18:16:26 +02:00

Merge pull request #14 from YunoHost-Apps/Fix_restoration

Fix restoration
This commit is contained in:
ljf (zamentur) 2019-08-23 12:53:37 +02:00 committed by GitHub
commit 5ce813cfbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 96 deletions

View file

@ -16,7 +16,7 @@
"requirements": { "requirements": {
"yunohost": ">> 3.0" "yunohost": ">> 3.0"
}, },
"version": "20180817~ynh3", "version": "20180817~ynh4",
"multi_instance": false, "multi_instance": false,
"services": [ "services": [
"nginx" "nginx"

View file

@ -18,3 +18,6 @@ ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
# Copy Gunicorn pool configuration # Copy Gunicorn pool configuration
ynh_backup "/etc/systemd/system/$app.service" "gunicorn.service" ynh_backup "/etc/systemd/system/$app.service" "gunicorn.service"
# Backup database
ynh_psql_dump_db "$app" > ${YNH_CWD}/dump.sql

View file

@ -7,9 +7,7 @@ function install_dependencies()
function init_db() function init_db()
{ {
sed -i '/local\s*all\s*all\s*peer/i \ ynh_psql_test_if_first_run
local all coin password' /etc/postgresql/9.*/main/pg_hba.conf
service postgresql reload
# Generate random password # Generate random password
db_name=$app db_name=$app
db_user=$app db_user=$app

View file

@ -237,90 +237,3 @@ ynh_exit_if_up_to_date () {
exit 0 exit 0
fi 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
}

View file

@ -98,6 +98,7 @@ function configure_gunicorn()
sudo cp ../conf/gunicorn.service /etc/systemd/system/$app.service sudo cp ../conf/gunicorn.service /etc/systemd/system/$app.service
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo cp ../conf/gunicorn_config.py /opt/$app/ sudo cp ../conf/gunicorn_config.py /opt/$app/
chown $app:www-data /opt/$app/gunicorn_config.py
} }
function configure_nginx_and_ssowat() function configure_nginx_and_ssowat()

View file

@ -15,8 +15,7 @@ DOMAIN=$(ynh_app_setting_get "$APP" domain)
# Add tests that stuff actually exists before removing them # Add tests that stuff actually exists before removing them
# Remove mysql table # Remove mysql table
ynh_psql_drop_db $app ynh_psql_remove_db $app $app
ynh_psql_drop_user $app
# Remove dependencies # Remove dependencies
ynh_remove_app_dependencies ynh_remove_app_dependencies

View file

@ -8,6 +8,7 @@ app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers # Source YunoHost helpers
. /usr/share/yunohost/helpers . /usr/share/yunohost/helpers
source ../settings/scripts/common.sh
# Retrieve old app settings # Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)
@ -17,6 +18,7 @@ email=$(ynh_app_setting_get "$app" email)
isp_name=$(ynh_app_setting_get "$app" isp_name) isp_name=$(ynh_app_setting_get "$app" isp_name)
isp_site=$(ynh_app_setting_get "$app" isp_site) isp_site=$(ynh_app_setting_get "$app" isp_site)
secret=$(ynh_app_setting_get "$app" secret) secret=$(ynh_app_setting_get "$app" secret)
db_pwd=$(ynh_app_setting_get "$app" psqlpassword)
# Check domain/path availability # Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app \ sudo yunohost app checkurl $domain$path -a $app \
@ -39,14 +41,16 @@ if [ -f $gunicorn_path ]; then
fi fi
# Dependences # Dependences
ynh_package_install python3-pip python3-virtualenv install_dependencies
# Restore sources & data # Restore sources & data
sudo cp -a ./sources $final_path sudo cp -a ./sources $final_path
# Create user
useradd $app -d $final_path || echo "User already exists"
# Set permissions # Set permissions
sudo chown -R www-data:www-data $final_path sudo chown -R $app:www-data $final_path
# Restore conf files # Restore conf files
sudo cp -a ./nginx.conf $conf sudo cp -a ./nginx.conf $conf
@ -59,6 +63,13 @@ if ynh_user_exists $admin; then
sudo yunohost app addaccess $app -u $admin sudo yunohost app addaccess $app -u $admin
fi 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 # Log folder
sudo mkdir -p /var/log/$app sudo mkdir -p /var/log/$app
sudo chown -R $app /var/log/$app sudo chown -R $app /var/log/$app
@ -66,6 +77,7 @@ sudo chgrp -R www-data /var/log/$app
# Reload Nginx # Reload Nginx
sudo service nginx reload sudo service nginx reload
systemctl daemon-reload
sudo systemctl start $app sudo systemctl start $app
sudo systemctl enable $app sudo systemctl enable $app
sudo yunohost service add $app -l /var/log/gunicorn/$app.log sudo yunohost service add $app -l /var/log/gunicorn/$app.log