confd: add support for manual start of containers

This commit adds 'manual:yes' to the container's Finit service
configuration and changes from pod: to container: prefix for a
unique namespace to prevent collision with regular services.

The prefix container: is more correct that pod:, which should
be reserved for any future pod support.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>

confd: fix missing variable in container script condition

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-02-25 19:49:27 +01:00
parent 0f0c119553
commit 2b19b61068
2 changed files with 12 additions and 21 deletions
+4 -4
View File
@@ -36,7 +36,7 @@ create()
args="$args --restart=no --systemd=false --tz=local --privileged --replace --quiet"
# args="$args --log-opt tag=$name"
pidfn=/run/pod:${name}.pid
pidfn=/run/container:${name}.pid
for net in "$@"; do
network="$network --net $net"
@@ -61,7 +61,7 @@ create()
log "Calling \"podman create --name $name --conmon-pidfile=$pidfn $network $args $image\""
if podman create --name "$name" --conmon-pidfile="$pidfn" $network $args "$image"; then
log "Successfully created container $name from $image"
initctl -nbq cond set pod:system
initctl -nbq cond set container:$name
exit 0
fi
log "Error: failed creating container $name, please check the configuration."
@@ -207,11 +207,11 @@ case $cmd in
;;
start)
verify "$1" || exit 1
initctl -bq start "pod:$1"
initctl -bq start "container:$1"
;;
stop)
verify "$1" || exit 1
initctl -bq stop "pod:$1" || podman kill "$1"
initctl -bq stop "container:$1" || podman kill "$1"
;;
*)
usage
+8 -17
View File
@@ -26,7 +26,7 @@ static const struct srx_module_requirement reqs[] = {
{ NULL }
};
static int job(const char *name, struct lyd_node *cif)
static int add(const char *name, struct lyd_node *cif)
{
const char *image = lydx_get_cattr(cif, "image");
struct lyd_node *net;
@@ -35,7 +35,7 @@ static int job(const char *name, struct lyd_node *cif)
fp = fopenf("w", "%s/%s.sh", INBOX_QUEUE, name);
if (!fp) {
ERROR("Failed adding job %s.sh to job queue" INBOX_QUEUE, name);
return 1;
return SR_ERR_SYS;
}
/* Stop any running container gracefully so it releases its IP addresses. */
@@ -68,29 +68,20 @@ static int job(const char *name, struct lyd_node *cif)
fprintf(fp, "\n");
fchmod(fileno(fp), 0700);
fclose(fp);
return fclose(fp);
}
static int add(const char *name, struct lyd_node *cif)
{
FILE *fp;
if (job(name, cif))
return SR_ERR_SYS;
fp = fopenf("w", "/etc/finit.d/available/pod:%s.conf", name);
fp = fopenf("w", "/etc/finit.d/available/container:%s.conf", name);
if (!fp) {
ERROR("Failed creating container %s monitor", name);
return SR_ERR_SYS;
}
fprintf(fp, "service name:pod log:prio:local1.err,tag:container :%s pid:!/run/pod:%s.pid \\\n"
" [2345] <usr/pod:%s> podman start -a %s -- Container %s\n",
name, name, name, name, name);
fprintf(fp, "service name:container :%s log:prio:local1.err,tag:%s %s pid:!/run/container:%s.pid \\\n"
" [2345] <usr/container:%s> podman start -a %s -- Container %s\n",
name, name, lydx_is_enabled(cif, "manual") ? "manual:yes" : "", name, name, name, name);
fclose(fp);
if (systemf("initctl -nbq enable pod:%s", name)) {
if (systemf("initctl -nbq enable container:%s", name)) {
ERROR("Failed enabling container %s monitor", name);
return SR_ERR_SYS;
}