Skip to contentSkip to conversation

package/pigpio: add sysv and systemd init scripts

PATCH New Grzegorz Blach 2 participants 3 messages Nov 11, 2019 – Sep 7, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/pigpio: add sysv and systemd init scripts

---
 package/pigpio/S50pigpio      | 40 +++++++++++++++++++++++++++++++++++
 package/pigpio/pigpio.mk      | 13 ++++++++++++
 package/pigpio/pigpio.service | 10 +++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 package/pigpio/S50pigpio
 create mode 100644 package/pigpio/pigpio.service
package/pigpio/S50pigpio new file +40 -0
new file mode 100644
index 0000000000..7b2e979600
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Starts pigpio daemon.
+#
+
+# Allow a few customizations from a config file
+test -r /etc/default/pigpio && . /etc/default/pigpio
+
+start() {
+	printf "Starting pigpio daemon: "
+	umask 077
+	pigpiod $PIGPIOD_ARGS
+	[ $? = 0 ] && echo "OK" || echo "FAIL"
+}
+stop() {
+	printf "Stopping pigpio daemon: "
+	start-stop-daemon -K -q -p /var/run/pigpio.pid
+	[ $? = 0 ] && echo "OK" || echo "FAIL"
+}
+restart() {
+	stop
+	start
+}
+
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart|reload)
+	restart
+	;;
+  *)
+	echo "Usage: $0 {start|stop|restart}"
+	exit 1
+esac
+
+exit $?
package/pigpio/pigpio.mk +13 -0
index 1cf8f50afc..e8c37621d9 100644
@@ -38,4 +38,17 @@ define PIGPIO_INSTALL_STAGING_CMDS
 	ln -sf libpigpiod_if2.so.1 $(STAGING_DIR)/usr/lib/libpigpiod_if2.so
 endef
 
+define PIGPIO_INSTALL_INIT_SYSV
+        $(INSTALL) -D -m 755 package/pigpio/S50pigpio \
+                $(TARGET_DIR)/etc/init.d/S50pigpio
+endef
+
+define PIGPIO_INSTALL_INIT_SYSTEMD
+        $(INSTALL) -D -m 644 package/pigpio/pigpio.service \
+                $(TARGET_DIR)/usr/lib/systemd/system/pigpio.service
+        mkdir -p $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants
+        ln -fs ../../../../usr/lib/systemd/system/pigpio.service \
+                $(TARGET_DIR)/etc/systemd/system/multi-user.target.wants/pigpio.service
+endef
+
 $(eval $(generic-package))
package/pigpio/pigpio.service new file +10 -0
new file mode 100644
index 0000000000..135624cc43
@@ -0,0 +1,10 @@
+[Unit]
+Description=Pigpio daemon
+After=network.target
+
+[Service]
+EnvironmentFile=-/etc/default/pigpio
+ExecStart=/usr/bin/pigpiod -g $PIGPIOD_ARGS
+
+[Install]
+WantedBy=multi-user.target
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/1 package/pigpio: add sysv and systemd init scripts

Hello Grzegorz,

Sorry for the long delay in not getting back to you. A few comments below.

package/pigpio/S50pigpio line 4

Quoted 10 lines · On Mon, 11 Nov 2019 15:05:34 +0000 Grzegorz Blach <[email protected]> wrote:
package/pigpio/S50pigpio new file +4 -0
new file mode 100644
index 0000000000..7b2e979600
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Starts pigpio daemon.
+#

Could you use package/busybox/S01syslogd as a template for this init script, and model yours to be as similar as possible ?

package/pigpio/S50pigpio line 11

Quoted 7 lines
package/pigpio/S50pigpio new file +7 -0
+
+# Allow a few customizations from a config file
+test -r /etc/default/pigpio && . /etc/default/pigpio
+
+start() {
+	printf "Starting pigpio daemon: "
+	umask 077

Why do you need this umask ?

package/pigpio/S50pigpio line 12

Quoted 1 line
package/pigpio/S50pigpio new file +1 -0
+	pigpiod $PIGPIOD_ARGS

Could you use start-stop-daemon for starting the daemon?

Other than these comments, the whole thing looks pretty good. If you respin soon, I promise to apply quickly!

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/pigpio: add sysv and systemd init scripts

Hello,

I've just sent an updated patch.

Quoted 8 lines · Thomas Petazzoni

Hello Grzegorz,

Sorry for the long delay in not getting back to you. A few comments below.

On Mon, 11 Nov 2019 15:05:34 +0000
Grzegorz Blach <[email protected]> wrote:

Quoted 13 lines

package/pigpio/S50pigpio line 4

Quoted 10 lines
package/pigpio/S50pigpio new file +4 -0
new file mode 100644
index 0000000000..7b2e979600
@@ -0,0 +1,40 @@
+#!/bin/sh
+#
+# Starts pigpio daemon.
+#

Could you use package/busybox/S01syslogd as a template for this init script, and model yours to be as similar as possible ?

Done

Quoted 9 lines

package/pigpio/S50pigpio line 11

Quoted 7 lines
package/pigpio/S50pigpio new file +7 -0
+
+# Allow a few customizations from a config file
+test -r /etc/default/pigpio && . /etc/default/pigpio
+
+start() {
+	printf "Starting pigpio daemon: "
+	umask 077

Why do you need this umask ?

I don't remember, probably I just copied this line from another init.d script.

Quoted 3 lines

package/pigpio/S50pigpio line 12

Quoted 1 line
package/pigpio/S50pigpio new file +1 -0
+	pigpiod $PIGPIOD_ARGS

Could you use start-stop-daemon for starting the daemon?

Done

Quoted 7 lines

Other than these comments, the whole thing looks pretty good. If you respin soon, I promise to apply quickly!

Thanks!

Thomas