Zero downtime config reload (glance-control)
Update glance-control to send a SIGHUP rather than perform a start/stop for the 'reload' operation. This allows picking up new configuration values without interrupting the service. Closes-bug: 1436275 Change-Id: I5a653daa3e582b665c0a2c402cf2d7c9e47e1c38
This commit is contained in:
parent
6dc5477a12
commit
0c7f172117
@ -222,3 +222,16 @@ here::
|
||||
$> sudo glance-control registry restart etc/glance-registry.conf
|
||||
Stopping glance-registry pid: 17611 signal: 15
|
||||
Starting glance-registry with /home/jpipes/repos/glance/trunk/etc/glance-registry.conf
|
||||
|
||||
Reloading a server
|
||||
-------------------
|
||||
|
||||
You can reload a server with the ``glance-control`` program, as demonstrated
|
||||
here::
|
||||
|
||||
$> sudo glance-control api reload
|
||||
Reloading glance-api (pid 18506) with signal(1)
|
||||
|
||||
A reload sends a SIGHUP signal to the master process and causes new configuration
|
||||
settings to be picked up without any interruption to the running service (provided
|
||||
neither bind_host or bind_port has changed).
|
||||
|
@ -54,6 +54,7 @@ CONF = cfg.CONF
|
||||
ALL_COMMANDS = ['start', 'status', 'stop', 'shutdown', 'restart',
|
||||
'reload', 'force-reload']
|
||||
ALL_SERVERS = ['api', 'registry', 'scrubber']
|
||||
RELOAD_SERVERS = ['glance-api', 'glance-registry']
|
||||
GRACEFUL_SHUTDOWN_SERVERS = ['glance-api', 'glance-registry',
|
||||
'glance-scrubber']
|
||||
MAX_DESCRIPTORS = 32768
|
||||
@ -242,6 +243,28 @@ def get_pid_file(server, pid_file):
|
||||
return pid_file
|
||||
|
||||
|
||||
def do_reload(pid_file, server):
|
||||
if server not in RELOAD_SERVERS:
|
||||
msg = (_('Reload of %(serv)s not supported') % {'serv': server})
|
||||
sys.exit(msg)
|
||||
|
||||
pid = None
|
||||
if os.path.exists(pid_file):
|
||||
with open(pid_file, 'r') as pidfile:
|
||||
pid = int(pidfile.read().strip())
|
||||
else:
|
||||
msg = (_('Server %(serv)s is stopped') % {'serv': server})
|
||||
sys.exit(msg)
|
||||
|
||||
sig = signal.SIGHUP
|
||||
try:
|
||||
print(_('Reloading %(serv)s (pid %(pid)s) with signal(%(sig)s)')
|
||||
% {'serv': server, 'pid': pid, 'sig': sig})
|
||||
os.kill(pid, sig)
|
||||
except OSError:
|
||||
print(_("Process %d not running") % pid)
|
||||
|
||||
|
||||
def do_stop(server, args, graceful=False):
|
||||
if graceful and server in GRACEFUL_SHUTDOWN_SERVERS:
|
||||
sig = signal.SIGHUP
|
||||
@ -383,8 +406,7 @@ def main():
|
||||
|
||||
if CONF.server.command in ('reload', 'force-reload'):
|
||||
for server in CONF.server.servers:
|
||||
do_stop(server, CONF.server.args, graceful=True)
|
||||
pid_file = get_pid_file(server, CONF.pid_file)
|
||||
do_start('Restart', pid_file, server, CONF.server.args)
|
||||
do_reload(pid_file, server)
|
||||
|
||||
sys.exit(exitcode)
|
||||
|
Loading…
Reference in New Issue
Block a user