mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
82 lines
2.6 KiB
Bash
82 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Source app helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Récupère les infos de l'application.
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
domain=$(sudo yunohost app setting $app domain)
|
|
final_path=$(sudo yunohost app setting $app final_path)
|
|
|
|
if [ -d $final_path ]; then
|
|
echo "There is already a directory: $final_path " >&2
|
|
exit 1
|
|
fi
|
|
|
|
# The parameter $1 is the uncompressed restore directory location
|
|
backup_dir=$1/apps/$app
|
|
|
|
# Restore Nginx
|
|
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
if [ -f $conf ]; then
|
|
echo "There is already a nginx conf file at this path: $conf " >&2
|
|
exit 1
|
|
fi
|
|
sudo cp -a $backup_dir/nginx.conf $conf
|
|
|
|
# Restore YunoHost parameters
|
|
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
|
|
|
|
# Restore sources & data
|
|
sudo cp -a "$backup_dir/sources/." $final_path
|
|
|
|
# Créer la base de donnée et la restaure
|
|
db_pwd=$(sudo yunohost app setting $app mysqlpwd)
|
|
db_user=$app
|
|
ynh_mysql_create_db $db_user $db_user $db_pwd
|
|
mysql --debug-check -u $db_user -p$db_pwd $db_user < ${backup_dir}/db.sql
|
|
|
|
# Créer l'user etherpad
|
|
if ! grep -q "^etherpad:" /etc/passwd # Test l'existence de l'utilisateur
|
|
then # Si il n'existe pas, l'user etherpad est créé
|
|
sudo useradd etherpad -r
|
|
fi
|
|
|
|
# Créer le dossier de log
|
|
sudo mkdir -p /var/log/$app
|
|
sudo touch /var/log/$app/etherpad.log
|
|
sudo chown etherpad -R /var/log/$app
|
|
|
|
# Restaure la configuration de logrotate
|
|
sudo cp -a $backup_dir/logrotate /etc/logrotate.d/$app
|
|
|
|
# Ajoute le service au monitoring de Yunohost.
|
|
sudo yunohost service add $app.service --log "/var/log/$app/etherpad.log"
|
|
|
|
# Restauration des fichiers du script systemd
|
|
sudo cp -a $backup_dir/$app.service /etc/systemd/system/$app.service
|
|
## Démarrage auto du service
|
|
sudo systemctl enable $app.service
|
|
|
|
# Démarre etherpad
|
|
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 service $app start # Démarre etherpad. Le démarrage est fait le plus tôt possible, car il est très long...
|
|
|
|
# Reload webserver
|
|
sudo service nginx reload
|
|
|
|
# Surveille le démarrage du service.
|
|
for i in `seq 1 20`
|
|
do # La boucle attend le démarrage d'etherpad. Ou 20 secondes. 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
|
|
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.
|
|
sudo rm "$tempfile"
|