Source: logrotate
Version: 3.8.7-2
Severity: wishlist
Tags: patch

Hi,

the attached patch backports the systemd timer and service units from upstream
version 3.11.0 and adds a check to the cron script to only run on non-systemd
systems.

-- Package-specific info:
Contents of /etc/logrotate.d
total 20
-rw-r--r-- 1 root root 173 Apr  5  2016 apt
-rw-r--r-- 1 root root  79 Mar  5  2016 aptitude
-rw-r--r-- 1 root root 181 Jun 17  2016 cups-daemon
-rw-r--r-- 1 root root 232 Jun 10  2015 dpkg
-rw-r--r-- 1 root root  82 Mar 21  2016 dracut-core


-- System Information:
Debian Release: stretch/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (103, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-rc8-amd64 (SMP w/4 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

-- no debconf information
>From 1a162ea16ea651f3b5f6a14ac93ec0d4a62f3a15 Mon Sep 17 00:00:00 2001
From: Daniel Schaal <daniel@schaal.email>
Date: Sat, 31 Dec 2016 17:49:17 +0100
Subject: [PATCH] Add systemd timer and skip cron script on systems running
 systemd

---
 debian/control           |  2 +-
 debian/cron.daily        |  2 +-
 debian/logrotate.install |  6 ++++--
 debian/logrotate.service | 11 +++++++++++
 debian/logrotate.timer   | 11 +++++++++++
 debian/rules             | 11 ++++++++++-
 6 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 debian/logrotate.service
 create mode 100644 debian/logrotate.timer

diff --git a/debian/control b/debian/control
index 4e6a9ad..15e0d87 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: logrotate
 Section: admin
 Priority: important
 Maintainer: Paul Martin <p...@debian.org>
-Build-Depends: libpopt-dev, debhelper (>= 9),
+Build-Depends: libpopt-dev, debhelper (>= 9), dh-systemd,
  libselinux1-dev [linux-any], libacl1-dev [linux-any]
 Vcs-Svn: http://svn.fedorahosted.org/svn/logrotate/
 Homepage: https://fedorahosted.org/logrotate/
diff --git a/debian/cron.daily b/debian/cron.daily
index f4f56a9..1d907be 100644
--- a/debian/cron.daily
+++ b/debian/cron.daily
@@ -1,4 +1,4 @@
 #!/bin/sh
 
-test -x /usr/sbin/logrotate || exit 0
+test -x /usr/sbin/logrotate -a \! -d /lib/systemd/system || exit 0
 /usr/sbin/logrotate /etc/logrotate.conf
diff --git a/debian/logrotate.install b/debian/logrotate.install
index d4696ba..2291f02 100644
--- a/debian/logrotate.install
+++ b/debian/logrotate.install
@@ -1,2 +1,4 @@
-logrotate              usr/sbin/
-debian/logrotate.conf  etc/
+logrotate                      usr/sbin/
+debian/logrotate.conf          etc/
+debian/logrotate.service       lib/systemd/system
+debian/logrotate.timer         lib/systemd/system
diff --git a/debian/logrotate.service b/debian/logrotate.service
new file mode 100644
index 0000000..e276878
--- /dev/null
+++ b/debian/logrotate.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Rotate log files
+Documentation=man:logrotate(8) man:logrotate.conf(5)
+ConditionACPower=true
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/logrotate /etc/logrotate.conf
+Nice=19
+IOSchedulingClass=best-effort
+IOSchedulingPriority=7
diff --git a/debian/logrotate.timer b/debian/logrotate.timer
new file mode 100644
index 0000000..8f405d5
--- /dev/null
+++ b/debian/logrotate.timer
@@ -0,0 +1,11 @@
+[Unit]
+Description=Daily rotation of log files
+Documentation=man:logrotate(8) man:logrotate.conf(5)
+
+[Timer]
+OnCalendar=daily
+AccuracySec=12h
+Persistent=true
+
+[Install]
+WantedBy=timers.target
diff --git a/debian/rules b/debian/rules
index ad020e4..4628b3b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -22,7 +22,7 @@ endif
 
 
 %:
-       dh $@
+       dh $@ --with systemd
 
 override_dh_auto_build:
 ifeq ($(DEB_HOST_ARCH_OS),linux)
@@ -46,3 +46,12 @@ ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
        cd test ; ./test
   endif
 endif
+
+override_dh_systemd_enable:
+       dh_systemd_enable --package=logrotate logrotate.timer
+
+override_dh_systemd_start:
+       dh_systemd_start --package=logrotate logrotate.timer
+       dh_systemd_start --package=logrotate --no-start logrotate.service
+
+override_dh_installinit:
-- 
2.11.0

Reply via email to