Blame otp-0009-Don-t-send-unasked-for-systemd-notifications.patch

8d530e
From: Alexey Lebedeff <alebedev@mirantis.com>
8d530e
Date: Tue, 29 Mar 2016 20:30:22 +0300
8d530e
Subject: [PATCH] Don't send unasked for systemd notifications
8d530e
8d530e
Suppose we have some erlang system that uses systemd unit with
8d530e
Type=notify - so this should send startup confirmation itself. But if
8d530e
systemd-enabled epmd will be started as a first step of that system
8d530e
startup, empd startup confirmation will be misinterpeted by systemd. And
8d530e
our erlang service will be considered 'ready' to early. Also this will
8d530e
interefere with systemd MAINPID detection: systemd will be monitoring
8d530e
`epmd` process instead of `beam` one.
8d530e
8d530e
For example, rabbitmq works around this issue by starting epmd using
8d530e
separate short-lived beam process, with NOTIFY_SOCKET environment
8d530e
variable reset - only in this way we could be sure that epmd will not
8d530e
interfere with rabbit startup sequence.
8d530e
8d530e
This patch disables indiscriminate confirmation sending, and does it
8d530e
only when it was explicitly asked to do so.
8d530e
8d530e
diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c
8d530e
index 5513cb2..4740ce8 100644
8d530e
--- a/erts/epmd/src/epmd.c
8d530e
+++ b/erts/epmd/src/epmd.c
8d530e
@@ -592,8 +592,10 @@ void epmd_cleanup_exit(EpmdVars *g, int exitval)
8d530e
       free(g->argv);
8d530e
   }
8d530e
 #ifdef HAVE_SYSTEMD_DAEMON
8d530e
-  sd_notifyf(0, "STATUS=Exited.\n"
8d530e
-                "ERRNO=%i", exitval);
8d530e
+  if (g->is_systemd){
8d530e
+    sd_notifyf(0, "STATUS=Exited.\n"
8d530e
+               "ERRNO=%i", exitval);
8d530e
+  }
8d530e
 #endif /* HAVE_SYSTEMD_DAEMON */
8d530e
   exit(exitval);
8d530e
 }
8d530e
diff --git a/erts/epmd/src/epmd_srv.c b/erts/epmd/src/epmd_srv.c
8d530e
index e1bac99..59d59ad 100644
8d530e
--- a/erts/epmd/src/epmd_srv.c
8d530e
+++ b/erts/epmd/src/epmd_srv.c
8d530e
@@ -452,9 +452,11 @@ void run(EpmdVars *g)
8d530e
   num_sockets = bound;
8d530e
 #ifdef HAVE_SYSTEMD_DAEMON
8d530e
     }
8d530e
-    sd_notifyf(0, "READY=1\n"
8d530e
-                  "STATUS=Processing port mapping requests...\n"
8d530e
-                  "MAINPID=%lu", (unsigned long) getpid());
8d530e
+    if (g->is_systemd) {
8d530e
+      sd_notifyf(0, "READY=1\n"
8d530e
+                    "STATUS=Processing port mapping requests...\n"
8d530e
+                    "MAINPID=%lu", (unsigned long) getpid());
8d530e
+    }
8d530e
 #endif /* HAVE_SYSTEMD_DAEMON */
8d530e
 
8d530e
   dbg_tty_printf(g,2,"entering the main select() loop");