#!/bin/bash # Source app helpers source /usr/share/yunohost/helpers # Récupère les infos de l'application. app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) final_path=$(ynh_app_setting_get $app final_path) if [ -d $final_path ]; then ynh_die "There is already a directory: $final_path" 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 ynh_die "There is already a nginx conf file at this path: $conf" 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 le dossier de log 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 etherpad -R /var/log/$app sudo chown admin -R $install_log # Installation de npm et nodejs sudo apt-get update sudo apt-get install npm nodejs-legacy -qy # Installe les dépendances de etherpad # sudo "$final_path/bin/installDeps.sh" > $install_log 2>&1 sudo npm install forever -g >> $install_log 2>&1 # Créer la base de donnée et la restaure db_pwd=$(ynh_app_setting_get $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 # ADD_SYS_USER # Créer un user système dédié pour l'application if ! ynh_system_user_exists "$app" # Test l'existence de l'utilisateur then sudo useradd -d /var/www/$app --system --user-group $app --shell /usr/sbin/nologin || (echo "Unable to create $app system account" >&2 && false) fi # 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 --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 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 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" sudo cat /var/log/$app/etherpad.log >&2