diff --git a/client/driver/driver_config.py b/client/driver/driver_config.py index ff091f2..1e5c72a 100644 --- a/client/driver/driver_config.py +++ b/client/driver/driver_config.py @@ -47,7 +47,12 @@ DB_HOST = 'localhost' # Database port DB_PORT = '5432' +# If set to True, DB_CONF file is mounted to database container file +# Only available when HOST_CONN is docker or remote_docker +DB_CONF_MOUNT = True + # Path to the configuration file on the database server +# If DB_CONF_MOUNT is True, the path is on the host server, not docker DB_CONF = '/etc/postgresql/9.6/main/postgresql.conf' # Path to the directory for storing database dump files diff --git a/client/driver/fabfile.py b/client/driver/fabfile.py index 95494f3..7b1d1a9 100644 --- a/client/driver/fabfile.py +++ b/client/driver/fabfile.py @@ -259,7 +259,7 @@ def change_conf(next_conf=None): with open(tmp_conf_out, 'w') as f: f.write(''.join(lines)) - sudo('cp {0} {0}.ottertune.bak'.format(dconf.DB_CONF)) + sudo('cp {0} {0}.ottertune.bak'.format(dconf.DB_CONF), remote_only=True) put(tmp_conf_out, dconf.DB_CONF, use_sudo=False) local('rm -f {} {}'.format(tmp_conf_in, tmp_conf_out)) diff --git a/client/driver/utils.py b/client/driver/utils.py index e454ef2..712046f 100644 --- a/client/driver/utils.py +++ b/client/driver/utils.py @@ -146,10 +146,18 @@ def get(remote_path, local_path, use_sudo=False): else: # docker or remote_docker docker_cmd = 'docker cp -L {}:{} {}'.format(dconf.CONTAINER_NAME, remote_path, local_path) if dconf.HOST_CONN == 'docker': - res = local(docker_cmd) + if dconf.DB_CONF_MOUNT is True: + pre_cmd = 'sudo ' if use_sudo else '' + opts = '-r' if os.path.isdir(remote_path) else '' + res = local('{}cp {} {} {}'.format(pre_cmd, opts, remote_path, local_path)) + else: + res = local(docker_cmd) elif dconf.HOST_CONN == 'remote_docker': - res = sudo(docker_cmd, remote_only=True) - res = _get(local_path, local_path, use_sudo) + if dconf.DB_CONF_MOUNT is True: + res = _get(remote_path, local_path, use_sudo=use_sudo) + else: + res = sudo(docker_cmd, remote_only=True) + res = _get(local_path, local_path, use_sudo) else: raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN)) return res @@ -168,10 +176,18 @@ def put(local_path, remote_path, use_sudo=False): else: # docker or remote_docker docker_cmd = 'docker cp -L {} {}:{}'.format(local_path, dconf.CONTAINER_NAME, remote_path) if dconf.HOST_CONN == 'docker': - res = local(docker_cmd) + if dconf.DB_CONF_MOUNT is True: + pre_cmd = 'sudo ' if use_sudo else '' + opts = '-r' if os.path.isdir(local_path) else '' + res = local('{}cp {} {} {}'.format(pre_cmd, opts, local_path, remote_path)) + else: + res = local(docker_cmd) elif dconf.HOST_CONN == 'remote_docker': - res = _put(local_path, local_path, use_sudo=True) - res = sudo(docker_cmd, remote_only=True) + if dconf.DB_CONF_MOUNT is True: + res = _put(local_path, remote_path, use_sudo=use_sudo) + else: + res = _put(local_path, local_path, use_sudo=True) + res = sudo(docker_cmd, remote_only=True) else: raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN)) return res