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

Use new helpers

This commit is contained in:
Maniack Crudelis 2017-12-16 23:20:29 +01:00
parent 205edf60c3
commit 15b66671e7
9 changed files with 478 additions and 212 deletions

View file

@ -6,7 +6,7 @@
"en": "Extendable continuous integration server", "en": "Extendable continuous integration server",
"fr": "Serveur d'intégration continue extensible" "fr": "Serveur d'intégration continue extensible"
}, },
"version": "2.46.3", "version": "2.46.3~ynh1",
"url": "https://jenkins.io/index.html", "url": "https://jenkins.io/index.html",
"license": "MIT", "license": "MIT",
"maintainer": { "maintainer": {

View file

@ -1,31 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# DISPLAYING
#=================================================
NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument.
set +x
$@
set -x
}
WARNING () { # Écrit sur le canal d'erreur pour passer en warning.
$@ >&2
}
SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard
$@ 2>&1
}
QUIET () { # Redirige la sortie standard dans /dev/null
$@ > /dev/null
}
ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null
$@ > /dev/null 2>&1
}
#================================================= #=================================================
# BACKUP # BACKUP
#================================================= #=================================================
@ -42,8 +16,8 @@ CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
if [ $free_space -le $backup_size ] if [ $free_space -le $backup_size ]
then then
WARNING echo "Espace insuffisant pour sauvegarder $file_to_analyse." ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
WARNING echo "Espace disponible: $(HUMAN_SIZE $free_space)" ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)" ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
fi fi
} }
@ -57,7 +31,7 @@ IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé)
} }
#================================================= #=================================================
# NODEJS # EXPERIMENTAL HELPERS
#================================================= #=================================================
# INFOS # INFOS
@ -234,6 +208,344 @@ EOF
chmod +x "/etc/cron.daily/node_update" chmod +x "/etc/cron.daily/node_update"
} }
#=================================================
# Start or restart a service and follow its booting
#
# usage: ynh_check_starting "Line to match" [Log file] [Timeout]
#
# | arg: Line to match - The line to find in the log to attest the service have finished to boot.
# | arg: Log file - The log file to watch
# /var/log/$app/$app.log will be used if no other log is defined.
# | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
ynh_check_starting () {
local line_to_match="$1"
local app_log="${2:-/var/log/$app/$app.log}"
local timeout=${3:-300}
ynh_clean_check_starting () {
# Stop the execution of tail.
kill -s 15 $pid_tail 2>&1
ynh_secure_remove "$templog" 2>&1
}
echo "Starting of $app" >&2
systemctl restart $app
local templog="$(mktemp)"
# Following the starting of the app in its log
tail -f -n1 "$app_log" > "$templog" &
# Get the PID of the tail command
local pid_tail=$!
local i=0
for i in `seq 1 $timeout`
do
# Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
if grep --quiet "$line_to_match" "$templog"
then
echo "The service $app has correctly started." >&2
break
fi
echo -n "." >&2
sleep 1
done
if [ $i -eq $timeout ]
then
echo "The service $app didn't fully started before the timeout." >&2
fi
echo ""
ynh_clean_check_starting
}
#=================================================
ynh_print_log () {
echo "${1}"
}
# Print an info on stdout
#
# usage: ynh_print_info "Text to print"
# | arg: text - The text to print
ynh_print_info () {
ynh_print_log "[INFO] ${1}"
}
# Print a warning on stderr
#
# usage: ynh_print_warn "Text to print"
# | arg: text - The text to print
ynh_print_warn () {
ynh_print_log "[WARN] ${1}" >&2
}
# Print a error on stderr
#
# usage: ynh_print_err "Text to print"
# | arg: text - The text to print
ynh_print_err () {
ynh_print_log "[ERR] ${1}" >&2
}
# Execute a command and print the result as an error
#
# usage: ynh_exec_err command to execute
# usage: ynh_exec_err "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_err () {
ynh_print_err "$(eval $@)"
}
# Execute a command and print the result as a warning
#
# usage: ynh_exec_warn command to execute
# usage: ynh_exec_warn "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_warn () {
ynh_print_warn "$(eval $@)"
}
# Execute a command and force the result to be printed on stdout
#
# usage: ynh_exec_warn_less command to execute
# usage: ynh_exec_warn_less "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_warn_less () {
eval $@ 2>&1
}
# Execute a command and redirect stdout in /dev/null
#
# usage: ynh_exec_quiet command to execute
# usage: ynh_exec_quiet "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_quiet () {
eval $@ > /dev/null
}
# Execute a command and redirect stdout and stderr in /dev/null
#
# usage: ynh_exec_fully_quiet command to execute
# usage: ynh_exec_fully_quiet "command to execute | following command"
# In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
#
# | arg: command - command to execute
ynh_exec_fully_quiet () {
eval $@ > /dev/null 2>&1
}
#=================================================
# Install or update the main directory yunohost.multimedia
#
# usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () {
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip 2>&1
unzip -q master.zip
./yunohost.multimedia-master/script/ynh_media_build.sh
}
# Add a directory in yunohost.multimedia
# This "directory" will be a symbolic link to a existing directory.
#
# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
#
# | arg: Source directory - The real directory which contains your medias.
# | arg: Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
ynh_multimedia_addfolder () {
local source_dir="$1"
local dest_dir="$2"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
}
# Move a directory in yunohost.multimedia, and replace by a symbolic link
#
# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
#
# | arg: Source directory - The real directory which contains your medias.
# It will be moved to "Destination directory"
# A symbolic link will replace it.
# | arg: Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
ynh_multimedia_movefolder () {
local source_dir="$1"
local dest_dir="$2"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
}
# Allow an user to have an write authorisation in multimedia directories
#
# usage: ynh_multimedia_addaccess user_name
#
# | arg: user_name - The name of the user which gain this access.
ynh_multimedia_addaccess () {
local user_name=$1
groupadd -f multimedia
usermod -a -G multimedia $user_name
}
#=================================================
# Create a dedicated fail2ban config (jail and filter conf files)
#
# usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]]
# | arg: log_file - Log file to be checked by fail2ban
# | arg: failregex - Failregex to be looked for by fail2ban
# | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3
# | arg: ports - Ports blocked for a banned IP address - default: http,https
ynh_add_fail2ban_config () {
# Process parameters
logpath=$1
failregex=$2
max_retry=${3:-3}
ports=${4:-http,https}
test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
sudo tee $finalfail2banjailconf <<EOF
[$app]
enabled = true
port = $ports
filter = $app
logpath = $logpath
maxretry = $max_retry"
EOF
sudo tee $finalfail2banfilterconf <<EOF
[INCLUDES]
before = common.conf
[Definition]
failregex = $failregex
ignoreregrex ="
EOF
ynh_store_file_checksum "$finalfail2banjailconf"
ynh_store_file_checksum "$finalfail2banfilterconf"
sudo systemctl restart fail2ban
}
# Remove the dedicated fail2ban config (jail and filter conf files)
#
# usage: ynh_remove_fail2ban_config
ynh_remove_fail2ban_config () {
ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
sudo systemctl restart fail2ban
}
#=================================================
# Read the value of a key in a ynh manifest file
#
# usage: ynh_read_manifest manifest key
# | arg: manifest - Path of the manifest to read
# | arg: key - Name of the key to find
ynh_read_manifest () {
manifest="$1"
key="$2"
python3 -c "import sys, json;print(json.load(open('$manifest'))['$key'])"
}
# Exit without error if the package is up to date
#
# This helper should be used to avoid an upgrade of a package
# when it's not needed.
#
# To force an upgrade, even if the package is up to date,
# you have to set the variable YNH_FORCE_UPGRADE before.
# example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
#
# usage: ynh_abort_if_up_to_date
ynh_abort_if_up_to_date () {
local force_upgrade=${YNH_FORCE_UPGRADE:-0}
local package_check=${PACKAGE_CHECK_EXEC:-0}
local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0)
local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0)
if [ "$version" = "$last_version" ]
then
if [ "$force_upgrade" != "0" ]
then
echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
unset YNH_FORCE_UPGRADE
elif [ "$package_check" != "0" ]
then
echo "Upgrade forced for package check." >&2
else
ynh_die "Up-to-date, nothing to do" 0
fi
fi
}
#=================================================
# Send an email to inform the administrator
#
# usage: ynh_send_readme_to_admin app_message [recipients]
# | arg: app_message - The message to send to the administrator.
# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
# example: "root admin@domain"
# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
# example: "root admin@domain user1 user2"
ynh_send_readme_to_admin() {
local app_message="${1:-...No specific informations...}"
local recipients="${2:-root}"
# Retrieve the email of users
find_mails () {
local list_mails="$1"
local mail
local recipients=" "
# Read each mail in argument
for mail in $list_mails
do
# Keep root or a real email address as it is
if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
then
recipients="$recipients $mail"
else
# But replace an user name without a domain after by its email
if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
then
recipients="$recipients $mail"
fi
fi
done
echo "$recipients"
}
recipients=$(find_mails "$recipients")
local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
local mail_message="This is an automated message from your beloved YunoHost server.
Specific informations for the application $app.
$app_message
---
Automatic diagnosis data from YunoHost
$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
# Send the email to the recipients
echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
}
#================================================= #=================================================
#============= FUTURE YUNOHOST HELPER ============ #============= FUTURE YUNOHOST HELPER ============

