1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jenkins_ynh.git synced 2024-09-03 19:26:18 +02:00
jenkins_ynh/scripts/restore

67 lines
2.1 KiB
Text
Raw Normal View History

2016-11-30 17:49:37 +01:00
#!/bin/bash
# Récupère les infos de l'application.
app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
2016-11-30 17:55:46 +01:00
domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
2016-11-30 17:49:37 +01:00
if [ -d $final_path ]; then
2016-11-30 17:55:46 +01:00
ynh_die "There is already a directory: $final_path"
2016-11-30 17:49:37 +01:00
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
2016-11-30 17:55:46 +01:00
ynh_die "There is already a nginx conf file at this path: $conf"
2016-11-30 17:49:37 +01:00
fi
sudo cp -a $backup_dir/nginx.conf $conf
# Restore YunoHost parameters
sudo cp -a $backup_dir/yunohost/. /etc/yunohost/apps/$app
echo "Reinstall dependencies..."
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
2016-11-30 17:51:05 +01:00
sudo apt-get install default-jre-headless -y
2016-11-30 17:49:37 +01:00
sudo apt-get install jenkins -y
# Restore sources & data
sudo cp -a "$backup_dir/sources/." $final_path
# Restauration de la configuration de démarrage de Jenkins
2016-11-30 17:55:46 +01:00
sudo cp -a $backup_dir/etc /etc/default/$app
2016-11-30 17:49:37 +01:00
sudo service $app restart # Redémarre jenkins pour prendre en compte les modifications
2016-11-30 17:55:46 +01:00
tempfile="$(mktemp)"
tail -f -n1 /var/log/$app/$app.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.
2016-11-30 17:49:37 +01:00
# Ajoute le service au monitoring de Yunohost.
sudo yunohost service add $app --log "/var/log/$app/$app.log"
# Reload webserver
sudo service nginx reload
2016-11-30 17:55:46 +01:00
# Surveille le démarrage du service.
2016-12-17 19:52:21 +01:00
for i in `seq 1 120`
do # La boucle attend le démarrage de jenkins Ou 120 secondes.
2016-11-30 17:55:46 +01:00
if grep -q "INFOS: Jenkins is fully up and running" "$tempfile"; then
2016-12-17 19:52:21 +01:00
echo "Le service $app a démarré correctement." >&2
2016-11-30 17:55:46 +01:00
break # Si le log annonce le démarrage de jenkins, sort de la boucle.
fi
echo -n "." >&2
sleep 1
done
kill -s 15 $PID_TAIL > /dev/null # Arrête l'exécution de tail.
sudo rm "$tempfile"