mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
152 lines
4.8 KiB
Bash
152 lines
4.8 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
#=================================================
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
if [ ! -e _common.sh ]; then
|
|
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant
|
|
sudo cp ../settings/scripts/_common.sh ./_common.sh
|
|
sudo chmod a+rx _common.sh
|
|
fi
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# 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)
|
|
abiword=$(ynh_app_setting_get $app abiword)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
|
|
sudo 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 nginx.conf
|
|
|
|
#=================================================
|
|
# RESTORE OF THE MAIN DIR OF THE APP
|
|
#=================================================
|
|
|
|
ynh_restore_file sources
|
|
|
|
#=================================================
|
|
# RESTORE OF THE SQL BDD
|
|
#=================================================
|
|
|
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|
ynh_mysql_create_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 # Recreate the dedicated user, if not exist
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORE
|
|
#=================================================
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
#=================================================
|
|
|
|
sudo mkdir -p /var/log/$app
|
|
sudo touch /var/log/$app/etherpad.log
|
|
install_log=/var/log/$app/installation.log
|
|
sudo touch $install_log
|
|
sudo chown $app -R /var/log/$app
|
|
sudo chown admin -R $install_log
|
|
|
|
# Restaure la configuration de logrotate
|
|
ynh_restore_file logrotate
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
|
|
if [ "$abiword" -eq 1 ]
|
|
then
|
|
ynh_install_app_dependencies npm nodejs-legacy abiword
|
|
else
|
|
ynh_install_app_dependencies npm nodejs-legacy
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL ETHERPAD DEPENDENCIES
|
|
#=================================================
|
|
|
|
sudo npm install forever -g >> $install_log 2>&1
|
|
|
|
#=================================================
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
sudo yunohost service add $app --log "/var/log/$app/etherpad.log"
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEMD
|
|
#=================================================
|
|
|
|
ynh_restore_file systemd
|
|
## Démarrage auto du service
|
|
sudo 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.
|
|
sudo systemctl start $app # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
|
|
sudo 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"
|