]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib, watchfrr: Add some additional status messages to systemd
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 4 Oct 2019 01:09:28 +0000 (21:09 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 4 Oct 2019 01:09:28 +0000 (21:09 -0400)
Allow systemd to be informed about operational state so operators can
infer a bit about what is going on with FRR from the systemd status
cli.

sharpd@robot ~/frr4> systemctl status frr
● frr.service - FRRouting
   Loaded: loaded (/usr/lib/systemd/system/frr.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-10-03 21:09:04 EDT; 7s ago
     Docs: https://frrouting.readthedocs.io/en/latest/setup.html
  Process: 32455 ExecStart=/usr/lib/frr/frrinit.sh start (code=exited, status=0/SUCCESS)
   Status: "FRR Operational"
    Tasks: 12 (limit: 4915)
   Memory: 76.5M
   CGroup: /system.slice/frr.service
           ├─32468 /usr/lib/frr/watchfrr -d zebra bgpd staticd
           ├─32487 /usr/lib/frr/zebra -d -A 127.0.0.1 -s 90000000
           ├─32492 /usr/lib/frr/bgpd -d -A 127.0.0.1
           └─32500 /usr/lib/frr/staticd -d -A 127.0.0.1

Please note the `Status: ...` line above.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/systemd.c
lib/systemd.h
watchfrr/watchfrr.c

index 8a2a5eeac3bfef24b848d7a11db4138ab78827ba..44db48d0060351bb007dec7376aaa6826162957f 100644 (file)
@@ -86,6 +86,7 @@ static int systemd_get_watchdog_time(int the_process)
 
 void systemd_send_stopping(void)
 {
+       systemd_send_information("STATUS=");
        systemd_send_information("STOPPING=1");
 }
 
@@ -116,3 +117,11 @@ void systemd_send_started(struct thread_master *m, int the_process)
        if (wsecs != 0)
                thread_add_timer(m, systemd_send_watchdog, m, wsecs, NULL);
 }
+
+void systemd_send_status(const char *status)
+{
+       char buffer[1024];
+
+       snprintf(buffer, sizeof(buffer), "STATUS=%s", status);
+       systemd_send_information(buffer);
+}
index 6e43df527d7a9fc17b929a72f9e1f3112de7eb86..1f730720cefb18dc719a304f55e953b1010c3236 100644 (file)
@@ -42,6 +42,11 @@ void systemd_send_stopping(void);
  */
 void systemd_send_started(struct thread_master *master, int the_process);
 
+/*
+ * status - A status string to send to systemd
+ */
+void systemd_send_status(const char *status);
+
 #ifdef __cplusplus
 }
 #endif
index a6a910a1dbaed6604616ef823dcd38f9b29fd364..ea5965582490696e23b3ed4d78796116029cb2ee 100644 (file)
@@ -460,12 +460,20 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
                return -1;
        }
 
+#if defined HAVE_SYSTEMD
+       char buffer[512];
+
+       snprintf(buffer, sizeof(buffer), "restarting %s", restart->name);
+       systemd_send_status(buffer);
+#endif
+
        /* Note: time_elapsed test must come before the force test, since we
           need
           to make sure that delay is initialized for use below in updating the
           restart interval. */
        if ((time_elapsed(&delay, &restart->time)->tv_sec < restart->interval)
            && !force) {
+
                if (gs.loglevel > LOG_DEBUG + 1)
                        zlog_debug(
                                "postponing %s %s: "
@@ -490,6 +498,9 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
                        restart->pid = 0;
        }
 
+#if defined HAVE_SYSTEMD
+       systemd_send_status("FRR Operational");
+#endif
        /* Calculate the new restart interval. */
        if (update_interval) {
                if (delay.tv_sec > 2 * gs.max_restart_interval)
@@ -707,6 +718,7 @@ static void daemon_send_ready(int exitcode)
                fclose(fp);
 #if defined HAVE_SYSTEMD
        systemd_send_started(master, 0);
+       systemd_send_status("FRR Operational");
 #endif
        sent = 1;
 }