From 56147b45320723e314f107e4c4c04ed3fcdd776b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Sun, 15 May 2016 21:08:10 +0200 Subject: add systemd service and timer This add systemd service file and timer. To enable the timer: $ systemctl enable etckeeper.timer When enabled the timer will auto-commit 15 minutes after system boot and every 24 hours afer that. Signed-off-by: Christian Hesse --- Makefile | 4 ++++ systemd/etckeeper | 19 +++++++++++++++++++ systemd/etckeeper.service | 12 ++++++++++++ systemd/etckeeper.timer | 10 ++++++++++ 4 files changed, 45 insertions(+) create mode 100755 systemd/etckeeper create mode 100644 systemd/etckeeper.service create mode 100644 systemd/etckeeper.timer diff --git a/Makefile b/Makefile index 640e1e8..206e44c 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,10 @@ install: etckeeper.version $(INSTALL_DATA) etckeeper.8 $(DESTDIR)$(mandir)/man8/etckeeper.8 mkdir -p $(DESTDIR)$(completiondir) $(INSTALL_DATA) bash_completion $(DESTDIR)$(completiondir)/etckeeper + mkdir -p $(DESTDIR)$(prefix)/lib/systemd/system/ $(DESTDIR)$(prefix)/lib/systemd/scripts/ + $(INSTALL) systemd/etckeeper $(DESTDIR)$(prefix)/lib/systemd/scripts/etckeeper + $(INSTALL_DATA) systemd/etckeeper.service $(DESTDIR)$(prefix)/lib/systemd/system/etckeeper.service + $(INSTALL_DATA) systemd/etckeeper.timer $(DESTDIR)$(prefix)/lib/systemd/system/etckeeper.timer ifeq ($(HIGHLEVEL_PACKAGE_MANAGER),apt) mkdir -p $(DESTDIR)$(etcdir)/apt/apt.conf.d $(INSTALL_DATA) apt.conf $(DESTDIR)$(etcdir)/apt/apt.conf.d/05etckeeper diff --git a/systemd/etckeeper b/systemd/etckeeper new file mode 100755 index 0000000..5255691 --- /dev/null +++ b/systemd/etckeeper @@ -0,0 +1,19 @@ +#!/bin/sh +set -e +if [ -x /usr/bin/etckeeper ] && [ -e /etc/etckeeper/etckeeper.conf ]; then + . /etc/etckeeper/etckeeper.conf + if [ "$AVOID_DAILY_AUTOCOMMITS" != "1" ]; then + # avoid autocommit if an install run is in progress + lockfile=/var/cache/etckeeper/packagelist.pre-install + if [ -e "$lockfile" ] && [ -n "$(find "$lockfile" -mtime +1)" ]; then + rm -f "$lockfile" # stale + fi + if [ ! -e "$lockfile" ]; then + AVOID_SPECIAL_FILE_WARNING=1 + export AVOID_SPECIAL_FILE_WARNING + if etckeeper unclean; then + etckeeper commit "daily autocommit" >/dev/null + fi + fi + fi +fi diff --git a/systemd/etckeeper.service b/systemd/etckeeper.service new file mode 100644 index 0000000..45912bb --- /dev/null +++ b/systemd/etckeeper.service @@ -0,0 +1,12 @@ +[Unit] +Description=Autocommit of changes in /etc directory +Documentation=man:etckeeper(8) +DefaultDependencies=no +Conflicts=shutdown.target +After=local-fs.target time-sync.target +Before=shutdown.target + +[Service] +Type=oneshot +ExecStart=/usr/lib/systemd/scripts/etckeeper +IOSchedulingClass=idle diff --git a/systemd/etckeeper.timer b/systemd/etckeeper.timer new file mode 100644 index 0000000..364c089 --- /dev/null +++ b/systemd/etckeeper.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Daily autocommit of changes in /etc directory +Documentation=man:etckeeper(8) + +[Timer] +OnBootSec=15min +OnUnitActiveSec=1d + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3