From e09e97e4327a96f8583ae74095a0fa5cbb8188a3 Mon Sep 17 00:00:00 2001
From: "Igor Zalatov (from Citadel PC)" <flyrouter@gmail.com>
Date: Sat, 11 Dec 2021 00:44:32 +0300
Subject: [PATCH] Basic iteration by crond

---
 general/overlay/etc/crontab         | 13 +++++++
 general/overlay/etc/init.d/S60crond | 60 +++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 general/overlay/etc/crontab
 create mode 100755 general/overlay/etc/init.d/S60crond

diff --git a/general/overlay/etc/crontab b/general/overlay/etc/crontab
new file mode 100644
index 00000000..f4362695
--- /dev/null
+++ b/general/overlay/etc/crontab
@@ -0,0 +1,13 @@
+#
+# Example of job definition:
+# .---------------- minute (0 - 59)
+# |    .------------- hour (0 - 23)
+# |    |      .---------- day of month (1 - 31)
+# |    |      |     .------- month (1 - 12) OR jan,feb,mar,apr ...
+# |    |      |     |     .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
+# |    |      |     |     |
+# *    *      *     *     *     command to be executed
+#
+#
+*/5    *      *     *     *     /usr/bin/logger -p cron.info -t crond WTF ?
+#
diff --git a/general/overlay/etc/init.d/S60crond b/general/overlay/etc/init.d/S60crond
new file mode 100755
index 00000000..8e67e518
--- /dev/null
+++ b/general/overlay/etc/init.d/S60crond
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+DAEMON="crond"
+PIDFILE="/var/run/$DAEMON.pid"
+
+CROND_ARGS="-f -l 6"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
+
+# The mini-snmpd does not create a pidfile, so pass "-n" in the command line
+# and use "-m" to instruct start-stop-daemon to create one.
+start() {
+	[ -d /var/spool/cron/crontabs ] || mkdir -p /var/spool/cron/crontabs
+	[ -f /etc/crontab ] && ln -sf /etc/crontab /var/spool/cron/crontabs/root
+	#
+	printf 'Starting %s: ' "$DAEMON"
+	[ -f /usr/sbin/$DAEMON ] || echo -en "DISABLED, "
+	# shellcheck disable=SC2086 # we need the word splitting
+	start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
+		-- $CROND_ARGS
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+stop() {
+	printf 'Stopping %s: ' "$DAEMON"
+	[ -f /usr/sbin/$DAEMON ] || echo -en "DISABLED, "
+	start-stop-daemon -K -q -p "$PIDFILE"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		rm -f "$PIDFILE"
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+case "$1" in
+	start|stop|restart)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac