From 25d73a472c195aa0b0a3713c9f00f6bc586fe6a6 Mon Sep 17 00:00:00 2001 From: Kayou Date: Wed, 20 Mar 2019 00:16:02 +0100 Subject: [PATCH] Fix upgrade from the old version --- conf/lufi.conf.template | 2 +- scripts/backup | 5 ++++- scripts/change_url | 2 ++ scripts/install | 5 +++++ scripts/remove | 2 +- scripts/restore | 14 +++++++++----- scripts/upgrade | 24 +++++++++++++++++++++--- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/conf/lufi.conf.template b/conf/lufi.conf.template index 4fc1e86..4a24af8 100644 --- a/conf/lufi.conf.template +++ b/conf/lufi.conf.template @@ -117,7 +117,7 @@ # choose what database you want to use # valid choices are sqlite, postgresql and mysql (all lowercase) # optional, default is sqlite - dbtype => 'postgresql', + dbtype => '__DB_MANAGER__', # SQLite ONLY - only used if dbtype is set to sqlite # define a path to the SQLite database diff --git a/scripts/backup b/scripts/backup index 15c84e6..e7dac3c 100644 --- a/scripts/backup +++ b/scripts/backup @@ -30,6 +30,7 @@ app=$YNH_APP_INSTANCE_NAME 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) +db_manager=$(ynh_app_setting_get $app db_manager) #================================================= # STANDARD BACKUP STEPS @@ -52,7 +53,9 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db "$db_name" > db.sql +if [ $db_manager = "postgresql" ]; then + ynh_psql_dump_db "$db_name" > db.sql +fi #================================================= # SPECIFIC BACKUP diff --git a/scripts/change_url b/scripts/change_url index 23da1c3..a90a093 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -37,6 +37,7 @@ db_pwd=$(ynh_app_setting_get $app psqlpwd) db_user=$db_name secret=$(ynh_app_setting_get $app secret) max_file_size=$(ynh_app_setting_get $app max_file_size) +db_manager=$(ynh_app_setting_get $app db_manager) #================================================= # CHECK THE SYNTAX OF THE PATHS @@ -112,6 +113,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf" ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf" +ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf" if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf" fi diff --git a/scripts/install b/scripts/install index 33afb7c..05be583 100644 --- a/scripts/install +++ b/scripts/install @@ -48,6 +48,9 @@ if ! [[ $max_file_size =~ "^[\-0-9]+$" ]] && [ $max_file_size -lt 0 ]; then ynh_die "Max file must be a number positive or zero" fi +# Use postgresql by default +db_manager="postgresql" + # Check web path availability ynh_webpath_available $domain $path_url # Register (book) web path @@ -73,6 +76,7 @@ ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app port $port ynh_app_setting_set $app path $path_url ynh_app_setting_set $app max_file_size $max_file_size +ynh_app_setting_set $app db_manager $db_manager #================================================= # STANDARD MODIFICATIONS @@ -137,6 +141,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf" ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf" +ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf" if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf" fi diff --git a/scripts/remove b/scripts/remove index 8377d9d..627263d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -63,7 +63,7 @@ ynh_remove_nginx_config # DELETE LOG #================================================= -ynh_secure_remove "/var/log/$app/" +ynh_secure_remove "/var/log/$app" #================================================= # REMOVE LOGROTATE CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 286e393..0bef29a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -32,6 +32,7 @@ domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get $app db_name) +db_manager=$(ynh_app_setting_get $app db_manager) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -79,12 +80,15 @@ ynh_system_user_create $app #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_print_info "Restoring the PostregSQL database..." -db_pwd=$(ynh_app_setting_get $app psqlpwd) -ynh_psql_test_if_first_run -ynh_psql_setup_db $db_name $db_name $db_pwd -ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql +if [ $db_manager = "postgresql" ]; then + ynh_print_info "Restoring the PostregSQL database..." + + db_pwd=$(ynh_app_setting_get $app psqlpwd) + ynh_psql_test_if_first_run + ynh_psql_setup_db $db_name $db_name $db_pwd + ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql +fi #================================================= # RESTORE USER RIGHTS diff --git a/scripts/upgrade b/scripts/upgrade index fb6d1e3..e2dd559 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,6 +26,7 @@ db_name=$(ynh_app_setting_get $app db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get $app psqlpwd) max_file_size=$(ynh_app_setting_get $app max_file_size) +db_manager=$(ynh_app_setting_get $app db_manager) #================================================= # FIX OLD THINGS @@ -59,6 +60,11 @@ if [ -z "$max_file_size" ]; then max_file_size=100 # 100 Mo fi +# If db_manager is empty, use sqlite for a backward compatibility +if [ -z "$db_manager" ]; then + db_manager="sqlite" +fi + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -116,6 +122,7 @@ ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lufi.conf" ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lufi.conf" ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lufi.conf" ynh_replace_string "__MAX_FILE_SIZE__" "$max_file_size" "${final_path}/lufi.conf" +ynh_replace_string "__DB_MANAGER__" "$db_manager" "${final_path}/lufi.conf" if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit ynh_replace_string "max_file_size" "#max_file_size" "${final_path}/lufi.conf" fi @@ -141,7 +148,7 @@ chmod +x $final_path/script/lufi # SECURING FILES AND DIRECTORIES #================================================= -chown -R $app:$app "$final_path" +chown -R $app: "$final_path" #================================================= # SETUP SYSTEMD @@ -156,7 +163,11 @@ ynh_add_systemd_config #================================================= pushd $final_path -carton install --deployment --without=sqlite --without=mysql +if [ $db_manager = "postgresql" ]; then + carton install --deployment --without=sqlite --without=mysql +else + carton install --deployment --without=postgresql --without=mysql +fi popd #================================================= @@ -171,14 +182,21 @@ ynh_use_logrotate --non-append # ADVERTISE SERVICE IN ADMIN PANEL #================================================= +# if /var/log/$app/production.log is a symbolic link, then move it to $final_path/log/production.log +if [ ! -L "/var/log/$app/production.log" ] +then + mv "/var/log/$app/production.log" "$final_path/log/production.log" + chown -R $app: "$final_path/log/production.log" +fi + yunohost service add $app --log "$final_path/log/production.log" #================================================= # RESTART LUFI #================================================= -ynh_systemd_action -n $app -a reload -l "Creating process id file" -p "$final_path/log/production.log" ln -sf "$final_path/log/production.log" "/var/log/$app/production.log" +ynh_systemd_action -n $app -a restart -l "Creating process id file" -p "$final_path/log/production.log" #================================================= # SETUP SSOWAT