2016-11-30 17:49:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ ! -e .fonctions ]; then
|
|
|
|
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant
|
|
|
|
sudo cp ../settings/scripts/.fonctions ./.fonctions
|
|
|
|
sudo chmod a+rx .fonctions
|
|
|
|
fi
|
|
|
|
source .fonctions
|
2016-11-30 17:49:37 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2016-11-30 17:55:46 +01:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-03-19 18:28:38 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2016-11-30 17:55:46 +01:00
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
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
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
|
|
|
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
if [ -f $conf ]; then
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_die "There is already a nginx conf file at this path: $conf"
|
2016-11-30 17:49:37 +01:00
|
|
|
fi
|
2017-03-19 18:28:38 +01:00
|
|
|
sudo cp -a ./nginx.conf $conf
|
|
|
|
|
|
|
|
# Reload webserver
|
|
|
|
sudo systemctl reload nginx
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
|
|
|
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'
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_install_app_dependencies default-jre-headless jenkins
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE MAIN DIR OF THE APP
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
sudo cp -a ./sources/. $final_path
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE JENKINS' BOOT CONFIG
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
sudo cp -a ./etc /etc/default/$app
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START JENKINS IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
sudo systemctl restart $app # 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
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
2016-11-30 17:49:37 +01:00
|
|
|
sudo yunohost service add $app --log "/var/log/$app/$app.log"
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK JENKINS STARTING
|
|
|
|
#=================================================
|
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
|
2017-03-19 18:28:38 +01:00
|
|
|
WARNING echo "Le service $app a démarré correctement."
|
2016-11-30 17:55:46 +01:00
|
|
|
break # Si le log annonce le démarrage de jenkins, sort de la boucle.
|
|
|
|
fi
|
2017-03-19 18:28:38 +01:00
|
|
|
WARNING echo -n "."
|
2016-11-30 17:55:46 +01:00
|
|
|
sleep 1
|
|
|
|
done
|
2017-03-19 18:28:38 +01:00
|
|
|
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
2016-11-30 17:55:46 +01:00
|
|
|
sudo rm "$tempfile"
|