Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/mpd: rebase init script on layout introduced by openssh
@ 2024-07-21  6:57 Andreas Ziegler
  2024-07-21 16:23 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Ziegler @ 2024-07-21  6:57 UTC (permalink / raw)
  To: buildroot; +Cc: Andreas Ziegler

Rebase S95mpd on commit 1f743f4 (package/openssh: tidy up init script)

$ utils/check-package package/mpd/S95mpd 
61 lines processed
0 warnings generated

Signed-off-by: Andreas Ziegler <br015@umbiko.net>
---
 package/mpd/S95mpd | 64 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/package/mpd/S95mpd b/package/mpd/S95mpd
index a258930b3e..8e5bac995a 100644
--- a/package/mpd/S95mpd
+++ b/package/mpd/S95mpd
@@ -1,33 +1,61 @@
 #!/bin/sh
+#
+# S95mpd	Starts Music Player daemon.
+#
+# shellcheck disable=SC2317 # functions are called via variable
+
+DAEMON="mpd"
+PIDFILE="/var/run/$DAEMON.pid"
 
 # Sanity checks
-test -f /etc/mpd.conf || exit 0
+[ -f /etc/$DAEMON.conf ] || exit 0
 
 start() {
-	printf "Starting mpd: "
-	start-stop-daemon --start --quiet --background --exec /usr/bin/mpd \
-		&& echo "OK" || echo "FAIL"
+	printf "Starting %s: " "$DAEMON"
+	# $DAEMON creates its own $PIDFILE, so do not use --pidfile
+	start-stop-daemon --start --exec "/usr/bin/$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
 }
 
 stop() {
-	printf "Stopping mpd: "
-	start-stop-daemon --stop --quiet --pidfile /var/run/mpd.pid \
-		&& echo "OK" || echo "FAIL"
+	printf "Stopping %s: " "$DAEMON"
+	start-stop-daemon --stop --pidfile "$PIDFILE" \
+		--exec "/usr/bin/$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	# $DAEMON deletes its PID file on exit, wait for it to be gone
+	while [ -f "$PIDFILE" ]; do
+		sleep 0.1
+	done
+	return "$status"
+}
+
+restart() {
+	stop
+	start
+}
+
+reload() {
+	restart
 }
 
 case "$1" in
-	start)
-		start
-		;;
-	stop)
-		stop
-		;;
-	restart|reload)
-		stop
-		sleep 1
-		start
+	start|stop|reload|restart)
+		"$1"
 		;;
 	*)
-		echo "Usage: $0 {start|stop|restart}"
+		echo "Usage: $0 {start|stop|reload|restart}"
 		exit 1
 esac
+
+exit $?
-- 
2.43.0

_______________________________________________
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] package/mpd: rebase init script on layout introduced by openssh
  2024-07-21  6:57 [Buildroot] [PATCH] package/mpd: rebase init script on layout introduced by openssh Andreas Ziegler
@ 2024-07-21 16:23 ` Thomas Petazzoni via buildroot
  2024-07-21 17:36   ` [Buildroot] [PATCH v2] " Andreas Ziegler
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni via buildroot @ 2024-07-21 16:23 UTC (permalink / raw)
  To: Andreas Ziegler; +Cc: buildroot

Hello Andreas,

On Sun, 21 Jul 2024 08:57:37 +0200
Andreas Ziegler <br015@umbiko.net> wrote:

> +	printf "Starting %s: " "$DAEMON"
> +	# $DAEMON creates its own $PIDFILE, so do not use --pidfile

Not correct: you still need to use --pidfile. --pidfile does not tell
start-stop-daemon to create the PID file, but it will check whether the
process really created it.

OpenSSH also creates its own PID file, so could you rework to really
follow the S50sshd example?

Thanks a lot!

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

* [Buildroot] [PATCH v2] package/mpd: rebase init script on layout introduced by openssh
  2024-07-21 16:23 ` Thomas Petazzoni via buildroot
@ 2024-07-21 17:36   ` Andreas Ziegler
  2024-07-22 12:15     ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Ziegler @ 2024-07-21 17:36 UTC (permalink / raw)
  To: buildroot; +Cc: Andreas Ziegler, Thomas Petazzoni

