* [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
* [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd init script
2024-06-05 11:13 [Buildroot] [PATCH 1/2] package/busybox: Add crond init script Fiona Klute via buildroot
@ 2024-06-05 11:13 ` 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
1 sibling, 1 reply; 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
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 <fiona.klute+wiwa@gmx.de>
---
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?
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"
+IFPLUGD_ARGS="${IFPLUGD_ARGS} -i ${IFACE}"
+
+# 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
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ return "$status"
+}
+
+stop() {
+ printf 'Stopping %s for %s: ' "$DAEMON" "$IFACE"
+ 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
+ rm -f "$PIDFILE"
+ echo "OK"
+ 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 a3ba12f8e2..22ce04f473 100644
--- a/package/busybox/busybox.mk
+++ b/package/busybox/busybox.mk
@@ -323,6 +323,17 @@ define BUSYBOX_INSTALL_CROND_SCRIPT
endef
endif
+# Only install our ifplugd script if no other package does it.
+ifeq ($(BR2_PACKAGE_IFPLUGD),)
+define BUSYBOX_INSTALL_IFPLUGD_SCRIPT
+ if grep -q CONFIG_IFPLUGD=y $(@D)/.config; \
+ then \
+ $(INSTALL) -m 0755 -D package/busybox/S41ifplugd \
+ $(TARGET_DIR)/etc/init.d/S41ifplugd; \
+ fi;
+endef
+endif
+
ifeq ($(BR2_INIT_BUSYBOX),y)
define BUSYBOX_INSTALL_INITTAB
if test ! -e $(TARGET_DIR)/etc/inittab; then \
@@ -418,6 +429,7 @@ define BUSYBOX_INSTALL_INIT_OPENRC
$(BUSYBOX_INSTALL_MDEV_SCRIPT)
$(BUSYBOX_INSTALL_LOGGING_SCRIPT)
$(BUSYBOX_INSTALL_WATCHDOG_SCRIPT)
+ $(BUSYBOX_INSTALL_IFPLUGD_SCRIPT)
$(BUSYBOX_INSTALL_CROND_SCRIPT)
$(BUSYBOX_INSTALL_TELNET_SCRIPT)
endef
@@ -431,6 +443,7 @@ define BUSYBOX_INSTALL_INIT_SYSV
$(BUSYBOX_INSTALL_LOGGING_SCRIPT)
$(BUSYBOX_INSTALL_WATCHDOG_SCRIPT)
$(BUSYBOX_INSTALL_SYSCTL_SCRIPT)
+ $(BUSYBOX_INSTALL_IFPLUGD_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
* Re: [Buildroot] [PATCH 1/2] package/busybox: Add crond init script
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 7:57 ` Thomas Petazzoni via buildroot
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Petazzoni via buildroot @ 2024-07-15 7:57 UTC (permalink / raw)
To: Fiona Klute via buildroot; +Cc: Fiona Klute, Alvaro G . M
Hello Fiona,
On Wed, 5 Jun 2024 13:13:46 +0200
Fiona Klute via buildroot <buildroot@buildroot.org> wrote:
> 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>
Thanks, I applied your patch after making a few changes.
> +# 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.
After discussion with Arnout, we decided that our default of
/var/spool/cron didn't make sense. Indeed the crontab generally needs
to be persistent, so having it in a tmpfs as the out-of-the-box
experience didn't seem very appropriate. So we changed the default
Busybox configuration to set CONFIG_FEATURE_CROND_DIR="/etc/cron". So
of course, I dropped your comment above.
> + 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" \
Adjusted to use long options.
> + -- -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"
Ditto.
> + 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
And adjusted to use the loop of start-stop-daemon.
> +# 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 \
And here we create $(TARGET_DIR)/etc/cron/crontabs/ to make sure it
exists, otherwise crond doesn't start.
> + $(INSTALL) -m 0755 -D package/busybox/S50crond \
> + $(TARGET_DIR)/etc/init.d/S50crond; \
> + fi;
> +endef
> +endif
Thanks for this work!
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Buildroot] [PATCH 2/2] package/busybox: Add ifplugd init script
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
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Petazzoni via buildroot @ 2024-07-15 8:27 UTC (permalink / raw)
To: Fiona Klute via buildroot; +Cc: Fiona Klute, Alvaro G . M
Hello Fiona,
On Wed, 5 Jun 2024 13:13:47 +0200
Fiona Klute via buildroot <buildroot@buildroot.org> 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 <fiona.klute+wiwa@gmx.de>
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
^ permalink raw reply [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.