Add logrotate template rendered upon installation
There are no logrotate configurations for the mysql router logs. This PR introduces a template rendered upon installation of the charm. A maximum of 10 log files (10M each) are retained. Change-Id: I18376228af4ca809c10a1b138ceb96459686daa4 Closes-Bug: #1880083
This commit is contained in:
@@ -66,6 +66,11 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
|
|||||||
"/etc/systemd/system",
|
"/etc/systemd/system",
|
||||||
"{}.service".format(name))
|
"{}.service".format(name))
|
||||||
|
|
||||||
|
logrotate_file = os.path.join(
|
||||||
|
"/etc/logrotate.d",
|
||||||
|
"{}".format(name)
|
||||||
|
)
|
||||||
|
|
||||||
services = [name]
|
services = [name]
|
||||||
restart_map = {
|
restart_map = {
|
||||||
"/var/lib/mysql/{}/mysqlrouter.conf".format(name): services
|
"/var/lib/mysql/{}/mysqlrouter.conf".format(name): services
|
||||||
@@ -301,6 +306,19 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
|
|||||||
cmd = ["systemctl", "enable", self.name]
|
cmd = ["systemctl", "enable", self.name]
|
||||||
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
# Logrotate File
|
||||||
|
ch_core.templating.render(
|
||||||
|
source="logrotate",
|
||||||
|
template_loader=os_templating.get_loader(
|
||||||
|
"templates/", self.release),
|
||||||
|
target=self.logrotate_file,
|
||||||
|
context={
|
||||||
|
"owner": self.mysqlrouter_user,
|
||||||
|
"group": self.mysqlrouter_group
|
||||||
|
},
|
||||||
|
perms=0o644,
|
||||||
|
)
|
||||||
|
|
||||||
def get_db_helper(self):
|
def get_db_helper(self):
|
||||||
"""Get an instance of the MySQLDB8Helper class.
|
"""Get an instance of the MySQLDB8Helper class.
|
||||||
|
|
||||||
|
|||||||
9
src/templates/logrotate
Normal file
9
src/templates/logrotate
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/var/lib/mysql/*/log/*.log {
|
||||||
|
rotate 9
|
||||||
|
notifempty
|
||||||
|
size 10M
|
||||||
|
create 0644 {{ owner }} {{ group }}
|
||||||
|
postrotate
|
||||||
|
kill -HUP $(pidof mysqlrouter)
|
||||||
|
endscript
|
||||||
|
}
|
||||||
@@ -268,7 +268,7 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
|
|||||||
self.mkdir.assert_called_once_with(
|
self.mkdir.assert_called_once_with(
|
||||||
"/var/lib/mysql", group="mysql", owner="mysql", perms=0o755)
|
"/var/lib/mysql", group="mysql", owner="mysql", perms=0o755)
|
||||||
|
|
||||||
self.render.assert_called_once()
|
self.assertEqual(self.render.call_count, 2)
|
||||||
self.subprocess.check_output.assert_called_once_with(
|
self.subprocess.check_output.assert_called_once_with(
|
||||||
['systemctl', 'enable', _name],
|
['systemctl', 'enable', _name],
|
||||||
stderr=self.subprocess.STDOUT)
|
stderr=self.subprocess.STDOUT)
|
||||||
|
|||||||
Reference in New Issue
Block a user