#include "includes.h"
#include "system/filesys.h"
#include "system/locale.h"
+#if HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
/*******************************************************************
Close the low 3 fd's and open dev/null in their place.
_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout)
{
+ pid_t newpid;
if (do_fork) {
- if (fork()) {
+ newpid = fork();
+ if (newpid) {
+#if HAVE_SYSTEMD
+ sd_notifyf(0, "READY=0\nSTATUS=Starting process...\nMAINPID=%lu", (unsigned long) newpid);
+#endif /* HAVE_SYSTEMD */
_exit(0);
}
}
* never close stderr (but debug might dup it onto a log file) */
close_low_fds(do_fork, !log_stdout, false);
}
+
+_PUBLIC_ void exit_daemon(const char *msg, int error)
+{
+#ifdef HAVE_SYSTEMD
+ if (msg == NULL) {
+ msg = strerror(error);
+ }
+
+ sd_notifyf(0, "STATUS=daemon failed to start: %s\n"
+ "ERRNO=%i",
+ msg,
+ error);
+#endif
+ DEBUG(0, ("STATUS=daemon failed to start: %s, error code %d\n", msg, error));
+ exit(1);
+}
+
+_PUBLIC_ void daemon_ready(const char *daemon)
+{
+ if (daemon == NULL) {
+ daemon = "Samba";
+ }
+#ifdef HAVE_SYSTEMD
+ sd_notifyf(0, "READY=1\nSTATUS=%s: ready to serve connections...", daemon);
+#endif
+ DEBUG(0, ("STATUS=daemon '%s' finished starting up and ready to serve connections", daemon));
+}
**/
_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool log_stdout);
+/**
+ Exit daemon and print error message to the log at level 0
+ Optionally report failure to systemd if systemd integration is enabled
+**/
+_PUBLIC_ void exit_daemon(const char *msg, int error);
+
+/**
+ Report that the daemon is ready to serve connections to the log at level 0
+ Optionally report status to systemd if systemd integration is enabled
+**/
+_PUBLIC_ void daemon_ready(const char *daemon);
+
/**
* @brief Get a password from the console.
*
server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
tevent_debug.c util_process.c''',
deps='DYNCONFIG',
- public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid',
+ public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid systemd-daemon',
public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h samba_util.h string_wrappers.h',
header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],
local_include=False,
After=syslog.target network.target
[Service]
-Type=forking
+Type=notify
+NotifyAccess=all
PIDFile=/run/nmbd.pid
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/usr/sbin/nmbd $NMBDOPTIONS
After=syslog.target network.target
[Service]
-Type=forking
+Type=notify
+NotifyAccess=all
PIDFile=/run/samba.pid
LimitNOFILE=16384
EnvironmentFile=-/etc/sysconfig/samba
After=syslog.target network.target nmb.service winbind.service
[Service]
-Type=forking
+Type=notify
+NotifyAccess=all
PIDFile=/run/smbd.pid
LimitNOFILE=16384
EnvironmentFile=-/etc/sysconfig/samba
After=syslog.target network.target nmb.service
[Service]
-Type=forking
+Type=notify
+NotifyAccess=all
PIDFile=/run/winbindd.pid
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/usr/sbin/winbindd "$WINBINDOPTIONS"
exit(1);
}
+ if (is_daemon && !opt_interactive) {
+ daemon_ready("nmbd");
+ }
+
TALLOC_FREE(frame);
process(msg);
exit(1);
}
+ if (is_daemon && !interactive) {
+ daemon_ready("smbd");
+ }
+
/* only start other daemons if we are running as a daemon
* -- bad things will happen if smbd is launched via inetd
* and we fork a copy of ourselves here */
}
TALLOC_FREE(frame);
+
+ if (!interactive) {
+ daemon_ready("winbindd");
+ }
+
/* Loop waiting for requests */
while (1) {
frame = talloc_stackframe();
return 1;
}
+ if (opt_daemon) {
+ daemon_ready("samba");
+ }
+
/* wait for events - this is where smbd sits for most of its
life */
tevent_loop_wait(event_ctx);
help=("Disable RELRO builds"),
action="store_false", dest='enable_relro')
- gr = opt.option_group('developer options')
+ opt.add_option('--with-systemd',
+ help=("Enable systemd integration"),
+ action='store_true', dest='enable_systemd')
+
+ opt.add_option('--without-systemd',
+ help=("Disable systemd integration"),
+ action='store_false', dest='enable_systemd')
+ gr = opt.option_group('developer options')
opt.tool_options('python') # options for disabling pyc or pyo compilation
# enable options related to building python extensions
addmain=False,
msg='Checking configure summary'):
raise Utils.WafError('configure summary failed')
-
- conf.SAMBA_CONFIG_H('include/config.h')
if Options.options.enable_pie != False:
if Options.options.enable_pie == True:
msg="Checking compiler for full RELRO support"):
conf.env['ENABLE_RELRO'] = True
+ if Options.options.enable_systemd != False:
+ conf.check_cfg(package='libsystemd-daemon', args='--cflags --libs',
+ msg='Checking for libsystemd-daemon', uselib_store="SYSTEMD-DAEMON")
+ conf.CHECK_HEADERS('systemd/sd-daemon.h', lib='systemd-daemon')
+ conf.CHECK_LIB('systemd-daemon', shlib=True)
+
+ if conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H'):
+ conf.DEFINE('HAVE_SYSTEMD', '1')
+ conf.env['ENABLE_SYSTEMD'] = True
+ else:
+ conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
+ conf.undefine('HAVE_SYSTEMD')
+
+ conf.SAMBA_CONFIG_H('include/config.h')
+
def etags(ctx):
'''build TAGS file using etags'''
import Utils