[Buildroot] [PATCH v2] package/restorecond: Add new init script
José Pekkarinen
jose.pekkarinen at unikie.com
Fri Aug 20 11:23:22 UTC 2021
The current restorecond upstream init script is no
good fit for the user space generated by buildroot,
this script is an extension of the original, that
brings some changes from the debian init script to
use start-stop-daemon instead of daemon, while
removing dependencies on /etc/rc.d/init.d/functions
and /lib/lsb/init-functions.
Signed-off-by: José Pekkarinen <jose.pekkarinen at unikie.com>
---
[ v1 -> v2 ] Moved to upstream script template
package/restorecond/S02restorecond | 75 ++++++++++++++++++++++++++++++
package/restorecond/restorecond.mk | 4 +-
2 files changed, 77 insertions(+), 2 deletions(-)
create mode 100644 package/restorecond/S02restorecond
diff --git a/package/restorecond/S02restorecond b/package/restorecond/S02restorecond
new file mode 100644
index 0000000000..ae5acbf73a
--- /dev/null
+++ b/package/restorecond/S02restorecond
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+DAEMON=restorecond
+PIDFILE=/var/run/$DAEMON.pid
+
+RESTORECOND_ARGS=""
+
+start()
+{
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ printf 'Starting %s: ' "$DAEMON"
+ start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" \
+ -- $RESTORECOND_ARGS
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ return "$status"
+}
+
+stop()
+{
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ printf 'Stopping %s: ' "$DAEMON"
+ start-stop-daemon -K -q -p $PIDFILE -R TERM/30/KILL/5 -n $DAEMON
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ rm -f "$PIDFILE"
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ return "$status"
+}
+
+restart()
+{
+ stop
+ sleep 1
+ start
+}
+
+check_status()
+{
+ start-stop-daemon -K -t -p $PIDFILE -n $DAEMON
+ status=$?
+ if [ "$status" -eq 0 ]; then
+ echo "RUNNING"
+ else
+ echo "STOPPED"
+ fi
+}
+
+case "$1" in
+ start|stop|restart)
+ "$1";;
+ status)
+ check_status;;
+ force-reload|restart|reload)
+ restart;;
+ condrestart)
+ [ -e /var/lock/subsys/restorecond ] && restart || :;;
+ *)
+ echo $"Usage: $0 {start|stop|restart|force-reload|status|condrestart}"
+ exit 1
+esac
diff --git a/package/restorecond/restorecond.mk b/package/restorecond/restorecond.mk
index 7ab7e978dd..3c6fb57ea6 100644
--- a/package/restorecond/restorecond.mk
+++ b/package/restorecond/restorecond.mk
@@ -27,8 +27,8 @@ define RESTORECOND_BUILD_CMDS
endef
define RESTORECOND_INSTALL_INIT_SYSV
- $(INSTALL) -m 0755 -D $(@D)/restorecond.init \
- $(TARGET_DIR)/etc/init.d/S20restorecond
+ $(INSTALL) -m 0755 -D package/restorecond/S02restorecond \
+ $(TARGET_DIR)/etc/init.d/S02restorecond
endef
define RESTORECOND_INSTALL_INIT_SYSTEMD
--
2.25.1
More information about the buildroot
mailing list