Buildroot Archive on 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; 5+ 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] 5+ messages in thread
* Re: [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd init script
@ 2025-03-26 15:18 uuidxx
  0 siblings, 0 replies; 5+ messages in thread
From: uuidxx @ 2025-03-26 15:18 UTC (permalink / raw)
  To: Thomas Petazzoni via buildroot, Thomas Petazzoni via buildroot
  Cc: Fiona Klute, Alvaro G . M

Hello, Fiona and Thomas.

I'm currently using the 2025.02 branch. This script does not start ifplugd (Busybox's ifplugd) properly in busybox 1.37.0.

For now, I've changed this part of the code:

>	start-stop-daemon --start --background --make-pidfile \
>		--pidfile "$PIDFILE" --exec "/usr/sbin/$DAEMON" \
>		-- -n $IFPLUGD_ARGS

to this:

>	start-stop-daemon --start --background --exec "/usr/sbin/$DAEMON" \
>		-- -n $IFPLUGD_ARGS

and it starts ifplugd properly. I checked the /var/run/ directory and the file ifplugd.eth0.pid exists.

________________________________________
From: Thomas Petazzoni via buildroot
Sent:
To: Fiona Klute via buildroot
Cc: Fiona Klute; Alvaro G . M
Subject: Re: Re: [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd init script


Hello Fiona,

On Wed,  5 Jun 2024 13:13:47 +0200
Fiona Klute via buildroot  wrote:

> The init script will be installed only if no other package provides
> ifplugd (currently that could be package/ifplugd). Users can configure
> the interface(s) which ifplugd should watch either using
> /etc/default/ifplugd (for one interface) or using per-interface
> symlinks to the script in /etc/init.d (for any number of
> interfaces). The action script that ifplugd runs when a link change is
> detected must be supplied separately.
> 
> Signed-off-by: Fiona Klute 

I applied your patch, with some changes. See below.

> ---
> make check-package complains about "Incorrect PIDFILE value" in the
> script. To support running multiple instances I need to support
> multiple (per-interface) PID files. Is there a better way to handle
> that, or explicitly silence the check?

Silence the check. See below :-)

> 
>  package/busybox/S41ifplugd | 84 ++++++++++++++++++++++++++++++++++++++
>  package/busybox/busybox.mk | 13 ++++++
>  2 files changed, 97 insertions(+)
>  create mode 100644 package/busybox/S41ifplugd
> 
> diff --git a/package/busybox/S41ifplugd b/package/busybox/S41ifplugd
> new file mode 100644
> index 0000000000..4d3b56ab6d
> --- /dev/null
> +++ b/package/busybox/S41ifplugd
> @@ -0,0 +1,84 @@
> +#!/bin/sh
> +
> +DAEMON="ifplugd"
> +
> +# Each ifplugd instance handles only one interface, so this script is
> +# designed to be symlinked per interface. For each interface create a
> +# symlink with .IFACE appended to the name. E.g. to launch ifplugd for
> +# eth1 create a symlink from /etc/init.d/S41ifplugd.eth1 to this
> +# script. DEFAULT_IFACE sets the interface the non-symlink script will
> +# use, set it to empty in /etc/default/ifplugd to disable the default
> +# instance and use symlinked instances only.
> +DEFAULT_IFACE="eth0"
> +# If your action script is not in the default location
> +# /etc/ifplugd/ifplugd.action, use the "-r" option to set the
> +# location.
> +IFPLUGD_ARGS="-M"
> +
> +# shellcheck source=/dev/null
> +[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
> +
> +NAME_IFACE="$(basename "$0" | cut -s -d. -f2)"
> +if [ -n "$NAME_IFACE" ]; then
> +	IFACE="${NAME_IFACE}"
> +elif [ -n "$DEFAULT_IFACE" ]; then
> +	IFACE="${DEFAULT_IFACE}"
> +else
> +	# no interface configured
> +	exit 0
> +fi
> +
> +PIDFILE="/var/run/${DAEMON}.${IFACE}.pid"

I've added:

+# check-package disable Variables

above this line to ignore the PIDFILE warning.

> +# BusyBox' ifplugd does not create a pidfile, so pass "-n" in the
> +# command line and use "-m" to instruct start-stop-daemon to create
> +# one.
> +start() {
> +	printf 'Starting %s for %s: ' "$DAEMON" "$IFACE"
> +	# shellcheck disable=SC2086 # we need the word splitting
> +	start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
> +		-- -n $IFPLUGD_ARGS

And I fixed the script to use the long options.

> +	while true; do
> +		pid="$( cat "${PIDFILE}" 2>/dev/null || true )"
> +		{ [ -n "${pid}" ] && [ -d "/proc/${pid}" ]; } || break
> +		sleep 0.1
> +	done

And the start-stop-daemon loop.

Thanks!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

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

end of thread, other threads:[~2025-03-26 15:34 UTC | newest]

Thread overview: 5+ 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
  -- strict thread matches above, loose matches on Subject: below --
2025-03-26 15:18 [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd " uuidxx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox