Add use_unix_socket_path to supervisor-proc-exit-listener (#16548)

Why I did it
ConfigDBConnector in supervisor-proc-exit-listener uses default parameter to connect CONFIG_DB (connect by 127.0.0.1:6379) which would fail at non-host network mode container, because they are not sharing the same network and socket.

How I did it
Add a new parameter use_unix_socket_path to this script to indicate whether to use socket to connect CONFIG_DB.

How to verify it
Build image and install it, kill critical processes in container and container crushed.
This commit is contained in:
Yaqiang Zhu 2023-09-15 19:23:25 -04:00 committed by GitHub
parent bb22c0309b
commit d11e0a214e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,12 +90,12 @@ def generate_alerting_message(process_name, status, dead_minutes):
.format(process_name, status, namespace, dead_minutes)) .format(process_name, status, namespace, dead_minutes))
def get_autorestart_state(container_name): def get_autorestart_state(container_name, use_unix_socket_path):
""" """
@summary: Read the status of auto-restart feature from Config_DB. @summary: Read the status of auto-restart feature from Config_DB.
@return: Return the status of auto-restart feature. @return: Return the status of auto-restart feature.
""" """
config_db = swsscommon.ConfigDBConnector() config_db = swsscommon.ConfigDBConnector(use_unix_socket_path=use_unix_socket_path)
config_db.connect() config_db.connect()
features_table = config_db.get_table(FEATURE_TABLE_NAME) features_table = config_db.get_table(FEATURE_TABLE_NAME)
if not features_table: if not features_table:
@ -122,10 +122,13 @@ def publish_events(events_handle, process_name, container_name):
def main(argv): def main(argv):
container_name = None container_name = None
opts, args = getopt.getopt(argv, "c:", ["container-name="]) use_unix_socket_path = False
opts, args = getopt.getopt(argv, "c:s", ["container-name=", "use-unix-socket-path"])
for opt, arg in opts: for opt, arg in opts:
if opt in ("-c", "--container-name"): if opt in ("-c", "--container-name"):
container_name = arg container_name = arg
if opt in ("-s", "--use-unix-socket-path"):
use_unix_socket_path = True
if not container_name: if not container_name:
syslog.syslog(syslog.LOG_ERR, "Container name not specified. Exiting...") syslog.syslog(syslog.LOG_ERR, "Container name not specified. Exiting...")
@ -159,7 +162,7 @@ def main(argv):
group_name = payload_headers['groupname'] group_name = payload_headers['groupname']
if (process_name in critical_process_list or group_name in critical_group_list) and expected == 0: if (process_name in critical_process_list or group_name in critical_group_list) and expected == 0:
is_auto_restart = get_autorestart_state(container_name) is_auto_restart = get_autorestart_state(container_name, use_unix_socket_path)
if is_auto_restart != "disabled": if is_auto_restart != "disabled":
MSG_FORMAT_STR = "Process '{}' exited unexpectedly. Terminating supervisor '{}'" MSG_FORMAT_STR = "Process '{}' exited unexpectedly. Terminating supervisor '{}'"
msg = MSG_FORMAT_STR.format(payload_headers['processname'], container_name) msg = MSG_FORMAT_STR.format(payload_headers['processname'], container_name)