Rebase S95mpd on commit 1f743f4 (package/openssh: tidy up init script)

$ utils/check-package package/mpd/S95mpd 
61 lines processed
0 warnings generated

(smoke test on live system)

Signed-off-by: Andreas Ziegler <br015@umbiko.net>
---
Changes v1 -> v2
 - use --pidfile in startup of service [Thomas Petazzoni]

 package/mpd/S95mpd | 64 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/package/mpd/S95mpd b/package/mpd/S95mpd
index a258930b3e..ac971e04a2 100644
--- a/package/mpd/S95mpd
+++ b/package/mpd/S95mpd
@@ -1,33 +1,61 @@
 #!/bin/sh
+#
+# S95mpd	Starts Music Player daemon.
+#
+# shellcheck disable=SC2317 # functions are called via variable
+
+DAEMON="mpd"
+PIDFILE="/var/run/$DAEMON.pid"
 
 # Sanity checks
-test -f /etc/mpd.conf || exit 0
+[ -f /etc/$DAEMON.conf ] || exit 0
 
 start() {
-	printf "Starting mpd: "
-	start-stop-daemon --start --quiet --background --exec /usr/bin/mpd \
-		&& echo "OK" || echo "FAIL"
+	printf "Starting %s: " "$DAEMON"
+	start-stop-daemon --start --pidfile "$PIDFILE" \
+		--exec "/usr/bin/$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
 }
 
 stop() {
-	printf "Stopping mpd: "
-	start-stop-daemon --stop --quiet --pidfile /var/run/mpd.pid \
-		&& echo "OK" || echo "FAIL"
+	printf "Stopping %s: " "$DAEMON"
+	start-stop-daemon --stop --pidfile "$PIDFILE" \
+		--exec "/usr/bin/$DAEMON"
+	status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	# $DAEMON deletes its PID file on exit, wait for it to be gone
+	while [ -f "$PIDFILE" ]; do
+		sleep 0.1
+	done
+	return "$status"
+}
+
+restart() {
+	stop
+	start
+}
+
+reload() {
+	restart
 }
 
 case "$1" in
-	start)
-		start
-		;;
-	stop)
-		stop
-		;;
-	restart|reload)
-		stop
-		sleep 1
-		start
+	start|stop|reload|restart)
+		"$1"
 		;;
 	*)
-		echo "Usage: $0 {start|stop|restart}"
+		echo "Usage: $0 {start|stop|reload|restart}"
 		exit 1
 esac
+
+exit $?
-- 
2.43.0

_______________________________________________
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 v2] package/mpd: rebase init script on layout introduced by openssh
  2024-07-21 17:36   ` [Buildroot] [PATCH v2] " Andreas Ziegler
@ 2024-07-22 12:15     ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Petazzoni via buildroot @ 2024-07-22 12:15 UTC (permalink / raw)
  To: Andreas Ziegler; +Cc: buildroot

On Sun, 21 Jul 2024 19:36:04 +0200
Andreas Ziegler <br015@umbiko.net> wrote:

> Rebase S95mpd on commit 1f743f4 (package/openssh: tidy up init script)
> 
> $ utils/check-package package/mpd/S95mpd 
> 61 lines processed
> 0 warnings generated
> 
> (smoke test on live system)
> 
> Signed-off-by: Andreas Ziegler <br015@umbiko.net>
> ---
> Changes v1 -> v2
>  - use --pidfile in startup of service [Thomas Petazzoni]

Applied to master, thanks.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
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-22 12:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-21  6:57 [Buildroot] [PATCH] package/mpd: rebase init script on layout introduced by openssh Andreas Ziegler
2024-07-21 16:23 ` Thomas Petazzoni via buildroot
2024-07-21 17:36   ` [Buildroot] [PATCH v2] " Andreas Ziegler
2024-07-22 12:15     ` Thomas Petazzoni via buildroot

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