2014-12-09 21:00:17 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2017-03-19 22:50:12 +01:00
|
|
|
source _common.sh
|
2017-03-19 18:28:38 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
2017-09-05 00:20:40 +02:00
|
|
|
# Load common variables for all scripts.
|
|
|
|
source _variables
|
2017-03-19 18:28:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2016-11-30 17:49:37 +01:00
|
|
|
|
|
|
|
# Récupère les infos de l'application.
|
|
|
|
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
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
2015-02-27 14:41:04 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# FIX OLD THINGS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
|
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 0
|
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
# Remove the apt list entry for jenkins
|
|
|
|
if [ -e "/etc/apt/sources.list.d/jenkins.list" ]
|
|
|
|
then
|
|
|
|
ynh_secure_remove /etc/apt/sources.list.d/jenkins.list
|
|
|
|
# Récupère l'id de la clé APT de jenkins
|
|
|
|
apt_key=$(apt-key list | grep -B1 "Kohsuke Kawaguchi" | grep pub | cut -d'/' -f2 | cut -d' ' -f1)
|
|
|
|
apt-key del $apt_key # Supprime la clé APT
|
|
|
|
apt-get update
|
|
|
|
fi
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
2017-12-05 19:30:08 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_clean_setup () {
|
2017-09-05 00:20:40 +02:00
|
|
|
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
|
|
ynh_secure_remove "$tempfile"
|
2017-12-05 19:30:08 +01:00
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
2017-03-19 18:28:38 +01:00
|
|
|
}
|
2017-12-05 19:30:08 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2017-03-19 18:28:38 +01:00
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE JENKINS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
wget --no-verbose https://pkg.jenkins.io/debian-stable/binary/jenkins_${version}_all.deb
|
|
|
|
dpkg --install jenkins_${version}_all.deb
|
|
|
|
|
2017-06-13 19:11:22 +02:00
|
|
|
#=================================================
|
|
|
|
# FIX JENKINS SETUP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$path_url" != "/" ];
|
|
|
|
then # Ajoute le path en cas d'installation en sous-dossier dans les options de démarrage de Jenkins
|
|
|
|
if ! grep --quiet "prefix=$path_url" /etc/default/jenkins
|
|
|
|
then
|
2017-09-05 00:20:40 +02:00
|
|
|
sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins
|
2017-06-13 19:11:22 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2014-12-09 21:00:17 +01:00
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START JENKINS IN BACKGROUND
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Démarre jenkins
|
|
|
|
WARNING echo "Redémarrage de jenkins"
|
|
|
|
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.
|
|
|
|
systemctl restart $app
|
2014-12-16 00:14:01 +01:00
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ $is_public -eq 1 ]
|
2014-12-16 00:14:01 +01:00
|
|
|
then
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
2014-12-16 00:14:01 +01:00
|
|
|
else
|
2017-03-19 18:28:38 +01:00
|
|
|
ynh_app_setting_delete $app unprotected_uris
|
2014-12-16 00:14:01 +01:00
|
|
|
fi
|
|
|
|
|
2017-03-19 18:28:38 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
2017-09-05 00:20:40 +02:00
|
|
|
systemctl reload nginx
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK JENKINS STARTING
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
for i in `seq 1 300`
|
|
|
|
do # La boucle attend le démarrage de jenkins ou 5 minutes
|
|
|
|
if grep -q "Jenkins is fully up and running" "$tempfile"; then
|
|
|
|
WARNING echo "Le service $app a démarré correctement."
|
|
|
|
break # Si le log annonce le démarrage de jenkins, sort de la boucle.
|
|
|
|
fi
|
|
|
|
WARNING echo -n "."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
echo ""
|
|
|
|
QUIET kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
|
|
ynh_secure_remove "$tempfile"
|