1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00
etherpad_mypads_ynh/scripts/restore
2017-09-05 00:11:45 +02:00

161 lines
5.1 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source ../settings/scripts/_variables
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path_url)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
export=$(ynh_app_setting_get $app export)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE OF THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE OF THE MAIN DIR OF THE APP
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE OF THE SQL BDD
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE OF THE DEDICATED USER
#=================================================
ynh_system_user_create $app $final_path # Recreate the dedicated user, if not exist
#=================================================
# SPECIFIC RESTORE
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
mkdir -p /var/log/$app
touch /var/log/$app/etherpad.log
install_log=/var/log/$app/installation.log
touch $install_log
chown $app -R /var/log/$app
chown admin -R $install_log
# Restaure la configuration de logrotate
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
if [ "$export" = "abiword" ]; then
ynh_install_app_dependencies $abiword_app_depencencies
elif [ "$export" = "libreoffice" ]; then
ynh_install_app_dependencies $libreoffice_app_dependencies
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
#=================================================
# INSTALL ETHERPAD DEPENDENCIES
#=================================================
ynh_use_nodejs
npm cache clean
npm install forever -g >> $install_log 2>&1
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/etherpad.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
## Démarrage auto du service
systemctl enable $app.service
#=================================================
# START ETHERPAD IN BACKGROUND
#=================================================
echo "Démarrage d'etherpad" >&2
tempfile="$(mktemp)"
tail -f -n1 /var/log/$app/etherpad.log > "$tempfile" & # Suit le démarrage dans le log
PID_TAIL=$! # Récupère le PID de la commande tail, qui est passée en arrière plan.
systemctl start $app # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx
#=================================================
# CHECK ETHERPAD STARTING
#=================================================
# Surveille le démarrage du service.
for i in `seq 1 60`
do # La boucle attend le démarrage d'etherpad. Ou 1 minute. Cette boucle évite simplement un 502 au début, car le démarrage est long...
if grep -q "You can access your Etherpad instance at" "$tempfile"; then
echo "Le service $app a démarré correctement." >&2
break # Si le log annonce le démarrage d'etherpad, sort de la boucle.
fi
echo -n "." >&2
sleep 1
done
echo ""
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
ynh_secure_remove "$tempfile"