mounted DB_CONF file
This commit is contained in:
parent
9770fe96b4
commit
52e1674f0a
|
@ -47,7 +47,12 @@ DB_HOST = 'localhost'
|
||||||
# Database port
|
# Database port
|
||||||
DB_PORT = '5432'
|
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
|
# 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'
|
DB_CONF = '/etc/postgresql/9.6/main/postgresql.conf'
|
||||||
|
|
||||||
# Path to the directory for storing database dump files
|
# Path to the directory for storing database dump files
|
||||||
|
|
|
@ -259,7 +259,7 @@ def change_conf(next_conf=None):
|
||||||
with open(tmp_conf_out, 'w') as f:
|
with open(tmp_conf_out, 'w') as f:
|
||||||
f.write(''.join(lines))
|
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)
|
put(tmp_conf_out, dconf.DB_CONF, use_sudo=False)
|
||||||
local('rm -f {} {}'.format(tmp_conf_in, tmp_conf_out))
|
local('rm -f {} {}'.format(tmp_conf_in, tmp_conf_out))
|
||||||
|
|
||||||
|
|
|
@ -146,10 +146,18 @@ def get(remote_path, local_path, use_sudo=False):
|
||||||
else: # docker or remote_docker
|
else: # docker or remote_docker
|
||||||
docker_cmd = 'docker cp -L {}:{} {}'.format(dconf.CONTAINER_NAME, remote_path, local_path)
|
docker_cmd = 'docker cp -L {}:{} {}'.format(dconf.CONTAINER_NAME, remote_path, local_path)
|
||||||
if dconf.HOST_CONN == 'docker':
|
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':
|
elif dconf.HOST_CONN == 'remote_docker':
|
||||||
res = sudo(docker_cmd, remote_only=True)
|
if dconf.DB_CONF_MOUNT is True:
|
||||||
res = _get(local_path, local_path, use_sudo)
|
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:
|
else:
|
||||||
raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
|
raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
|
||||||
return res
|
return res
|
||||||
|
@ -168,10 +176,18 @@ def put(local_path, remote_path, use_sudo=False):
|
||||||
else: # docker or remote_docker
|
else: # docker or remote_docker
|
||||||
docker_cmd = 'docker cp -L {} {}:{}'.format(local_path, dconf.CONTAINER_NAME, remote_path)
|
docker_cmd = 'docker cp -L {} {}:{}'.format(local_path, dconf.CONTAINER_NAME, remote_path)
|
||||||
if dconf.HOST_CONN == 'docker':
|
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':
|
elif dconf.HOST_CONN == 'remote_docker':
|
||||||
res = _put(local_path, local_path, use_sudo=True)
|
if dconf.DB_CONF_MOUNT is True:
|
||||||
res = sudo(docker_cmd, remote_only=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:
|
else:
|
||||||
raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
|
raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Reference in New Issue