Skip to content

Commit

Permalink
Send status to systemd on daemon start
Browse files Browse the repository at this point in the history
systemd service files run in no-forking mode (--foreground) since
8b6f581.

Rearrange sd_notify() call in become_daemon() to only send status to systemd
in this mode (Type=notify is not designed to monitor forking). Drop READY=0
(it does nothing) and MAINPID= (unnecessary because the process spawned by
systemd is already the main PID).

Also remove STATUS= prefix from debug messages.

Signed-off-by: Marcos Mello <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
Reviewed-by: Alexander Bokovoy <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
marcosfrm authored and abartlet committed Dec 17, 2018
1 parent 97c5a69 commit 440ddf8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/util/become_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,12 @@ void become_daemon(bool do_fork, bool no_session, bool log_stdout)
exit_daemon("Fork failed", errno);
}
if (newpid) {
#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
sd_notifyf(0,
"READY=0\nSTATUS=Starting process...\n"
"MAINPID=%lu",
(unsigned long) newpid);
#endif /* HAVE_LIBSYSTEMD_DAEMON */
_exit(0);
}
#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
} else {
sd_notify(0, "STATUS=Starting process...");
#endif
}

/* detach from the terminal */
Expand Down Expand Up @@ -120,7 +118,7 @@ void exit_daemon(const char *msg, int error)
msg,
error);
#endif
DBG_ERR("STATUS=daemon failed to start: %s, error code %d\n",
DBG_ERR("daemon failed to start: %s, error code %d\n",
msg, error);
exit(1);
}
Expand All @@ -134,7 +132,7 @@ void daemon_ready(const char *daemon)
sd_notifyf(0, "READY=1\nSTATUS=%s: ready to serve connections...",
daemon);
#endif
DBG_ERR("STATUS=daemon '%s' finished starting up and ready to serve "
DBG_ERR("daemon '%s' finished starting up and ready to serve "
"connections\n", daemon);
}

Expand All @@ -144,7 +142,7 @@ void daemon_status(const char *daemon, const char *msg)
daemon = "Samba";
}
#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
sd_notifyf(0, "\nSTATUS=%s: %s", daemon, msg);
sd_notifyf(0, "STATUS=%s: %s", daemon, msg);
#endif
DBG_ERR("STATUS=daemon '%s' : %s\n", daemon, msg);
DBG_ERR("daemon '%s' : %s\n", daemon, msg);
}

0 comments on commit 440ddf8

Please sign in to comment.