mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-06 07:33:01 +02:00
Merge pull request #862 from kernelkit/dagger-mem-usage
Dagger memory usage
This commit is contained in:
+54
-17
@@ -84,19 +84,25 @@ 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=
|
||||
|
||||
@@ -104,23 +110,31 @@ do_abandon()
|
||||
[ "$next" ] && [ -d "$basedir/$next" ] \
|
||||
|| abort "Next generation does not exist"
|
||||
|
||||
mv "$basedir/$next" "$basedir/$next-ABANDONED-$(date +%F-%T)"
|
||||
rm "$basedir/next"
|
||||
echo "$next"
|
||||
}
|
||||
|
||||
do_exec()
|
||||
{
|
||||
local action="$1"
|
||||
|
||||
action_exec "$1" "$basedir/$(get_current)"
|
||||
}
|
||||
|
||||
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=
|
||||
local next=
|
||||
|
||||
current=$([ -f "$basedir/current" ] && cat "$basedir/current" || true)
|
||||
[ ! "$current" ] || [ -d "$basedir/$current" ] \
|
||||
|| abort "Current generation does not exist"
|
||||
|
||||
next=$([ -f "$basedir/next" ] && cat "$basedir/next" || true)
|
||||
[ "$next" ] && [ -d "$basedir/$next" ] \
|
||||
|| abort "Next generation does not exist"
|
||||
local current=$(maybe_get_current)
|
||||
local next=$(get_next)
|
||||
local ar=
|
||||
|
||||
[ "$current" ] && action_exec exit "$basedir/$current"
|
||||
|
||||
@@ -128,6 +142,22 @@ do_evolve()
|
||||
|
||||
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()
|
||||
@@ -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.
|
||||
|
||||
@@ -201,6 +235,9 @@ case $cmd in
|
||||
"exec")
|
||||
do_exec "$@"
|
||||
;;
|
||||
"prune")
|
||||
do_prune "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage && exit 1
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user