All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2] package/restorecond: Add new init script
@ 2021-08-20 11:23 José Pekkarinen
  2021-08-20 21:36 ` Thomas Petazzoni
  0 siblings, 1 reply; 5+ messages in thread
From: José Pekkarinen @ 2021-08-20 11:23 UTC (permalink / raw)
  To: buildroot; +Cc: José Pekkarinen, thomas.petazzoni

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@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

_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

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

end of thread, other threads:[~2021-08-24  7:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-20 11:23 [Buildroot] [PATCH v2] package/restorecond: Add new init script José Pekkarinen
2021-08-20 21:36 ` Thomas Petazzoni
2021-08-23  5:45   ` José Pekkarinen
2021-08-23 15:09     ` [Buildroot] [External] " Weber, Matthew L Collins via buildroot
2021-08-24  7:25       ` José Pekkarinen

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.