When availble, systemd unit files can be leveraged by users to enable calling msync for you on a regular basis. This can also be used to allow you to configure fetching mail at differnt intervals for different configurations.
In order to use the systemd unit files a user must explicitly enable and then start the mbsync systemd timer for themselves: systemctl --user stop mbsync-oneshot.timer systemctl --user disable mbsync-oneshot.timer The system default settings are configured to check for mail every 15 minutes for all of your configured channels, and will only trigger if you have your home directory configuration file ~/.mbsyncrc. If users need to customize the system defaults they are encouraged to use the system default files as base and install modified versions on their ${XDG_DATA_HOME}/systemd/user (.config/systemd/user/) directory. Add support for this and document how to use all this. --- .gitignore | 3 + Config.mk.in | 4 + Makefile.am | 11 ++ configure.ac | 15 ++- m4/features.m4 | 21 ++++ m4/paths.m4 | 47 ++++++++ m4/systemd.m4 | 201 ++++++++++++++++++++++++++++++++ src/mbsync.1 | 59 ++++++++++ units/mbsync-oneshot.service.in | 11 ++ units/mbsync-oneshot.timer.in | 10 ++ 10 files changed, 381 insertions(+), 1 deletion(-) create mode 100644 Config.mk.in create mode 100644 m4/features.m4 create mode 100644 m4/paths.m4 create mode 100644 m4/systemd.m4 create mode 100644 units/mbsync-oneshot.service.in create mode 100644 units/mbsync-oneshot.timer.in diff --git a/.gitignore b/.gitignore index 310c028..18c6ae7 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ Makefile Makefile.in +Config.mk +units/mbsync-oneshot.service +units/mbsync-oneshot.timer diff --git a/Config.mk.in b/Config.mk.in new file mode 100644 index 0000000..f45a136 --- /dev/null +++ b/Config.mk.in @@ -0,0 +1,4 @@ +CONFIG_SYSTEMD_DEV := @systemddev@ +CONFIG_SYSTEMD_INIT := @systemdisinit@ +SYSTEMD_CFLAGS := @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS := @SYSTEMD_LIBS@ diff --git a/Makefile.am b/Makefile.am index 557742f..0b9b8b6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +-include $(CURDIR)/Config.mk + SUBDIRS = src bin_SCRIPTS = mbsync-get-cert EXTRA_DIST = debian isync.spec $(bin_SCRIPTS) @@ -74,4 +76,13 @@ rpm: dist rpm-ia32: dist CFLAGS="-O2 -m32 -march=i686" rpmbuild --target i686-unknown-linux --clean -ta $(PACKAGE)-$(VERSION).tar.gz +.PHONY: reload +reload: + -systemctl daemon-reload + +systemduserunitdir = @systemduserunitdir@ +systemduserunit_DATA = units/mbsync-oneshot.service units/mbsync-oneshot.timer + +install-data-hook: reload + doc_DATA = README TODO NEWS ChangeLog AUTHORS diff --git a/configure.ac b/configure.ac index f56ed81..598375c 100644 --- a/configure.ac +++ b/configure.ac @@ -196,7 +196,20 @@ fi AM_CONDITIONAL(with_compat, test "x$ob_cv_enable_compat" != xno -a "x$ac_cv_berkdb4" = xyes) AM_CONDITIONAL(with_mdconvert, test "x$ac_cv_berkdb4" = xyes) -AC_CONFIG_FILES([Makefile src/Makefile isync.spec]) +AC_CONFIG_FILES([Makefile + Config.mk + units/mbsync-oneshot.service + units/mbsync-oneshot.timer + src/Makefile + isync.spec]) +m4_include([m4/features.m4]) +m4_include([m4/systemd.m4]) +m4_include([m4/paths.m4]) + +AX_LOCAL_EXPAND_CONFIG() +AX_AVAILABLE_SYSTEMD() +AM_CONDITIONAL(CONFIG_SYSTEMD_INIT, [test x"$systemdisinit" = xy]) +AM_CONDITIONAL(CONFIG_SYSTEMD_DEV, [test x"$systemddev" = xy]) AC_OUTPUT AC_MSG_RESULT() diff --git a/m4/features.m4 b/m4/features.m4 new file mode 100644 index 0000000..bd672ab --- /dev/null +++ b/m4/features.m4 @@ -0,0 +1,21 @@ +AC_DEFUN([AX_ARG_DEFAULT_ENABLE], [ +AC_ARG_ENABLE([$1], AS_HELP_STRING([--disable-$1], [$2 (default is ENABLED)])) +AX_PARSE_VALUE([$1], [y]) +]) + +AC_DEFUN([AX_ARG_DEFAULT_DISABLE], [ +AC_ARG_ENABLE([$1], AS_HELP_STRING([--enable-$1], [$2 (default is DISABLED)])) +AX_PARSE_VALUE([$1], [n]) +]) + +dnl This function should not be called outside of this file +AC_DEFUN([AX_PARSE_VALUE], [ +AS_IF([test "x$enable_$1" = "xno"], [ + ax_cv_$1="n" +], [test "x$enable_$1" = "xyes"], [ + ax_cv_$1="y" +], [test -z $ax_cv_$1], [ + ax_cv_$1="$2" +]) +$1=$ax_cv_$1 +AC_SUBST($1)]) diff --git a/m4/paths.m4 b/m4/paths.m4 new file mode 100644 index 0000000..2ab99bd --- /dev/null +++ b/m4/paths.m4 @@ -0,0 +1,47 @@ +# paths.m4 - Macros to help expand configure variables early -*- Autoconf -*- +# +# Copyright (C) 2014 Luis R. Rodriguez <mcg...@suse.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +dnl these helpers expands generic autotools variables early so we can use +dnl these for substitutions with AC_CONFIG_FILES(). +AC_DEFUN([AX_LOCAL_EXPAND_CONFIG], [ +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix + +dnl BINDIR=$prefix/bin +BINDIR=`eval echo $bindir` +AC_SUBST(BINDIR) + +SBINDIR=`eval echo $sbindir` +AC_SUBST(SBINDIR) + +LIBEXEC=`eval echo $libexec` +AC_SUBST(LIBEXEC) + +LIBDIR=`eval echo $libdir` +AC_SUBST(LIBDIR) + +SHAREDIR=`eval echo $prefix/share` +AC_SUBST(SHAREDIR) + +dnl Not part of a ./configure option, does LSB define it? +RUNDIR="/var/run" +AC_SUBST(RUNDIR) + +CONFIG_DIR=/etc +AC_SUBST(CONFIG_DIR) +]) diff --git a/m4/systemd.m4 b/m4/systemd.m4 new file mode 100644 index 0000000..5347b62 --- /dev/null +++ b/m4/systemd.m4 @@ -0,0 +1,201 @@ +# systemd.m4 - Macros to check for and enable systemd -*- Autoconf -*- +# +# Copyright (C) 2014,2019 Luis Chamberlain <mcg...@kernel.org> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +dnl Some optional path options when your system is detected as systemd being +dnl the init process. +dnl +dnl We expect this to grow. For the list of variables refer to: +dnl +dnl pkg-config --print-variables systemd +dnl +dnl To see what each variable has, for instance for systemduserunitdir: +dnl +dnl pkg-config --variable=systemduserunitdir systemd +AC_DEFUN([AX_SYSTEMD_INIT_OPTIONS], [ + AC_ARG_WITH(systemduserunitdir, [ --with-systemduserunitdir=DIR set user directory for systemd service files], + systemduserunitdir="$withval", systemduserunitdir="") + AC_SUBST(systemduserunitdir) + + AC_ARG_WITH(systemdsystemunitdir, [ --with-systemdsystemunitdir=DIR set directory for systemd service files], + systemdsystemunitdir="$withval", systemdsystemunitdir="") + AC_SUBST(systemdsystemunitdir) + + AC_ARG_WITH(modulesloaddir, [ --with-modulesloaddir=DIR set directory for systemd modules load files], + modulesloaddir="$withval", modulesloaddir="") + AC_SUBST(modulesloaddir) +]) + +AC_DEFUN([AX_ENABLE_SYSTEMD_SYSTEM_OPTS], [ + AX_ARG_DEFAULT_ENABLE([systemdisinit], [Confirms systemd is your init process]) + AX_SYSTEMD_INIT_OPTIONS() +]) + +AC_DEFUN([AX_ALLOW_SYSTEMD_SYSTEM_OPTS], [ + AX_ARG_DEFAULT_DISABLE([systemdisinit], [Disables systemd as your init process]) + AX_SYSTEMD_INIT_OPTIONS() +]) + +AC_DEFUN([AX_ENABLE_SYSTEMD_OPTS], [ + AX_ARG_DEFAULT_ENABLE([systemddev], [Disable systemd development support]) +]) + +AC_DEFUN([AX_ENABLE_SYSTEMD_INIT_OPTS], [ + AX_ARG_DEFAULT_ENABLE([systemdisinit], [Disable systemd init support]) + AX_SYSTEMD_INIT_OPTIONS() +]) + +AC_DEFUN([AX_ALLOW_SYSTEMD_DEV], [ + AX_ARG_DEFAULT_DISABLE([systemddev], [Enable systemd development support]) +]) + +AC_DEFUN([AX_ALLOW_SYSTEMD_INIT], [ + AX_ARG_DEFAULT_DISABLE([systemdisinit], [Enable systemd init support]) + AX_SYSTEMD_INIT_OPTIONS() +]) + +AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [ + AC_CHECK_HEADER([systemd/sd-daemon.h], [ + AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [libsystemddaemon="y"]) + ]) + AS_IF([test "x$libsystemddaemon" = x], [ + AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library]) + ]) + + PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon]) + dnl pkg-config older than 0.24 does not set these for + dnl PKG_CHECK_MODULES() worth also noting is that as of version 208 + dnl of systemd pkg-config --cflags currently yields no extra flags yet. + AC_SUBST([SYSTEMD_CFLAGS]) + AC_SUBST([SYSTEMD_LIBS]) + +]) + +AC_DEFUN([AX_CHECK_SYSTEMD_VARS], [ + AS_IF([test "x$systemduserunitdir" = x], [ + systemduserunitdir='${prefix}/lib/systemd/user' + AC_SUBST(systemduserunitdir) + ], []) + + AS_IF([test "x$systemduserunitdir" = x], [ + AC_MSG_ERROR([systemduserunitdir is unset]) + ], []) + + AS_IF([test "x$systemdsystemunitdir" = x], [ + systemdsystemunitdir='${prefix}/lib/systemd/system/' + AC_SUBST(systemdsystemunitdir) + ], []) + + AS_IF([test "x$systemdsystemunitdir" = x], [ + AC_MSG_ERROR([systemdsystemunitdir is unset]) + ], []) + + AS_IF([test "x$modulesloaddir" = x], [ + modulesloaddir='${prefix}/lib/modules-load.d/' + AC_SUBST(modulesloaddir) + ], []) + + AS_IF([test "x$modulesloaddir" = x], [ + AC_MSG_ERROR([modulesloaddir is unset]) + ], []) +]) + + +AC_DEFUN([AX_CHECK_SYSTEMD_DEV], [ + dnl Respect user override to disable + AS_IF([test "x$enable_systemd" != "xno"], [ + AS_IF([test "x$systemddev" = "xy" ], [ + AC_DEFINE([HAVE_SYSTEMD], [1], [Systemd development libraries available and enabled]) + systemddev=y + AX_CHECK_SYSTEMD_LIBS() + ],[systemddev=n]) + ],[systemddev=n]) +]) + +AC_DEFUN([AX_CHECK_SYSTEMD_INIT], [ + dnl Respect user override to disable + AS_IF([test "x$enable_systemdinit" != "xno"], [ + AS_IF([test "x$systemdisinit" = "xy" ], [ + AC_DEFINE([HAVE_SYSTEMD_INIT], [1], [Systemd init running]) + systemdisinit=y + AX_CHECK_SYSTEMD_VARS() + ],[systemdisinit=n]) + ],[systemdisinit=n]) +]) + +AC_DEFUN([AX_CHECK_SYSTEMD_INIT_ENABLE_AVAILABLE], [ + AC_CACHE_CHECK([if systemd is your init], [systemd_cv_init], + [systemd_cv_init=no + systemdpid=x`pidof -s systemd` + if test "$systemdpid" != x; then + systemd_cv_init=yes + systemdisinit=y + fi]) +]) + +AC_DEFUN([AX_CHECK_SYSTEMD_DEV_ENABLE_AVAILABLE], [ + AC_CHECK_HEADER([systemd/sd-daemon.h], [ + AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [systemd="y"]) + ]) +]) + +dnl Enables systemd by default and requires a --disable-systemd option flag +dnl to configure if you want to disable. +AC_DEFUN([AX_ENABLE_SYSTEMD], [ + AX_ENABLE_SYSTEMD_INIT_OPTS() + AX_ENABLE_SYSTEMD_OPTS() + AX_CHECK_SYSTEMD_INIT() + AX_CHECK_SYSTEMD_DEV() +]) + +dnl Systemd will be disabled by default and requires you to run configure with +dnl --enable-systemd to look for and enable systemd. +AC_DEFUN([AX_ALLOW_SYSTEMD], [ + AX_ALLOW_SYSTEMD_INIT() + AX_ALLOW_SYSTEMD_DEV() + AX_CHECK_SYSTEMD_INIT() + AX_CHECK_SYSTEMD_DEV() +]) + +dnl Systemd will be disabled by default but if your build system is detected +dnl to have systemd build libraries it will be enabled. Note that this +dnl does not allow you to disable with --disable-systemd, for that use +dnl AX_ENABLE_SYSTEMD() instead. +AC_DEFUN([AX_AVAILABLE_SYSTEMD], [ + dnl allows you to force enable systemd-as-init through command line + AX_ALLOW_SYSTEMD_INIT() + + dnl checks if you have systemd as init and enables it if available + AX_CHECK_SYSTEMD_INIT_ENABLE_AVAILABLE() + + dnl checks to make sure init environment variables make sense. + dnl If you enabled systemd but there are no variables for the paths + dnl defined, we'll set them. + AX_CHECK_SYSTEMD_INIT() + + + dnl allows you to force enable systemd dev environment + AX_ALLOW_SYSTEMD_DEV() + + dnl checks if you have systemd dev environment and enables it if available + AX_CHECK_SYSTEMD_DEV_ENABLE_AVAILABLE() + + dnl checks to make sure development environment variables make sense. + dnl If you *did* enable systemd development environment a final check + dnl is done to ensure you have the proper dev environment present. + AX_CHECK_SYSTEMD_DEV() +]) diff --git a/src/mbsync.1 b/src/mbsync.1 index 4dcd5aa..2bad57c 100644 --- a/src/mbsync.1 +++ b/src/mbsync.1 @@ -730,6 +730,53 @@ before the mailbox is expunged. There is no risk as long as the IMAP mailbox is accessed by only one client (including \fBmbsync\fR) at a time. .. +.SH USER SYSTEMD UNITS +On systemd capable systems users can rely on the user systemd unit file timer to +configure what configuration file to use and how often \fBmbsync\fR should +check mail for you. The system default settings are configured to check for +mail every 15 minutes for all of your configured channels, and will only +trigger if you have your home directory configuration file +.B ~/.mbsyncrc. +If +.B ~/.mbsyncrc +is not present the timmer will not run. +.TP +To enable and start the timer: +.br +.B systemctl --user enable mbsync-oneshot.timer +.br +.B systemctl --user start mbsync-oneshot.timer +.P +If you enabled the timer but forgot to write your +.B ~/.mbsyncrc. +configuration file you can +start the timer after you've created your +.B ~/.mbsyncrc. +.TP +To stop and disable the timer: +.br +.B systemctl --user stop mbsync-oneshot.timer +.br +.B systemctl --user disable mbsync-oneshot.timer +.P +If you need to override the system settings you can copy the system unit +and modify alternatives on your your +.B ${XDG_DATA_HOME}/systemd/user +( +.B .config/systemd/user/ +) +directory. +.TP +Then let systemd know about these custom files's availability: +.br +.B systemctl --user daemon-reload +.P +You can then enable and start timer as described above. +.P +Custom systemd unit timer and service files can be used, for instance, +to allow you to fetch mail at different frequencies for different +configurations. +.. .SH FILES .TP .B ~/.mbsyncrc @@ -737,6 +784,18 @@ Default configuration file .TP .B ~/.mbsync/ Directory containing synchronization state files +.TP +Only applicable on systemd systems: +.TP +.B /usr/lib/systemd/user/mbsync-oneshot.timer +System mbsync timer, +.B how often +to run the mbsync systemd unit. +.TP +.B /usr/lib/systemd/user/mbsync-oneshot.service +System default mbsync service unit file, +.B how +to run mbsync. .. .SH SEE ALSO mdconvert(1), mutt(1), maildir(5) diff --git a/units/mbsync-oneshot.service.in b/units/mbsync-oneshot.service.in new file mode 100644 index 0000000..515197d --- /dev/null +++ b/units/mbsync-oneshot.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=mbsync service (oneshot) +Documentation=man:mbsync(1) +ConditionPathExists=%h/.mbsyncrc + +[Service] +Type=oneshot +ExecStart=@BINDIR@/mbsync -V -a + +[Install] +WantedBy=mail.target diff --git a/units/mbsync-oneshot.timer.in b/units/mbsync-oneshot.timer.in new file mode 100644 index 0000000..213387f --- /dev/null +++ b/units/mbsync-oneshot.timer.in @@ -0,0 +1,10 @@ +[Unit] +Description=mbsync query timer +ConditionPathExists=%h/.mbsyncrc + +[Timer] +OnBootSec=1m +OnUnitInactiveSec=15m + +[Install] +WantedBy=default.target -- 2.20.1 _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel