All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] package/busybox: Add crond init script
@ 2024-06-05 11:13 Fiona Klute via buildroot
  2024-06-05 11:13 ` [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd " Fiona Klute via buildroot
  2024-07-15  7:57 ` [Buildroot] [PATCH 1/2] package/busybox: Add crond " Thomas Petazzoni via buildroot
  0 siblings, 2 replies; 4+ messages in thread
From: Fiona Klute via buildroot @ 2024-06-05 11:13 UTC (permalink / raw)
  To: buildroot; +Cc: Fiona Klute, Alvaro G . M

The init script will be installed only if no other package provides
cron (currently that could be package/dcron). Users will need to
select a suitable location for their crontabs, using either runtime
configuration in /etc/default/crond or Busybox build
configuration. Note that crond fails to start if the crontabs
directory doesn't exist.

Signed-off-by: Fiona Klute <fiona.klute+wiwa@gmx.de>
---
 package/busybox/S50crond   | 65 ++++++++++++++++++++++++++++++++++++++
 package/busybox/busybox.mk | 13 ++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 package/busybox/S50crond

diff --git a/package/busybox/S50crond b/package/busybox/S50crond
new file mode 100644
index 0000000000..834c2787fa
--- /dev/null
+++ b/package/busybox/S50crond
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+DAEMON="crond"
+PIDFILE="/var/run/$DAEMON.pid"
+
+# Note that the Busybox default location for crontabs
+# /var/spool/cron/crontabs is on a tmpfs in the default Buildroot
+# filesystem layout. If you want persistent crontabs, override that
+# either using either the "-c" runtime option of crond in CROND_ARGS,
+# or the CONFIG_FEATURE_CROND_DIR Busybox build configuration option.
+CROND_ARGS=""
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
+
+# BusyBox' crond does not create a pidfile, so pass "-f" on the command line
+# and use "-m" to instruct start-stop-daemon to create one.
+start() {
+	printf 'Starting %s: ' "$DAEMON"
+	# shellcheck disable=SC2086 # we need the word splitting
+	start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
+		-- -f $CROND_ARGS
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+stop() {
+	printf 'Stopping %s: ' "$DAEMON"
+	start-stop-daemon -K -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"
+	status=$?
+	# wait for process to be gone
+	while true; do
+		pid="$( cat "${PIDFILE}" 2>/dev/null || true )"
+		{ [ -n "${pid}" ] && [ -d "/proc/${pid}" ]; } || break
+		sleep 0.1
+	done
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+		rm -f "$PIDFILE"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+restart() {
+	stop
+	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
diff --git a/package/busybox/busybox.mk b/package/busybox/busybox.mk
index eb5e7ad922..a3ba12f8e2 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -312,6 +312,17 @@ define BUSYBOX_INSTALL_SYSCTL_SCRIPT
 endef
 endif

+# Only install our crond script if no other package does it.
+ifeq ($(BR2_PACKAGE_DCRON),)
+define BUSYBOX_INSTALL_CROND_SCRIPT
+	if grep -q CONFIG_CROND=y $(@D)/.config; \
+	then \
+		$(INSTALL) -m 0755 -D package/busybox/S50crond \
+			$(TARGET_DIR)/etc/init.d/S50crond; \
+	fi;
+endef
+endif
+
 ifeq ($(BR2_INIT_BUSYBOX),y)
 define BUSYBOX_INSTALL_INITTAB
 	if test ! -e $(TARGET_DIR)/etc/inittab; then \
@@ -407,6 +418,7 @@ define BUSYBOX_INSTALL_INIT_OPENRC
 	$(BUSYBOX_INSTALL_MDEV_SCRIPT)
 	$(BUSYBOX_INSTALL_LOGGING_SCRIPT)
 	$(BUSYBOX_INSTALL_WATCHDOG_SCRIPT)
+	$(BUSYBOX_INSTALL_CROND_SCRIPT)
 	$(BUSYBOX_INSTALL_TELNET_SCRIPT)
 endef

@@ -419,6 +431,7 @@ define BUSYBOX_INSTALL_INIT_SYSV
 	$(BUSYBOX_INSTALL_LOGGING_SCRIPT)
 	$(BUSYBOX_INSTALL_WATCHDOG_SCRIPT)
 	$(BUSYBOX_INSTALL_SYSCTL_SCRIPT)
+	$(BUSYBOX_INSTALL_CROND_SCRIPT)
 	$(BUSYBOX_INSTALL_TELNET_SCRIPT)
 endef

--
2.45.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-15  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-05 11:13 [Buildroot] [PATCH 1/2] package/busybox: Add crond init script Fiona Klute via buildroot
2024-06-05 11:13 ` [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd " Fiona Klute via buildroot
2024-07-15  8:27   ` Thomas Petazzoni via buildroot
2024-07-15  7:57 ` [Buildroot] [PATCH 1/2] package/busybox: Add crond " Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.