Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r b8803a1e2dc2 -r f36a78324ec2 Makefile.am
- --- a/Makefile.am Sat Oct 16 18:33:42 2010 +0100
- +++ b/Makefile.am Wed Oct 20 12:53:52 2010 +0200
- @@ -49,6 +49,15 @@
- -e "s|^\(dovecot_moduledir\)=|\1=$(moduledir)|" \
- > dovecot-config
- +if HAVE_SYSTEMD
- +%.service: %.service.in
- + $(AM_V_GEN)sed -e 's,@sbindir\@,$(sbindir),g' $< > $@
- +
- +systemdsystemunit_DATA = \
- + dovecot.socket \
- + dovecot.service
- +endif
- +
- install-exec-hook:
- rm $(DESTDIR)$(pkglibdir)/dovecot-config && \
- grep -v '^LIBDOVECOT_.*_INCLUDE' dovecot-config | \
- @@ -62,6 +71,9 @@
- > $(DESTDIR)$(pkglibdir)/dovecot-config
- CLEANFILES = $(datafiles)
- +if HAVE_SYSTEMD
- +CLEANFILES += $systedmsystemunit_DATA
- +endif
- DISTCLEANFILES = $(top_builddir)/dovecot-version.h
- diff -r b8803a1e2dc2 -r f36a78324ec2 configure.in
- --- a/configure.in Sat Oct 16 18:33:42 2010 +0100
- +++ b/configure.in Wed Oct 20 12:53:52 2010 +0200
- @@ -2628,6 +2628,16 @@
- AC_SUBST(RUN_TEST)
- AC_SUBST(abs_top_builddir)
- +PKG_PROG_PKG_CONFIG
- +AC_ARG_WITH([systemdsystemunitdir],
- + AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
- + [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
- +if test "x$with_systemdsystemunitdir" != xno; then
- + AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
- + AC_DEFINE(HAVE_SYSTEMD,, Define if you want to use systemd socket activation)
- +fi
- +AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
- +
- AC_CONFIG_HEADERS([config.h])
- AC_CONFIG_FILES([
- Makefile
- diff -r b8803a1e2dc2 -r f36a78324ec2 dovecot.service.in
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
- +++ b/dovecot.service.in Wed Oct 20 12:53:52 2010 +0200
- @@ -0,0 +1,8 @@
- +[Unit]
- +Description=Dovecot IMAP/POP3 email server
- +After=local-fs.target network.target
- +
- +[Service]
- +Type=simple
- +ExecStart=@sbindir@/dovecot -F
- +NonBlocking=yes
- diff -r b8803a1e2dc2 -r f36a78324ec2 dovecot.socket
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
- +++ b/dovecot.socket Wed Oct 20 12:53:52 2010 +0200
- @@ -0,0 +1,15 @@
- +[Unit]
- +Description=Dovecot IMAP/POP3 email server activation socket
- +
- +[Socket]
- +#dovecot expects separate IPv4 and IPv6 sockets
- +BindIPv6Only=ipv6-only
- +ListenStream=0.0.0.0:143
- +ListenStream=[::]:143
- +ListenStream=0.0.0.0:993
- +ListenStream=[::]:993
- +KeepAlive=true
- +
- +[Install]
- +WantedBy=sockets.target
- +
- diff -r b8803a1e2dc2 -r f36a78324ec2 src/lib-master/master-service.c
- --- a/src/lib-master/master-service.c Sat Oct 16 18:33:42 2010 +0100
- +++ b/src/lib-master/master-service.c Wed Oct 20 12:53:52 2010 +0200
- @@ -397,6 +397,9 @@
- #ifdef DEBUG
- bool gdb = getenv("GDB") != NULL;
- #endif
- +#ifdef HAVE_SYSTEMD
- + const char *env_listen_pid, *env_listen_fds;
- +#endif
- user = getenv("USER");
- if (user != NULL)
- @@ -407,6 +410,17 @@
- home = preserve_home ? getenv("HOME") : NULL;
- if (home != NULL)
- home = t_strconcat("HOME=", home, NULL);
- +#ifdef HAVE_SYSTEMD
- + /* save LISTEN_PID and LISTEN_FDS since systemd socket activation
- + * needs that to work
- + */
- + env_listen_pid = getenv("LISTEN_PID");
- + if (env_listen_pid != NULL)
- + env_listen_pid = t_strconcat("LISTEN_PID=", env_listen_pid, NULL);
- + env_listen_fds = getenv("LISTEN_FDS");
- + if (env_listen_fds != NULL)
- + env_listen_fds = t_strconcat("LISTEN_FDS=", env_listen_fds, NULL);
- +#endif
- /* Note that if the original environment was set with env_put(), the
- environment strings will be invalid after env_clean(). That's why
- @@ -419,6 +433,10 @@
- #ifdef DEBUG
- if (gdb) env_put("GDB=1");
- #endif
- +#ifdef HAVE_SYSTEMD
- + if (env_listen_pid != NULL) env_put(env_listen_pid);
- + if (env_listen_fds != NULL) env_put(env_listen_fds);
- +#endif
- }
- void master_service_set_client_limit(struct master_service *service,
- diff -r b8803a1e2dc2 -r f36a78324ec2 src/master/Makefile.am
- --- a/src/master/Makefile.am Sat Oct 16 18:33:42 2010 +0100
- +++ b/src/master/Makefile.am Wed Oct 20 12:53:52 2010 +0200
- @@ -41,3 +41,10 @@
- service-process.h \
- service-process-notify.h \
- service.h
- +
- +HAVE_SYSTEMD=1
- +if HAVE_SYSTEMD
- +dovecot_SOURCES += sd-daemon.c
- +noinst_HEADERS += sd-daemon.h
- +endif
- +
- diff -r b8803a1e2dc2 -r f36a78324ec2 src/master/main.c
- --- a/src/master/main.c Sat Oct 16 18:33:42 2010 +0100
- +++ b/src/master/main.c Wed Oct 20 12:53:52 2010 +0200
- @@ -601,6 +601,9 @@
- struct master_settings *set;
- unsigned int child_process_env_idx = 0;
- const char *error, *env_tz, *doveconf_arg = NULL;
- +#ifdef HAVE_SYSTEMD
- + const char *env_listen_pid, *env_listen_fds;
- +#endif
- failure_callback_t *orig_info_callback, *orig_debug_callback;
- bool foreground = FALSE, ask_key_pass = FALSE;
- bool doubleopts[argc];
- @@ -732,6 +735,14 @@
- correctly. */
- env_tz = getenv("TZ");
- +#ifdef HAVE_SYSTEMD
- + /* save LISTEN_PID and LISTEN_FDS since systemd socket activation
- + * needs that to work
- + */
- + env_listen_pid = getenv("LISTEN_PID");
- + env_listen_fds = getenv("LISTEN_FDS");
- +#endif
- +
- /* clean up the environment of everything */
- env_clean();
- @@ -742,6 +753,20 @@
- env_put(env);
- child_process_env[child_process_env_idx++] = env;
- }
- +
- +#ifdef HAVE_SYSTEMD
- + /* put back systemd environment */
- + if (env_listen_pid != NULL) {
- + const char *env = t_strconcat("LISTEN_PID=", env_listen_pid, NULL);
- +
- + env_put(env);
- + }
- + if (env_listen_fds != NULL) {
- + const char *env = t_strconcat("LISTEN_FDS=", env_listen_fds, NULL);
- +
- + env_put(env);
- + }
- +#endif
- i_assert(child_process_env_idx <
- sizeof(child_process_env) / sizeof(child_process_env[0]));
- child_process_env[child_process_env_idx] = NULL;
- diff -r b8803a1e2dc2 -r f36a78324ec2 src/master/service-listen.c
- --- a/src/master/service-listen.c Sat Oct 16 18:33:42 2010 +0100
- +++ b/src/master/service-listen.c Wed Oct 20 12:53:52 2010 +0200
- @@ -2,9 +2,11 @@
- #include "common.h"
- #include "array.h"
- +#include "env-util.h"
- #include "fd-set-nonblock.h"
- #include "fd-close-on-exec.h"
- #include "network.h"
- +#include "sd-daemon.h"
- #include "service.h"
- #include "service-listen.h"
- @@ -148,19 +150,56 @@
- const struct inet_listener_settings *set = l->set.inetset.set;
- unsigned int port = set->port;
- int fd;
- + int n;
- - fd = net_listen(&l->set.inetset.ip, &port,
- - service_get_backlog(service));
- - if (fd < 0) {
- - service_error(service, "listen(%s, %u) failed: %m",
- - l->inet_address, set->port);
- - return errno == EADDRINUSE ? 0 : -1;
- + /* We unfortunately have to resort to this hack to workaround
- + * sd-listen-daemon.c PID check since dovecot binary starts by
- + * using execv to run doveconf, which then spawn again dovecot
- + * and this is this dovecot instance that will call this code,
- + * so it will no longer match the PID that systemd expects
- + */
- + if (getenv("LISTEN_PID") != NULL) {
- + const char *env = t_strdup_printf("LISTEN_PID=%d", getpid());
- + env_put(env);
- }
- - net_set_nonblock(fd, TRUE);
- - fd_close_on_exec(fd, TRUE);
- + n = sd_listen_fds(0);
- + if (n < 0) {
- + errno = -n;
- + goto failure;
- + } else if (n > 0) {
- + for (fd = SD_LISTEN_FDS_START;
- + fd <= SD_LISTEN_FDS_START + n - 1;
- + fd++) {
- + if (sd_is_socket_inet(fd, l->set.inetset.ip.family,
- + SOCK_STREAM, 1, port))
- + break;
- + }
- + if (fd > SD_LISTEN_FDS_START + n - 1) {
- + /* when systemd didn't provide a usable socket,
- + * fall back to the regular socket creation code
- + */
- + fd = -1;
- + }
- + } else {
- + fd = -1;
- + }
- +
- + if (fd == -1) {
- + fd = net_listen(&l->set.inetset.ip, &port,
- + service_get_backlog(service));
- + if (fd < 0)
- + goto failure;
- + net_set_nonblock(fd, TRUE);
- + fd_close_on_exec(fd, TRUE);
- + }
- l->fd = fd;
- return 1;
- +
- +failure:
- + service_error(service, "listen(%s, %u) failed: %m",
- + l->inet_address, set->port);
- + return errno == EADDRINUSE ? 0 : -1;
- }
- static int service_listen(struct service *service)
Add Comment
Please, Sign In to add comment