diff --git a/doc/source/controllingservers.rst b/doc/source/controllingservers.rst index c0216f6ddb..1bc3b8858e 100644 --- a/doc/source/controllingservers.rst +++ b/doc/source/controllingservers.rst @@ -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). diff --git a/glance/cmd/control.py b/glance/cmd/control.py index a1db670a34..e2e480af09 100644 --- a/glance/cmd/control.py +++ b/glance/cmd/control.py @@ -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)