Skip to content

Commit a91f4ec

Browse files
committed
flux-restore: call sd_notify()
Problem: flux-dump(1) now sends updates to systemd via sd_notify() but flux-restore(1), which runs during rc1 does not provide similar updates. Do the same thing in flux-restore(1).
1 parent 91c7cf3 commit a91f4ec

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cmd/builtin/restore.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#if HAVE_CONFIG_H
1212
# include <config.h>
1313
#endif
14+
#if HAVE_LIBSYSTEMD
15+
#include <systemd/sd-daemon.h>
16+
#endif
1417
#include <unistd.h>
1518
#include <stdarg.h>
1619
#include <jansson.h>
@@ -35,6 +38,7 @@
3538

3639
#define BLOCKSIZE 10240 // taken from libarchive example
3740

41+
static bool sd_notify_flag;
3842
static bool verbose;
3943
static bool quiet;
4044
static int content_flags;
@@ -56,6 +60,13 @@ static void progress (int delta_blob, int delta_keys)
5660
keycount,
5761
blobcount);
5862
}
63+
#if HAVE_LIBSYSTEMD
64+
if (sd_notify_flag
65+
&& (keycount % 100 == 0 || keycount < 10)) {
66+
sd_notifyf (0, "EXTEND_TIMEOUT_USEC=%d", 10000000); // 10s
67+
sd_notifyf (0, "STATUS=flux-restore(1) has restored %d keys", keycount);
68+
}
69+
#endif
5970
}
6071
static void progress_end (void)
6172
{
@@ -65,6 +76,11 @@ static void progress_end (void)
6576
keycount,
6677
blobcount);
6778
}
79+
#if HAVE_LIBSYSTEMD
80+
if (sd_notify_flag) {
81+
sd_notifyf (0, "STATUS=flux-restore(1) has restored %d keys", keycount);
82+
}
83+
#endif
6884
}
6985

7086
static struct archive *restore_create (const char *infile)
@@ -377,6 +393,11 @@ static int cmd_restore (optparse_t *p, int ac, char *av[])
377393
blob_size_limit = optparse_get_size_int (p, "size-limit", "0");
378394

379395
h = builtin_get_flux_handle (p);
396+
397+
const char *s;
398+
if ((s = flux_attr_get (h, "broker.sd-notify")) && !streq (s, "0"))
399+
sd_notify_flag = true;
400+
380401
ar = restore_create (infile);
381402

382403
if (optparse_hasopt (p, "checkpoint")) {

0 commit comments

Comments
 (0)