Skip to content

Commit

Permalink
Set up logrotate when upgrading + account for logrotate's systemd tim…
Browse files Browse the repository at this point in the history
…er (#365)

* Set up logrotate when upgrading + account for logrotate's systemd timer

* Address PR feedback + fix failing unittest
  • Loading branch information
shayancanonical authored Dec 6, 2023
1 parent f757f4e commit 19c37be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mysql_vm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ def setup_logrotate_and_cron(self) -> None:
with open("/etc/logrotate.d/flush_mysql_logs", "w") as file:
file.write(rendered)

cron = "* * * * * root logrotate -f /etc/logrotate.d/flush_mysql_logs\n"
cron = (
"* 1-23 * * * root logrotate -f /etc/logrotate.d/flush_mysql_logs\n"
"1-59 0 * * * root logrotate -f /etc/logrotate.d/flush_mysql_logs\n"
)
with open("/etc/cron.d/flush_mysql_logs", "w") as file:
file.write(cron)

Expand Down
1 change: 1 addition & 0 deletions src/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None:
self._check_server_upgradeability()
self.charm.unit.status = MaintenanceStatus("starting services...")
self.charm._mysql.start_mysqld()
self.charm._mysql.setup_logrotate_and_cron()
except VersionError:
logger.exception("Failed to upgrade MySQL dependencies")
self.set_unit_failed()
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def test_pre_upgrade_prepare(
@patch("mysql_vm_helpers.MySQL.start_mysqld")
@patch("upgrade.MySQLVMUpgrade._check_server_upgradeability")
@patch("mysql_vm_helpers.MySQL.is_instance_in_cluster", return_value=True)
@patch("mysql_vm_helpers.MySQL.setup_logrotate_and_cron", return_value=True)
def test_upgrade_granted(
self,
mock_setup_logrotate_and_cron,
mock_is_instance_in_cluster,
mock_check_server_upgradeability,
mock_start_mysqld,
Expand All @@ -165,6 +167,7 @@ def test_upgrade_granted(
mock_stop_mysqld.assert_called_once()
mock_install_workload.assert_called_once()
mock_get_mysql_version.assert_called_once()
mock_setup_logrotate_and_cron.assert_called_once()

self.harness.update_relation_data(
self.upgrade_relation_id, "mysql/0", {"state": "upgrading"}
Expand Down

0 comments on commit 19c37be

Please sign in to comment.