From 1732c373aa21fb7493b8fb50dd64bdf9425bf70b Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Mon, 4 Jul 2011 23:48:05 +0400 Subject: Gracefull shutdown of nova-api. --- bin/nova-api | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bin/nova-api') diff --git a/bin/nova-api b/bin/nova-api index fff67251f..71c68f24d 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -24,6 +24,7 @@ Starts both the EC2 and OpenStack APIs in separate processes. """ import os +import signal import sys possible_topdir = os.path.normpath(os.path.join(os.path.abspath( @@ -34,11 +35,15 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): import nova.service import nova.utils +def create_kill_handler(launcher): + def handle(signal, frame): + launcher.stop() + return handle def main(): """Launch EC2 and OSAPI services.""" nova.utils.Bootstrapper.bootstrap_binary(sys.argv) - + ec2 = nova.service.WSGIService("ec2") osapi = nova.service.WSGIService("osapi") @@ -46,10 +51,9 @@ def main(): launcher.launch_service(ec2) launcher.launch_service(osapi) - try: - launcher.wait() - except KeyboardInterrupt: - launcher.stop() + signal.signal(signal.SIGTERM, create_kill_handler(launcher)) + + launcher.wait() if __name__ == '__main__': -- cgit From fde44cdf69ad1884adf7007ae432438de5bcd664 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Wed, 6 Jul 2011 00:24:55 +0400 Subject: Signal handler cleanup, proper ^C handling. --- bin/nova-api | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'bin/nova-api') diff --git a/bin/nova-api b/bin/nova-api index 71c68f24d..a51eb1b6e 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -35,11 +35,6 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): import nova.service import nova.utils -def create_kill_handler(launcher): - def handle(signal, frame): - launcher.stop() - return handle - def main(): """Launch EC2 and OSAPI services.""" nova.utils.Bootstrapper.bootstrap_binary(sys.argv) @@ -51,9 +46,12 @@ def main(): launcher.launch_service(ec2) launcher.launch_service(osapi) - signal.signal(signal.SIGTERM, create_kill_handler(launcher)) - - launcher.wait() + signal.signal(signal.SIGTERM, lambda *_: launcher.stop()) + + try: + launcher.wait() + except KeyboardInterrupt: + launcher.stop() if __name__ == '__main__': -- cgit From c3229ec37f117d4fe8fc280b726a2e410a4b42a0 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Wed, 6 Jul 2011 01:09:00 +0400 Subject: Formatting fix. --- bin/nova-api | 1 + 1 file changed, 1 insertion(+) (limited to 'bin/nova-api') diff --git a/bin/nova-api b/bin/nova-api index a51eb1b6e..ccbb103f4 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -27,6 +27,7 @@ import os import signal import sys + possible_topdir = os.path.normpath(os.path.join(os.path.abspath( sys.argv[0]), os.pardir, os.pardir)) if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): -- cgit From 6b6fd2fe87ff23f3c056ba076218917404bd024a Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Wed, 6 Jul 2011 01:31:04 +0400 Subject: PEP8 passed. --- bin/nova-api | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'bin/nova-api') diff --git a/bin/nova-api b/bin/nova-api index ccbb103f4..4c5164ea1 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -36,10 +36,11 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): import nova.service import nova.utils + def main(): """Launch EC2 and OSAPI services.""" nova.utils.Bootstrapper.bootstrap_binary(sys.argv) - + ec2 = nova.service.WSGIService("ec2") osapi = nova.service.WSGIService("osapi") @@ -48,7 +49,7 @@ def main(): launcher.launch_service(osapi) signal.signal(signal.SIGTERM, lambda *_: launcher.stop()) - + try: launcher.wait() except KeyboardInterrupt: -- cgit From 209bf1ef495d2d599ef51e207e8de0694dec9790 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 8 Jul 2011 17:12:14 -0500 Subject: Add a flag to disable ec2 or osapi. --- bin/nova-api | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'bin/nova-api') diff --git a/bin/nova-api b/bin/nova-api index 4c5164ea1..fe8e83366 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -36,17 +36,21 @@ if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")): import nova.service import nova.utils +from nova import flags + + +FLAGS = flags.FLAGS + def main(): """Launch EC2 and OSAPI services.""" nova.utils.Bootstrapper.bootstrap_binary(sys.argv) - ec2 = nova.service.WSGIService("ec2") - osapi = nova.service.WSGIService("osapi") - launcher = nova.service.Launcher() - launcher.launch_service(ec2) - launcher.launch_service(osapi) + + for api in FLAGS.enabled_apis: + service = nova.service.WSGIService(api) + launcher.launch_service(service) signal.signal(signal.SIGTERM, lambda *_: launcher.stop()) -- cgit