From afbe5ca20b8e6ccaa9fee274e88fcdcf7adce2c8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 22 Jun 2024 12:10:24 +0200 Subject: [PATCH] confd: when disabling containers, delete in background Instead of potentially blocking sysrepo, which has a 5 second timeout, we move 'container delete' jobs to be run by the execd queue. Fixes #479 Signed-off-by: Joachim Wiberg --- src/confd/src/infix-containers.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/confd/src/infix-containers.c b/src/confd/src/infix-containers.c index 6f9c477c5..c11e66cbc 100644 --- a/src/confd/src/infix-containers.c +++ b/src/confd/src/infix-containers.c @@ -28,9 +28,9 @@ static int add(const char *name, struct lyd_node *cif) struct lyd_node *node, *nets, *caps; FILE *fp, *ap; - fp = fopenf("w", "%s/%s.sh", INBOX_QUEUE, name); + fp = fopenf("w", "%s/S01-%s.sh", INBOX_QUEUE, name); if (!fp) { - ERRNO("Failed adding job %s.sh to job queue" INBOX_QUEUE, name); + ERRNO("Failed adding job S01-%s.sh to job queue" INBOX_QUEUE, name); return SR_ERR_SYS; } @@ -187,6 +187,7 @@ static int del(const char *name) INBOX_QUEUE, ACTIVE_QUEUE, }; + FILE *fp; /* Remove any pending download/create job first */ for (size_t i = 0; i < NELEMS(queue); i++) { @@ -196,8 +197,21 @@ static int del(const char *name) erase(fn); } - return systemf("container delete %s", name) || - systemf("initctl -bnq disable container@%s.conf", name); + /* Disable service and schedule for deletion. */ + systemf("initctl -bnq disable container@%s.conf", name); + + fp = fopenf("w", "%s/K01-%s.sh", INBOX_QUEUE, name); + if (!fp) { + ERRNO("Failed adding job 00-delete-%s.sh to job queue" INBOX_QUEUE, name); + return SR_ERR_SYS; + } + + fprintf(fp, "#!/bin/sh\n" + "container delete %s\n", name); + fchmod(fileno(fp), 0700); + fclose(fp); + + return SR_ERR_OK; } static int change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,