From 2e024de2b8da0e91c57d1c78023fc8d3dcc16bfd Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Thu, 8 Oct 2020 16:12:41 -0700 Subject: [PATCH] [config] Reload Monit configuration after potential hostname changes (#1132) **- What I did** After hostname changes, we need to reload the Monit configuration in order for Monit to pick up the new system hostname. Otherwise, it will retain the previous hostname. **- How I did it** Call `sudo monit reload` after restarting hostname-config.service. --- config/main.py | 9 +++++++++ tests/config_test.py | 1 + 2 files changed, 10 insertions(+) diff --git a/config/main.py b/config/main.py index 1277acfc005d..d708f95240e6 100755 --- a/config/main.py +++ b/config/main.py @@ -751,6 +751,10 @@ def _restart_services(config_db): execute_systemctl(services_to_restart, SYSTEMCTL_ACTION_RESTART) + # Reload Monit configuration to pick up new hostname in case it changed + click.echo("Reloading Monit configuration ...") + clicommon.run_command("sudo monit reload") + def interface_is_in_vlan(vlan_member_table, interface_name): """ Check if an interface is in a vlan """ @@ -1235,6 +1239,11 @@ def hostname(new_hostname): except SystemExit as e: click.echo("Restarting hostname-config service failed with error {}".format(e)) raise + + # Reload Monit configuration to pick up new hostname in case it changed + click.echo("Reloading Monit configuration ...") + clicommon.run_command("sudo monit reload") + click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.") # diff --git a/tests/config_test.py b/tests/config_test.py index 023f41337a06..4fc6b876266b 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -43,6 +43,7 @@ Executing restart of service hostcfgd... Executing restart of service nat... Executing restart of service telemetry... +Reloading Monit configuration ... Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`. """