2015-11-18 00:28:42 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
2017-09-05 00:25:58 +02:00
|
|
|
# GENERIC START
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-11-08 13:33:28 +01:00
|
|
|
|
2017-03-21 00:44:14 +01:00
|
|
|
if [ ! -e _common.sh ]; then
|
2017-09-05 00:25:58 +02:00
|
|
|
# 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
|
2017-03-19 19:16:10 +01:00
|
|
|
fi
|
2017-03-21 00:44:14 +01:00
|
|
|
source _common.sh
|
2016-12-14 16:10:00 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-09-05 00:25:58 +02:00
|
|
|
# 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
|
2016-12-14 16:10:00 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-12-14 16:10:00 +01:00
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-03-19 19:16:10 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
2017-03-19 19:16:10 +01:00
|
|
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die "There is already a directory: $final_path "
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORE STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-06-13 17:11:57 +02:00
|
|
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE MAIN DIR OF THE APP
|
|
|
|
#=================================================
|
2016-12-14 16:10:00 +01:00
|
|
|
|
2017-06-13 17:11:57 +02:00
|
|
|
ynh_restore_file "$final_path"
|
2016-12-14 16:10:00 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# RECREATE OF THE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app # Recreate the dedicated user, if not exist
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
# Les fichiers appartiennent à root
|
2017-09-05 00:25:58 +02:00
|
|
|
chown -R $app: $final_path
|
2016-08-05 16:59:55 +02:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
ynh_install_app_dependencies $app_depencencies
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
yunohost service add $app --log "/var/log/$app/APP.log"
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-13 17:11:57 +02:00
|
|
|
ynh_restore_file "/etc/systemd/system/$app.service"
|
2017-03-19 19:16:10 +01:00
|
|
|
## Démarrage auto du service
|
2017-09-05 00:25:58 +02:00
|
|
|
systemctl enable $app.service
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE CRON FILE
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-13 17:11:57 +02:00
|
|
|
ynh_restore_file "/etc/cron.d/$app"
|
2017-03-19 19:16:10 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOG FILE
|
|
|
|
#=================================================
|
2015-11-18 00:28:42 +01:00
|
|
|
|
2016-08-05 16:59:55 +02:00
|
|
|
# Making log symbolic link to /var/log
|
2017-09-05 00:25:58 +02:00
|
|
|
mkdir -p /var/log/$app/
|
|
|
|
touch /var/log/$app/production.log
|
|
|
|
chown $app: -R /var/log/$app
|
2017-03-19 19:16:10 +01:00
|
|
|
|
2017-04-19 19:23:23 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-13 17:11:57 +02:00
|
|
|
ynh_restore_file "/etc/logrotate.d/$app"
|
2016-05-15 11:36:31 +02:00
|
|
|
|
2017-03-19 19:16:10 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2016-08-05 16:59:55 +02:00
|
|
|
|
2017-09-05 00:25:58 +02:00
|
|
|
systemctl reload nginx
|
2017-05-24 16:48:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START AND CHECK LUTIM BOOTING
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
tempfile="$(mktemp)"
|
|
|
|
tail -f -n1 /var/log/$app/production.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.
|
2017-09-05 00:25:58 +02:00
|
|
|
systemctl restart $app # Démarre lutim
|
2017-05-24 16:48:26 +02:00
|
|
|
|
|
|
|
for i in `seq 1 60`
|
|
|
|
do # La boucle attend le démarrage de lutim. Ou 1 minute. Cette boucle évite simplement un 502 au début, car le démarrage est parfois long...
|
|
|
|
if grep -q "Manager.*started" "$tempfile"; then
|
|
|
|
WARNING echo "Le service $app a démarré correctement."
|
|
|
|
break # Si le log annonce le démarrage de lutim, sort de la boucle.
|
|
|
|
fi
|
|
|
|
WARNING echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
QUIET kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
|
|
ynh_secure_remove "$tempfile"
|