[pve-devel] [PATCH manager v2 14/17] pveupdate: replace cron job with systemd timer

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Mar 12 14:14:05 CET 2018


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 bin/init.d/Makefile                 |  2 ++
 bin/init.d/pve-daily-update.service |  9 +++++++++
 bin/init.d/pve-daily-update.timer   | 10 ++++++++++
 debian/postinst                     | 17 +++--------------
 4 files changed, 24 insertions(+), 14 deletions(-)
 create mode 100644 bin/init.d/pve-daily-update.service
 create mode 100644 bin/init.d/pve-daily-update.timer

diff --git a/bin/init.d/Makefile b/bin/init.d/Makefile
index 45180244..f0fc7f9c 100644
--- a/bin/init.d/Makefile
+++ b/bin/init.d/Makefile
@@ -11,6 +11,8 @@ SERVICES=			\
 	pveproxy.service 	\
 	spiceproxy.service	\
 	pve-storage.target	\
+	pve-daily-update.service\
+	pve-daily-update.timer	\
 	pvesr.service		\
 	pvesr.timer
 
diff --git a/bin/init.d/pve-daily-update.service b/bin/init.d/pve-daily-update.service
new file mode 100644
index 00000000..f174241f
--- /dev/null
+++ b/bin/init.d/pve-daily-update.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Daily PVE download activities
+After=network-online.target
+Wants=network-online.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/pveupdate
+
diff --git a/bin/init.d/pve-daily-update.timer b/bin/init.d/pve-daily-update.timer
new file mode 100644
index 00000000..bf8d0b54
--- /dev/null
+++ b/bin/init.d/pve-daily-update.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Daily PVE download activities
+
+[Timer]
+OnCalendar=*-*-* 2:00
+RandomizedDelaySec=4h
+Persistent=true
+
+[Install]
+WantedBy=timers.target
diff --git a/debian/postinst b/debian/postinst
index 5f827933..e6aca419 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -32,26 +32,15 @@ case "$1" in
 
     mkdir /etc/pve 2>/dev/null || true
 
-    # remove old cron.daily update job to randomize it
-    if test -e /etc/cron.daily/pve; then
-	echo "Remove old update script from cron.daily"
-	rm /etc/cron.daily/pve
-    fi
-
     if dpkg --compare-versions "$2" '<=' '5.1-47'; then
+	# remove cron update job, superseeded by systemd timer
+	rm -f /etc/cron.d/pveupdate
+
 	# remove old/usused init.d files
 	OLD_INITD_FILES="pvebanner pvenetcommit pve-manager pvedaemon pveproxy pvestatd spiceproxy"
 	for f in ${OLD_INITD_FILES}; do rm -f "/etc/init.d/$f"; done
     fi
 
-    # create new daily randomize update cronjob if not exist
-    MIN="$(shuf -i 0-59 -n 1)"
-    HOUR="$(shuf -i 2-5 -n 1)"
-    cat <<EOF >/etc/cron.d/pveupdate
-# automatically generated - do not edit
-${MIN} ${HOUR} * * * root /usr/bin/pveupdate
-EOF
-
     if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
 	mkdir -p /var/lib/pve-manager/apl-info
 	cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
-- 
2.14.2





More information about the pve-devel mailing list