From 5bef2d75704d9f79cefd7462cbf625aed6c23be1 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Fri, 12 Apr 2024 14:38:39 +0200 Subject: [PATCH] added the ability to make a partial update of a machine This is very useful to do quick tests while debugging as the the partial updates can be much faster than a full update. work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=3814] --- home/bin/deboco | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/home/bin/deboco b/home/bin/deboco index d9163b2..d9f64ea 100755 --- a/home/bin/deboco +++ b/home/bin/deboco @@ -471,10 +471,12 @@ deboco__init_machine() return "$error_code" } -deboco__update_machine() +common_update_machine() { local debops_controller_path="$1" local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr + local only_role="$3" # eg "role::xymon_server" or "role::rsyslog" or "" if all roles need to be applied + local machine_group="$4" # eg 'site' or 'service/apache2' debops_controller_path=$(realpath $debops_controller_path) log 'info' "updating $target_host_fqdn using debobs controller $debops_controller_path" @@ -507,9 +509,14 @@ deboco__update_machine() ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//') log 'debug' "ANS_HOST=${ANS_HOST}" # example to apply just the role rsyslog: - # debops run site --limit "${ANS_HOST:-/dev/null}" -t "role::rsyslog" | tee --append ${report_file_path} - debops run site --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path} - debops_exit_code=$? + if [ "$only_role" != '' ] + then + debops run "${machine_group}" --limit "${ANS_HOST:-/dev/null}" -t "${only_role}" | tee --append ${report_file_path} + debops_exit_code=$? + else + debops run "${machine_group}" --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path} + debops_exit_code=$? + fi echo "return code for debops run site --limit ${ANS_HOST:-/dev/null} : $debops_exit_code" >> "${report_file_path}" if [ "$debops_exit_code" != "$RETURNCODE_SUCCESS" ] then @@ -524,6 +531,31 @@ deboco__update_machine() return "$error_code" } +deboco__update_machine() +{ + local debops_controller_path="$1" + local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr + local only_role="" + local machine_group="site" + common_update_machine "$debops_controller_path" "$target_host_fqdn" "$only_role" "$machine_group" +} + +deboco__update_machine_partially() +{ + local debops_controller_path="$1" + local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr + local only_role="$3" # eg "role::xymon_server" or "role::rsyslog" or "" if all roles need to be applied + local service="$4" # eg "nginx" "apache2" + local machine_group='' + if [ "$service" = "" ] + then + machine_group='site' + else + machine_group="service/$service" + fi + common_update_machine "$debops_controller_path" "$target_host_fqdn" "$only_role" "$machine_group" +} + deboco_print_usage() { echo "$0 performs a debops controller operation" @@ -549,11 +581,17 @@ deboco_print_usage() echo " update_machine " echo " updates the machine using the debops controller in " echo + echo " update_machine_partially " + echo " updates the role on machine belonging to service using the debops controller in " + echo echo " configure_machine " echo " configures the machine using the debops controller in ". Equivalent to a init_machine followed by update_machine echo - echo "example:" + echo "examples:" echo " deboco --python-path /usr/bin/python3.10 init ~/work/debops/controllers/alambix" + echo + echo "example to update xymon server's configuration (here it's much faster to specify the service apache than an unspecified service: 16s instead of 3m 33s):" + echo " deboco update_machine_partially ~/debops/controllers/alambix monitoring.ipr.univ-rennes.fr role::xymon_server apache" } deboco()