From d4474e8943d29d6c46f40631ae291dd47baa7927 Mon Sep 17 00:00:00 2001 From: Adam Harwell Date: Thu, 5 Apr 2018 07:29:13 +0900 Subject: [PATCH] Make keepalived initialization more predictable This prevents forcing keepalived to renegotiate roles between amps more times than necessary. Keepalived is already running at the point that we do our initial "amp start" command, so if we actually force a restart it loses its state and has to renegotiate. I would consider the fact that this works without issue right now "very good luck". Let's make this more sane, and only reload if that's what we need to do. Change-Id: Ie920bba9b2d718c59c6ce00c0f013058ed2634bb --- .../backends/agent/api_server/keepalived.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/octavia/amphorae/backends/agent/api_server/keepalived.py b/octavia/amphorae/backends/agent/api_server/keepalived.py index ed526c6285..e0400e7a14 100644 --- a/octavia/amphorae/backends/agent/api_server/keepalived.py +++ b/octavia/amphorae/backends/agent/api_server/keepalived.py @@ -128,6 +128,20 @@ class Keepalived(object): message='Invalid Request', details="Unknown action: {0}".format(action)), status=400) + if action == consts.AMP_ACTION_START: + keepalived_pid_path = util.keepalived_pid_path() + try: + # Is there a pid file for keepalived? + with open(keepalived_pid_path, 'r') as pid_file: + pid = int(pid_file.readline()) + os.kill(pid, 0) + + # If we got here, it means the keepalived process is running. + # We should reload it instead of trying to start it again. + action = consts.AMP_ACTION_RELOAD + except (IOError, OSError): + pass + cmd = ("/usr/sbin/service octavia-keepalived {action}".format( action=action))