Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger memory usage #862

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions src/confd/bin/dagger
Original file line number Diff line number Diff line change
Expand Up @@ -84,50 +84,80 @@ EOF
done
}

do_exec()
maybe_get_current()
{
echo $([ -f "$basedir/current" ] && cat "$basedir/current" || true)
[ ! "$current" ] || [ -d "$basedir/$current" ] \
|| abort "Current generation does not exist"
}

get_current()
{
local action="$1"
local current=

current=$([ -f "$basedir/current" ] && cat "$basedir/current")
current=$(maybe_get_current)
[ "$current" ] && [ -d "$basedir/$current" ] \
|| abort "Current generation does not exist"

action_exec "$1" "$basedir/$current"
echo "$current"
}

do_abandon()
get_next()
{
local next=

next=$([ -f "$basedir/next" ] && cat "$basedir/next" || true)
[ "$next" ] && [ -d "$basedir/$next" ] \
|| abort "Next generation does not exist"

mv "$basedir/$next" "$basedir/$next-ABANDONED-$(date +%F-%T)"
rm "$basedir/next"
inform info "Abandoned generation $next"
echo "$next"
}

do_evolve()
do_exec()
{
local current=
local next=
local action="$1"

current=$([ -f "$basedir/current" ] && cat "$basedir/current" || true)
[ ! "$current" ] || [ -d "$basedir/$current" ] \
|| abort "Current generation does not exist"
action_exec "$1" "$basedir/$(get_current)"
}

next=$([ -f "$basedir/next" ] && cat "$basedir/next" || true)
[ "$next" ] && [ -d "$basedir/$next" ] \
|| abort "Next generation does not exist"
do_abandon()
{
local next=$(get_next)

date +%F-%T >"$basedir/$next/ABANDONED"

mv "$basedir/next" "$basedir/current"
inform info "Abandoned generation $next"
}

do_evolve()
{
local current=$(maybe_get_current)
local next=$(get_next)
local ar=

[ "$current" ] && action_exec exit "$basedir/$current"

action_exec init "$basedir/$next"

mv "$basedir/next" "$basedir/current"
inform info "Evolved to generation $next"

if [ "$current" ]; then
ar="$current.tar.gz"
[ -f "$basedir/$current/ABANDONED" ] && ar="$current-ABANDONED.tar.gz"

(cd "$basedir" && tar caf "$ar.tar.gz" "$current")
rm -rf "$basedir/$current"
fi
}

do_prune()
{
local keep=${1:-10}

cd "$basedir"
rm -f old=$(ls -rv *.tar.gz | tail "+$((keep + 1))")
}

usage()
Expand Down Expand Up @@ -158,6 +188,10 @@ Commands:
exec <action>
Run the specified action of the current generation.

prune [<num-generations>]
Remove all but the last <num-generations>, or 10 by default,
archived generations.

help
Show this message.

Expand Down Expand Up @@ -201,6 +235,9 @@ case $cmd in
"exec")
do_exec "$@"
;;
"prune")
do_prune "$@"
;;

*)
usage && exit 1
Expand Down
12 changes: 12 additions & 0 deletions src/confd/src/dagger.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,23 @@ int dagger_evolve(struct dagger *d)
return exitcode;
}

static int dagger_prune(struct dagger *d)
{
int exitcode;

exitcode = systemf("dagger -C %s prune", d->path);
DEBUG("dagger(%d->%d): prune: exitcode=%d\n",
d->current, d->next, exitcode);

return exitcode;
}

int dagger_evolve_or_abandon(struct dagger *d)
{
int exitcode, err;

exitcode = dagger_evolve(d);
dagger_prune(d);
if (!exitcode)
return 0;

Expand Down
5 changes: 5 additions & 0 deletions src/confd/src/ietf-interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ static int netdag_exit_reload(struct dagger *net)
{
FILE *initctl;

if (systemf("runlevel >/dev/null 2>&1"))
/* If we are still bootstrapping, there is nothing to
* reload. */
return 0;

/* We may end up writing this file multiple times, e.g. if
* multiple services are disabled in the same config cycle,
* but since the contents of the file are static it doesn't
Expand Down