Browse Source

Configure /run/mysql location for PID file

Ensure that a location in /run is used for the PID file for
the mysqlrouter instance - this ensures that in the event
of a power outage, the old PID file will not be present and
the daemon will correctly startup when the machine starts up.

Update systemd configuration to create /run/mysql and to use
the mysql user and group to execute the daemon.

Switch to 'forking' mode to ensure that the mysqlrouter process
gets tracked by systemd.

Closes-Bug: 1931095
Change-Id: Id3f7605ad1e9e4a6e4b0a1abe8000abd75b5b0fd
changes/74/796274/5
James Page 1 year ago
parent
commit
72aca90ea3
  1. 18
      src/lib/charm/openstack/mysql_router.py
  2. 5
      src/templates/mysqlrouter.service
  3. 6
      unit_tests/test_lib_charm_openstack_mysql_router.py

18
src/lib/charm/openstack/mysql_router.py

@ -80,6 +80,17 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
# LP Bug #1915842
_waiting_for_initial_communication_packet_error = 2013
@property
def mysqlrouter_pid_file(self):
"""Determine the path for the mysqlrouter PID file.
:param self: Self
:type self: MySQLRouterCharm instance
:returns: Path to the PID file in /run
:rtype: str
"""
return "/run/mysql/mysqlrouter-{}.pid".format(self.name)
@property
def mysqlrouter_bin(self):
"""Determine the path to the mysqlrouter binary.
@ -654,15 +665,18 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
"auth_cache_ttl": str(self.options.auth_cache_ttl),
"auth_cache_refresh_interval":
str(self.options.auth_cache_refresh_interval),
},
"DEFAULT": {
"pid_file": self.mysqlrouter_pid_file,
}
}
if self.ssl_ca:
ch_core.hookenv.log("TLS mode PASSTHROUGH", "DEBUG")
_parameters["DEFAULT"] = {"client_ssl_mode": "PASSTHROUGH"}
_parameters["DEFAULT"]["client_ssl_mode"] = "PASSTHROUGH"
else:
ch_core.hookenv.log("TLS mode PREFERRED", "DEBUG")
_parameters["DEFAULT"] = {"client_ssl_mode": "PREFERRED"}
_parameters["DEFAULT"]["client_ssl_mode"] = "PREFERRED"
with ch_core.host.restart_on_change(
self.restart_map, restart_functions=self.restart_functions):

5
src/templates/mysqlrouter.service

@ -5,7 +5,10 @@ Description=MySQL Router
After=network.target
[Service]
Type=exec
Type=forking
User=mysql
Group=mysql
RuntimeDirectory=mysql
ExecStart=/var/lib/mysql/{{ options.charm_instance.name }}/start.sh
ExecStop=/var/lib/mysql/{{ options.charm_instance.name }}/stop.sh
RemainAfterExit=yes

6
unit_tests/test_lib_charm_openstack_mysql_router.py

@ -679,11 +679,15 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
_mock_update_config_parameters = mock.MagicMock()
mrc = mysql_router.MySQLRouterCharm()
mrc.name = 'foobar'
mrc.update_config_parameters = _mock_update_config_parameters
_params = {
'metadata_cache:jujuCluster': _config_data,
'DEFAULT': {'client_ssl_mode': "PASSTHROUGH"},
'DEFAULT': {
'client_ssl_mode': "PASSTHROUGH",
'pid_file': '/run/mysql/mysqlrouter-foobar.pid'
},
}
# Not bootstrapped yet

Loading…
Cancel
Save