mirror of
https://github.com/YunoHost-Apps/lstu_ynh.git
synced 2024-09-03 19:36:12 +02:00
update restore script
This commit is contained in:
parent
bec4c2407b
commit
790fb2a42e
1 changed files with 75 additions and 71 deletions
146
scripts/restore
146
scripts/restore
|
@ -1,97 +1,101 @@
|
|||
#!/bin/bash
|
||||
# vim:set noexpandtab:
|
||||
# This restore script is adapted to Yunohost >=2.4
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# Source app helpers
|
||||
source ../settings/scripts/_common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# The parameter $app is the id of the app instance ex: ynhexample__2
|
||||
#=================================================
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_clean_setup () {
|
||||
#### Remove this function if there's nothing to clean before calling the remove script.
|
||||
true
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Get old parameter of the app
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path=$(ynh_app_setting_get $app path)
|
||||
is_public=$(ynh_app_setting_get $app is_public)
|
||||
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)
|
||||
|
||||
ynh_package_update
|
||||
ynh_package_install build-essential libssl-dev libpq-dev
|
||||
echo yes | sudo cpan Carton
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
# Check domain/path availability
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \
|
||||
|| ynh_die "Path not available: ${domain}${path}"
|
||||
ynh_webpath_available $domain $path_url \
|
||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||
test ! -d $final_path \
|
||||
|| ynh_die "There is already a directory: $final_path "
|
||||
|
||||
# Check $final_path
|
||||
final_path="/var/www/${app}"
|
||||
if [ -d "${final_path}" ]; then
|
||||
ynh_die "There is already a directory: ${final_path}"
|
||||
fi
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Check configuration files nginx
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
if [ -f "${nginx_conf}" ]; then
|
||||
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# Check configuration files lstu
|
||||
lstu_conf="${final_path}/${app}.conf"
|
||||
if [ -f "${lstu_conf}" ]; then
|
||||
ynh_die "The LSTU CONF configuration already exists at '${lstu_conf}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
lstu_systemd="/etc/systemd/system/${app}.service"
|
||||
if [ -f "${lstu_systemd}" ]; then
|
||||
ynh_die "The LSTU SYSTEMD configuration already exists at '${lstu_systemd}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
ynh_restore_file "$final_path"
|
||||
|
||||
lstu_logrotate="/etc/logrotate.d/${app}"
|
||||
if [ -f "${lstu_logrotate}" ]; then
|
||||
ynh_die "The LSTU LOGROTATE configuration already exists at '${lstu_logrotate}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
lstu_log="/var/log/${app}/production.log"
|
||||
if [ -f "${lstu_log}" ]; then
|
||||
ynh_die "The LSTU LOG configuration already exists at '${lstu_log}'. You should safely delete it before restoring this app."
|
||||
fi
|
||||
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
||||
ynh_psql_setup_db $db_name $db_name $db_pwd
|
||||
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||
|
||||
# Restore sources & data
|
||||
sudo cp -a ./sources "${final_path}"
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Set permissions
|
||||
sudo chown -R www-data: "${final_path}"
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
|
||||
|
||||
# Restore nginx configuration files
|
||||
sudo cp -a ./nginx.conf "${nginx_conf}"
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
#=================================================
|
||||
|
||||
# Restore lstu configuration files
|
||||
sudo cp -a ./lstu.conf "${lstu_conf}"
|
||||
ynh_restore_file "/etc/systemd/system/$app.service"
|
||||
systemctl enable $app.service
|
||||
systemctl start $app
|
||||
|
||||
# Restore service
|
||||
sudo cp -a ./systemd_lstu.service "${lstu_systemd}"
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
||||
sudo cp -a ./logrotate_lstu "${lstu_logrotate}"
|
||||
yunohost service add $app --log "/var/log/$app.log"
|
||||
|
||||
# Create log production
|
||||
sudo mkdir "/var/log/${app}/"
|
||||
sudo cp -a ./production.log "${lstu_log}"
|
||||
# Delete symbolic link and restore
|
||||
sudo rm -fr "${final_path}/log/production.log"
|
||||
sudo ln -s "/var/log/${app}/production.log" "${final_path}/log/production.log"
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Reload lstu service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl start lstu.service
|
||||
sudo systemctl enable lstu.service
|
||||
ynh_restore_file "/etc/logrotate.d/$app"
|
||||
|
||||
# Set ssowat config
|
||||
if [ $is_public -eq 0 ];
|
||||
then
|
||||
ynh_app_setting_delete $app skipped_uris
|
||||
fi
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
# Reload services
|
||||
sudo systemctl reload nginx
|
||||
sudo yunohost app ssowatconf
|
||||
systemctl reload nginx
|
||||
yunohost app ssowatconf
|
||||
|
|
Loading…
Add table
Reference in a new issue