Skip to content

Commit

Permalink
confd: when disabling containers, delete in background
Browse files Browse the repository at this point in the history
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 <troglobit@gmail.com>
  • Loading branch information
troglobit committed Jun 25, 2024
1 parent 0edc2d5 commit afbe5ca
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/confd/src/infix-containers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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++) {
Expand All @@ -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,
Expand Down

0 comments on commit afbe5ca

Please sign in to comment.