mirror of
https://github.com/YunoHost-Apps/jenkins_ynh.git
synced 2024-09-03 19:26:18 +02:00
4f31b7624a
Fix install with new deb package Uses last helpers Fix install with alternative port
129 lines
4.1 KiB
Bash
129 lines
4.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
#=================================================
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
set -eu
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
if [ ! -e _common.sh ]; then
|
|
# Rapatrie le fichier de fonctions si il n'est pas dans le dossier courant
|
|
sudo cp ../settings/scripts/_common.sh ./_common.sh
|
|
sudo chmod a+rx _common.sh
|
|
fi
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
#=================================================
|
|
|
|
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
|
|
#=================================================
|
|
|
|
ynh_restore_file nginx.conf
|
|
|
|
# Reload webserver
|
|
sudo systemctl reload nginx
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORE
|
|
#=================================================
|
|
# 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'
|
|
|
|
ynh_install_app_dependencies default-jre-headless
|
|
|
|
#=================================================
|
|
# FIX THE PORT TO USE
|
|
#=================================================
|
|
|
|
change_port() {
|
|
# Wait for the creation of the jenkins service file
|
|
while [ ! -e /etc/default/jenkins ]
|
|
do
|
|
sleep 0.5
|
|
done
|
|
# And modify the port as soon as possible, to prevent a crach of jenkins if the default port is already used.
|
|
ynh_replace_string "^HTTP_PORT=.*" "HTTP_PORT=$port" /etc/default/jenkins
|
|
}
|
|
change_port &
|
|
|
|
#=================================================
|
|
# INSTALL JENKINS
|
|
#=================================================
|
|
|
|
ynh_package_install jenkins
|
|
|
|
#=================================================
|
|
# RESTORE OF THE MAIN DIR OF THE APP
|
|
#=================================================
|
|
|
|
ynh_restore_file sources
|
|
|
|
#=================================================
|
|
# RESTORE OF THE JENKINS' BOOT CONFIG
|
|
#=================================================
|
|
|
|
ynh_secure_remove "/etc/default/jenkins"
|
|
ynh_restore_file etc
|
|
|
|
#=================================================
|
|
# START JENKINS IN BACKGROUND
|
|
#=================================================
|
|
|
|
sudo systemctl restart $app # Redémarre jenkins pour prendre en compte les modifications
|
|
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.
|
|
|
|
#=================================================
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
sudo yunohost service add $app --log "/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# CHECK JENKINS STARTING
|
|
#=================================================
|
|
|
|
# Surveille le démarrage du service.
|
|
for i in `seq 1 120`
|
|
do # La boucle attend le démarrage de jenkins Ou 120 secondes.
|
|
if grep -q "INFOS: 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
|
|
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
|
|
ynh_secure_remove "$tempfile"
|