Re: [Dovecot] add basic systemd support to dovecot

2010-11-17 Thread Christophe Fergeau
2010/11/17 Timo Sirainen t...@iki.fi:

 Committed, with some small changes:
 http://hg.dovecot.org/dovecot-2.0/rev/84eb4afebc95

Great, thanks a lot!


 I hope it still works :)

I'll let you know if it breaks ;)

Christophe


Re: [Dovecot] add basic systemd support to dovecot

2010-11-14 Thread Christophe Fergeau
Hi,

Sorry for the delay in replying, I was away for a few weeks :) I have finally
reworked the patch according to your feedback.

On Mon, Oct 25, 2010 at 05:47:20PM +0100, Timo Sirainen wrote:
 You can simplify the environment preserving with these changes:
 
 http://hg.dovecot.org/dovecot-2.0/rev/e0a97842182f
 http://hg.dovecot.org/dovecot-2.0/rev/d1fd5b84d410

Ah, that indeed makes things much simpler, thanks!

 
 I don't think this is portable. You could do it instead like:

Ok, I changed it even after reading your other email.

 
  +AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for 
  systemd service files]),
  +[], [with_systemdsystemunitdir=$($PKG_CONFIG 
  --variable=systemdsystemunitdir systemd)])
 
 Is this a common name for this option? If not, I'd prefer a shorter
 name.

I asked upstream about it, and I was told it's the usual way of naming options
with the autotools, so they'd prefer if it was kept this way. But I don't mind
changing it to something else if you prefer, I have a patch changing it to
--with-systemd if needed.

Here is the updated patch, if you want I also have it as a patch series:
systemd: Add proper systemd configure.in blob (from daemon(7))
systemd: Preserve LISTEN_FDS and LISTEN_PID during env cleanup when systemd is 
used
systemd: Use sockets provided by systemd if possible
systemd: When systemd didn't provide a suitable socket, fallback to the regular 
socket creation code
systemd: Add systemd unit files

Christophe
diff --git a/Makefile.am b/Makefile.am
index d037258..8a6000a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,17 @@ dovecot-config: dovecot-config.in Makefile
-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
+else
+EXTRA_DIST+= dovecot.socket dovecot.service.in
+endif
+
 install-exec-hook:
rm $(DESTDIR)$(pkglibdir)/dovecot-config  \
grep -v '^LIBDOVECOT_.*_INCLUDE' dovecot-config | \
@@ -62,6 +73,9 @@ install-exec-hook:
 $(DESTDIR)$(pkglibdir)/dovecot-config
 
 CLEANFILES = $(datafiles)
+if HAVE_SYSTEMD
+CLEANFILES += $systedmsystemunit_DATA
+endif
 
 DISTCLEANFILES = $(top_builddir)/dovecot-version.h
 
diff --git a/configure.in b/configure.in
index 348f441..ecb3046 100644
--- a/configure.in
+++ b/configure.in
@@ -2628,6 +2628,16 @@ fi
 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 --git a/dovecot.service.in b/dovecot.service.in
new file mode 100644
index 000..db03946
--- /dev/null
+++ b/dovecot.service.in
@@ -0,0 +1,8 @@
+[Unit]
+Description=Dovecot IMAP/POP3 email server
+After=local-fs.target network.target
+
+[Service]
+Type=simple
+execsta...@sbindir@/dovecot -F
+NonBlocking=yes
diff --git a/dovecot.socket b/dovecot.socket
new file mode 100644
index 000..0fdef6f
--- /dev/null
+++ b/dovecot.socket
@@ -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 --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c
index e2dc98d..5925bb6 100644
--- a/src/lib-master/master-service.c
+++ b/src/lib-master/master-service.c
@@ -400,6 +400,10 @@ void master_service_env_clean(bool preserve_home)
 #ifdef DEBUG
GDB,
 #endif
+#ifdef HAVE_SYSTEMD
+   LISTEN_PID,
+   LISTEN_FDS,
+#endif
NULL
};
env_clean_except(preserve_envs + (preserve_home ? 0 : 1));
diff --git a/src/master/Makefile.am b/src/master/Makefile.am
index 526b75b..9d3ad78 100644
--- a/src/master/Makefile.am
+++ b/src/master/Makefile.am
@@ -2,6 +2,11 @@ pkglibexecdir = $(libexecdir)/dovecot
 
 sbin_PROGRAMS = dovecot
 
+if HAVE_SYSTEMD
+SYSTEMD_SOURCES = sd-daemon.c
+endif
+
+
 AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
-I$(top_srcdir)/src/lib-settings \
@@ -27,13 +32,15 @@ dovecot_SOURCES = \
service-monitor.c \
service-process.c \
service-process-notify.c \
-   service.c
+   service.c \
+   

[Dovecot] add basic systemd support to dovecot

2010-10-20 Thread Christophe Fergeau
Hi all,

In the last days, I've been trying to add support for systemd[1]
socket activation to dovecot. The basic idea is that systemd takes
care of opening the sockets needed by dovecot to communicate with
external processes, and when a connection happens on one of these
sockets, systemd spawns dovecot, and then dovecot uses these sockets
instead of creating its own sockets. The main reason why I hacked on
this was that I wanted to get on-demand startup of dovecot on my home
box.

WIth the patch attached to this email, I'm now able to do that. The
patch includes a dovecot.socket file which should be seen as a sample
file, however I'm not sure what is the best way to handle this file
(systemd uses it to know which sockets dovecot needs).

What I wanted to ask the list for now is if such a patch is wanted,
and to get feedback on how things are done in it, and what should be
improved in it. [2] and [3] might be useful reading while looking at
the patch.

Thanks in advance for the feedback!

Christophe

[1] http://www.freedesktop.org/wiki/Software/systemd
[2] http://0pointer.de/public/systemd-man/daemon.html
[3] http://0pointer.de/public/systemd-man/sd-daemon.html


systemd.diff
Description: Binary data