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]
This commit is contained in:
Guillaume Raffy 2024-04-12 14:38:39 +02:00
parent a8549fbd60
commit 5bef2d7570
1 changed files with 43 additions and 5 deletions

View File

@ -471,10 +471,12 @@ deboco__init_machine()
return "$error_code" return "$error_code"
} }
deboco__update_machine() common_update_machine()
{ {
local debops_controller_path="$1" local debops_controller_path="$1"
local target_host_fqdn="$2" # eg alambix-108.ipr.univ-rennes.fr 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) debops_controller_path=$(realpath $debops_controller_path)
log 'info' "updating $target_host_fqdn using debobs controller $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$//') ANS_HOST=$(echo ${target_host_fqdn} | sed -E 's/\.univ-rennes[1]?\.fr$//')
log 'debug' "ANS_HOST=${ANS_HOST}" log 'debug' "ANS_HOST=${ANS_HOST}"
# example to apply just the role rsyslog: # example to apply just the role rsyslog:
# debops run site --limit "${ANS_HOST:-/dev/null}" -t "role::rsyslog" | tee --append ${report_file_path} if [ "$only_role" != '' ]
debops run site --limit "${ANS_HOST:-/dev/null}" | tee --append ${report_file_path} then
debops_exit_code=$? 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}" echo "return code for debops run site --limit ${ANS_HOST:-/dev/null} : $debops_exit_code" >> "${report_file_path}"
if [ "$debops_exit_code" != "$RETURNCODE_SUCCESS" ] if [ "$debops_exit_code" != "$RETURNCODE_SUCCESS" ]
then then
@ -524,6 +531,31 @@ deboco__update_machine()
return "$error_code" 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() deboco_print_usage()
{ {
echo "$0 performs a debops controller operation" echo "$0 performs a debops controller operation"
@ -549,11 +581,17 @@ deboco_print_usage()
echo " update_machine <debobs-controller-path> <machine-fqdn>" echo " update_machine <debobs-controller-path> <machine-fqdn>"
echo " updates the machine <machine-fqdn> using the debops controller in <debobs-controller-path>" echo " updates the machine <machine-fqdn> using the debops controller in <debobs-controller-path>"
echo echo
echo " update_machine_partially <debobs-controller-path> <machine-fqdn> <role> <service>"
echo " updates the role <role> on machine <machine-fqdn> belonging to service <service> using the debops controller in <debobs-controller-path>"
echo
echo " configure_machine <debobs-controller-path> <machine-fqdn>" echo " configure_machine <debobs-controller-path> <machine-fqdn>"
echo " configures the machine <machine-fqdn> using the debops controller in <debobs-controller-path>". Equivalent to a init_machine followed by update_machine echo " configures the machine <machine-fqdn> using the debops controller in <debobs-controller-path>". Equivalent to a init_machine followed by update_machine
echo echo
echo "example:" echo "examples:"
echo " deboco --python-path /usr/bin/python3.10 init ~/work/debops/controllers/alambix" 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() deboco()