51
scripts/_sed Normal file
View file

@ -0,0 +1,51 @@
#!/bin/bash
# https://github.com/YunoHost/yunohost/pull/394
# Substitute/replace a string (or expression) by another in a file
#
# usage: ynh_replace_string match_string replace_string target_file
# | arg: match_string - String to be searched and replaced in the file
# | arg: replace_string - String that will replace matches
# | arg: target_file - File in which the string will be replaced.
#
# As this helper is based on sed command, regular expressions and
# references to sub-expressions can be used
# (see sed manual page for more information)
ynh_replace_string () {
local delimit=@
local match_string=$1
local replace_string=$2
local workfile=$3
# Escape the delimiter if it's in the string.
match_string=${match_string//${delimit}/"\\${delimit}"}
replace_string=${replace_string//${delimit}/"\\${delimit}"}
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
}
# Substitute/replace a password by another in a file
#
# usage: ynh_replace_password_string match_string replace_string target_file
# | arg: match_string - String to be searched and replaced in the file
# | arg: replace_string - String that will replace matches
# | arg: target_file - File in which the string will be replaced.
#
# This helper will use ynh_replace_string, but as you can use special
# characters, you can't use some regular expressions and sub-expressions.
ynh_replace_password_string () {
local match_string=$1
local replace_string=$2
local workfile=$3
# Escape any backslash to preserve them as simple backslash.
match_string=${match_string//\\/"\\\\"}
replace_string=${replace_string//\\/"\\\\"}
# Escape the & character, who has a special function in sed.
match_string=${match_string//&/"\&"}
replace_string=${replace_string//&/"\&"}
ynh_replace_string "$match_string" "$replace_string" "$workfile"
}

View file

@ -20,8 +20,7 @@ source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_clean_setup () { ynh_clean_setup () {
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. ynh_clean_check_starting
ynh_secure_remove "$tempfile"
} }
ynh_abort_if_errors ynh_abort_if_errors
@ -60,30 +59,9 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup /etc/default/$app ynh_backup /etc/default/$app
#=================================================
# 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
#================================================= #=================================================
# CHECK JENKINS STARTING # CHECK JENKINS STARTING
#================================================= #=================================================
for i in `seq 1 300` # Wait for Jenkins fully started
do # La boucle attend le démarrage de jenkins ou 5 minutes ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "300"
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"

View file

@ -51,8 +51,7 @@ fi
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. ynh_clean_check_starting
ynh_secure_remove "$tempfile"
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -122,31 +121,11 @@ fi
# RESTART JENKINS IN BACKGROUND # RESTART JENKINS IN BACKGROUND
#================================================= #=================================================
WARNING echo "Redémarrage de jenkins" # Wait for Jenkins fully started
tempfile="$(mktemp)" ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "300"
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
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl reload nginx 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"

View file

@ -10,6 +10,7 @@ source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Load common variables for all scripts. # Load common variables for all scripts.
source _variables source _variables
source _sed
#================================================= #=================================================
# MANAGE FAILURE OF THE SCRIPT # MANAGE FAILURE OF THE SCRIPT
@ -17,17 +18,11 @@ source _variables
ynh_clean_setup () { ynh_clean_setup () {
# Nettoyage des résidus d'installation non pris en charge par le script remove. # Nettoyage des résidus d'installation non pris en charge par le script remove.
if test -n "$PID_TAIL" ynh_clean_check_starting
then ynh_exec_warn_less kill -s 15 $pid_change_port # Arrête l'exécution de change_port
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
SUPPRESS_WARNING kill -s 15 $pid_change_port # Arrête l'exécution de change_port
ynh_secure_remove "$tempfile"
fi
# Clean hosts # Clean hosts
sed -i '/#jenkins/d' /etc/hosts sed -i '/#jenkins/d' /etc/hosts
echo ""
} }
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée. ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
@ -123,15 +118,6 @@ then # Ajoute le path en cas d'installation en sous-dossier dans les options de
sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins sed -i "$ s@--httpPort=\$HTTP_PORT@& --prefix=$path_url@g" /etc/default/jenkins
fi fi
#=================================================
# START JENKINS IN BACKGROUND
#=================================================
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.
#================================================= #=================================================
# FORCE PUBLIC ACCESS # FORCE PUBLIC ACCESS
#================================================= #=================================================
@ -158,71 +144,55 @@ echo "127.0.0.1 $domain #jenkins" | tee -a /etc/hosts # Renseigne le domain dans
jenkins_cli="java -jar /var/lib/jenkins/jenkins-cli.jar -remoting -s http://$domain$path_url" jenkins_cli="java -jar /var/lib/jenkins/jenkins-cli.jar -remoting -s http://$domain$path_url"
# Wait for Jenkins fully started
ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "$timeout"
# Si le log annonce une première fois le démarrage de jenkins. Installe les plugins
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar
for i in `seq 1 $timeout` for i in `seq 1 $timeout`
do # La boucle attend le démarrage de jenkins Ou $timeout (Le démarrage sur arm est trèèèèèèèèès long...). do # La boucle attend la mise à jour des dépôts de plugins.
if grep -q "Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 0 ]; then if test -e /var/lib/jenkins/updates/default.json; then
# Si le log annonce une première fois le démarrage de jenkins. Installe les plugins break;
wget -nv --no-check-certificate https://$domain$path_url/jnlpJars/jenkins-cli.jar -O /var/lib/jenkins/jenkins-cli.jar else
WARNING echo "" echo -n "."
for i in `seq 1 $timeout` sleep 1
do # La boucle attend la mise à jour des dépôts de plugins.
if test -e /var/lib/jenkins/updates/default.json; then
break;
else
WARNING echo -n "."
sleep 1
fi
done
# Installation du plugin pour l'authentification ldap et http auth
$jenkins_cli install-plugin reverse-proxy-auth-plugin
# Installation des plugins recommandés (Lors de l'install avec le Setup Wizard)
$jenkins_cli install-plugin cloudbees-folder # Folders Plugin
$jenkins_cli install-plugin antisamy-markup-formatter # OWASP Markup Formatter Plugin
$jenkins_cli install-plugin pam-auth # PAM Authentication plugin
$jenkins_cli install-plugin mailer # Mailer Plugin
$jenkins_cli install-plugin ldap # LDAP Plugin
$jenkins_cli install-plugin matrix-auth # Matrix Authorization Strategy Plugin
$jenkins_cli install-plugin build-timeout # Build timeout plugin
$jenkins_cli install-plugin credentials-binding # Credentials Binding Plugin
$jenkins_cli install-plugin timestamper # Timestamper
$jenkins_cli install-plugin ws-cleanup # Workspace Cleanup Plugin
$jenkins_cli install-plugin ant # Ant Plugin
$jenkins_cli install-plugin gradle # Gradle Plugin
$jenkins_cli install-plugin workflow-aggregator # Pipeline
$jenkins_cli install-plugin pipeline-stage-view # Pipeline: Stage View Plugin
$jenkins_cli install-plugin git # Git plugin
$jenkins_cli install-plugin github-organization-folder # GitHub Organization Folder Plugin
$jenkins_cli install-plugin subversion # Subversion Plug-in
$jenkins_cli install-plugin email-ext # Email Extension Plugin
$jenkins_cli install-plugin ssh-slaves # SSH Slaves plugin
# Installation de plugins supplémentaires pour le confort
$jenkins_cli install-plugin ansicolor # Prise en charge des couleurs pour la sortie console. Améliore la lisibilité de la console (par contre les couleurs ne passent pas...)
$jenkins_cli install-plugin fstrigger # Monitoring sur le système de fichier local. Pour surveiller des dossiers de code et builder sur les changements.
# Configure la sécurité globale avec ldap par défaut.
cp ../conf/config.xml /var/lib/jenkins/
chown jenkins: /var/lib/jenkins/config.xml
systemctl restart $app # Puis redémarre à nouveau le service.
cat /dev/null > "$tempfile" # Purge le log de suivi du démarrage.
config_OK=1
i=1;
fi fi
if grep -q "Jenkins is fully up and running" "$tempfile" && [ "$config_OK" -eq 1 ]; then
WARNING echo "Le service $app a démarré correctement."
break # Si le log annonce une deuxième fois le démarrage de jenkins, sort de la boucle.
fi
WARNING echo -n "."
sleep 1
done done
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
ynh_secure_remove "$tempfile" # Installation du plugin pour l'authentification ldap et http auth
if [ "$i" -ge $timeout ]; then $jenkins_cli install-plugin reverse-proxy-auth-plugin
ynh_die "\nLe service $app n'a pas démarré dans le temps imparti."
fi # Installation des plugins recommandés (Lors de l'install avec le Setup Wizard)
$jenkins_cli install-plugin cloudbees-folder # Folders Plugin
$jenkins_cli install-plugin antisamy-markup-formatter # OWASP Markup Formatter Plugin
$jenkins_cli install-plugin pam-auth # PAM Authentication plugin
$jenkins_cli install-plugin mailer # Mailer Plugin
$jenkins_cli install-plugin ldap # LDAP Plugin
$jenkins_cli install-plugin matrix-auth # Matrix Authorization Strategy Plugin
$jenkins_cli install-plugin build-timeout # Build timeout plugin
$jenkins_cli install-plugin credentials-binding # Credentials Binding Plugin
$jenkins_cli install-plugin timestamper # Timestamper
$jenkins_cli install-plugin ws-cleanup # Workspace Cleanup Plugin
$jenkins_cli install-plugin ant # Ant Plugin
$jenkins_cli install-plugin gradle # Gradle Plugin
$jenkins_cli install-plugin workflow-aggregator # Pipeline
$jenkins_cli install-plugin pipeline-stage-view # Pipeline: Stage View Plugin
$jenkins_cli install-plugin git # Git plugin
$jenkins_cli install-plugin github-organization-folder # GitHub Organization Folder Plugin
$jenkins_cli install-plugin subversion # Subversion Plug-in
$jenkins_cli install-plugin email-ext # Email Extension Plugin
$jenkins_cli install-plugin ssh-slaves # SSH Slaves plugin
# Installation de plugins supplémentaires pour le confort
$jenkins_cli install-plugin ansicolor # Prise en charge des couleurs pour la sortie console. Améliore la lisibilité de la console (par contre les couleurs ne passent pas...)
$jenkins_cli install-plugin fstrigger # Monitoring sur le système de fichier local. Pour surveiller des dossiers de code et builder sur les changements.
# Configure la sécurité globale avec ldap par défaut.
cp ../conf/config.xml /var/lib/jenkins/
chown jenkins: /var/lib/jenkins/config.xml
# Wait for Jenkins fully started
ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "$timeout"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -240,3 +210,11 @@ fi
#================================================= #=================================================
sed -i '/#jenkins/d' /etc/hosts sed -i '/#jenkins/d' /etc/hosts
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
ynh_send_readme_to_admin "$message" "$admin root"

View file

@ -25,7 +25,7 @@ domain=$(ynh_app_setting_get $app domain)
if yunohost service status | grep -q $app # Test l'existence du service dans Yunohost if yunohost service status | grep -q $app # Test l'existence du service dans Yunohost
then then
echo "Remove $app service" ynh_print_info "Remove $app service" >&2
yunohost service remove $app yunohost service remove $app
fi fi

View file

@ -22,12 +22,7 @@ source ../settings/scripts/_variables
ynh_clean_setup () { ynh_clean_setup () {
# Nettoyage des résidus d'installation non pris en charge par le script remove. # Nettoyage des résidus d'installation non pris en charge par le script remove.
if test -n "$PID_TAIL" ynh_clean_check_starting
then
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
SUPPRESS_WARNING kill -s 15 $pid_change_port # Arrête l'exécution de change_port
ynh_secure_remove "$tempfile"
fi
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -47,7 +42,7 @@ port=$(ynh_app_setting_get $app port)
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
#================================================= #=================================================
yunohost app checkurl "${domain}${path_url}" -a "$app" \ ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}" || ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \ test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path " || ynh_die "There is already a directory: $final_path "
@ -107,15 +102,6 @@ ynh_restore_file "$final_path"
ynh_secure_remove "/etc/default/jenkins" ynh_secure_remove "/etc/default/jenkins"
ynh_restore_file /etc/default/$app ynh_restore_file /etc/default/$app
#=================================================
# START JENKINS IN BACKGROUND
#=================================================
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 # ENABLE SERVICE IN ADMIN PANEL
#================================================= #=================================================
@ -126,15 +112,13 @@ yunohost service add $app --log "/var/log/$app/$app.log"
# CHECK JENKINS STARTING # CHECK JENKINS STARTING
#================================================= #=================================================
# Surveille le démarrage du service. # Wait for Jenkins fully started
for i in `seq 1 120` ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "300"
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." # SEND A README FOR THE ADMIN
break # Si le log annonce le démarrage de jenkins, sort de la boucle. #=================================================
fi
WARNING echo -n "." message="If you facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/jenkins_ynh"
sleep 1
done ynh_send_readme_to_admin "$message" "$admin root"
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail.
ynh_secure_remove "$tempfile"

View file

@ -23,6 +23,12 @@ path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public) is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port) port=$(ynh_app_setting_get $app port)
#=================================================
# CHECK VERSION
#=================================================
ynh_abort_if_up_to_date
#================================================= #=================================================
# FIX OLD THINGS # FIX OLD THINGS
#================================================= #=================================================
@ -52,8 +58,7 @@ fi
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
SUPPRESS_WARNING kill -s 15 $PID_TAIL # Arrête l'exécution de tail. ynh_clean_check_starting
ynh_secure_remove "$tempfile"
# restore it if the upgrade fails # restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -85,17 +90,6 @@ fi
ynh_add_nginx_config 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
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
#================================================= #=================================================
@ -117,15 +111,5 @@ systemctl reload nginx
# CHECK JENKINS STARTING # CHECK JENKINS STARTING
#================================================= #=================================================
for i in `seq 1 300` # Wait for Jenkins fully started
do # La boucle attend le démarrage de jenkins ou 5 minutes ynh_check_starting "Jenkins is fully up and running" "/var/log/$app/$app.log" "300"
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"