Skip to contentSkip to conversation

owfs: add sysv init scripts

PATCH New Arnout Vandecappelle (Essensium/Mind) 2 participants 2 messages Mar 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 owfs: add sysv init scripts

owserver is started unconditionally, but it needs the device(s) to be specified at startup. Therefore a check for non-empty OWSERVER_ARGS is added to the owserver start script.

owfs is started only if is built. It will connect to the owserver. It will try to load the fuse module; if fuse is built-in or already loaded, modprobe -q will fail silently. The filesystem will be mounted on /dev/1wire, because it represents the 1-wire slave devices; also, the bundled Debian init scripts mount it there. We have to create that directory in the init script in case of devtmpfs, and we have to create it in the rootfs for static /dev; for simplicity, just do both.

Users who want a setup without owserver need to remove the owserver init script post-build and need to give appropriate defaults to owfs.

---
v3: Create /dev/1wire for static /dev
v2: Suggestions from PeterK:
- prefix variables from defaults file with OWFS_;
- allow defaults file to override the server with other devices;
- add empty definition of OWFS_ARGS, to make it clearer that this variable can also be used in the defaults file.

---
 package/owfs/S25owserver | 31 +++++++++++++++++++++++++++++++
 package/owfs/S30owfs     | 33 +++++++++++++++++++++++++++++++++
 package/owfs/owfs.mk     | 14 ++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100755 package/owfs/S25owserver
 create mode 100755 package/owfs/S30owfs
package/owfs/S25owserver new file +31 -0
new file mode 100755
index 0000000..b8da768
@@ -0,0 +1,31 @@
+NAME="owserver"
+DAEMON="/usr/bin/${NAME}"
+PID_F="/run/${NAME}.pid"
+
+OWSERVER_ARGS=
+[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
+
+case "$1" in
+start)
+	printf "Starting ${NAME}: "
+	if [ -z "${OWSERVER_ARGS}" ]; then
+		echo "OWSERVER_ARGS must be set in defaults file" 1>&2
+		exit 1
+	fi
+	start-stop-daemon -S -x ${DAEMON} -- \
+		--pid_file ${PID_F} ${OWSERVER_ARGS}
+	[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	;;
+stop)
+	printf "Stopping ${NAME}: "
+	start-stop-daemon -K -p ${PID_F}
+	[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	;;
+restart|reload)
+	$0 stop
+	$0 start
+	;;
+*)
+	echo "Usage: $0 {start|stop|restart|reload}"
+	exit 1
+esac
package/owfs/S30owfs new file +33 -0
new file mode 100755
index 0000000..7077a0e
@@ -0,0 +1,33 @@
+NAME="owfs"
+DAEMON="/usr/bin/${NAME}"
+PID_F="/run/${NAME}.pid"
+OWFS_MOUNTPOINT="/dev/1wire"
+OWFS_DEVICES="-s localhost:4304"
+OWFS_ARGS=""
+
+[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
+
+case "$1" in
+start)
+	printf "Starting ${NAME}: "
+	# Fuse may be in a module, so try to load it
+	modprobe -q fuse && printf "[fuse] "
+	mkdir -p ${MOUNTPOINT}
+	start-stop-daemon -S -x ${DAEMON} -- \
+		--pid_file ${PID_F} -m ${OWFS_MOUNTPOINT} ${OWFS_DEVICES} \
+		${OWFS_ARGS}
+	[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	;;
+stop)
+	printf "Stopping ${NAME}: "
+	start-stop-daemon -K -p ${PID_F}
+	[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	;;
+restart|reload)
+	$0 stop
+	$0 start
+	;;
+*)
+	echo "Usage: $0 {start|stop|restart|reload}"
+	exit 1
+esac
package/owfs/owfs.mk +14 -0
index 083939a..0092603 100644
@@ -23,6 +23,14 @@ OWFS_CONF_OPTS += \
 	--enable-owfs \
 	--with-fuseinclude=$(STAGING_DIR)/usr/include \
 	--with-fuselib=$(STAGING_DIR)/usr/lib
+define OWFS_INSTALL_FUSE_INIT_SYSV
+	$(INSTALL) -D -m 0755 $(OWFS_PKGDIR)S30owfs \
+		$(TARGET_DIR)/etc/init.d/S30owfs
+endef
+define OWFS_CREATE_MOUNTPOINT
+	mkdir -p $(TARGET_DIR)/dev/1wire
+endef
+OWFS_POST_INSTALL_TARGET_HOOKS += OWFS_CREATE_MOUNTPOINT
 else
 OWFS_CONF_OPTS += --disable-owfs
 endif
@@ -70,4 +78,10 @@ ifeq ($(BR2_STATIC_LIBS),y)
 OWFS_CONF_OPTS += --disable-zero
 endif
 
+define OWFS_INSTALL_INIT_SYSV
+	$(INSTALL) -D -m 0755 $(OWFS_PKGDIR)S25owserver \
+		$(TARGET_DIR)/etc/init.d/S25owserver
+	$(OWFS_INSTALL_FUSE_INIT_SYSV)
+endef
+
 $(eval $(autotools-package))
Signature · 1 line
2.8.0.rc3
#1 lore raw

PATCH v3 1/1 owfs: add sysv init scripts

Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle (Essensium/Mind) <[email protected]> writes:

owserver is started unconditionally, but it needs the device(s) to be specified at startup. Therefore a check for non-empty OWSERVER_ARGS is added to the owserver start script.

owfs is started only if is built. It will connect to the owserver. It will try to load the fuse module; if fuse is built-in or already loaded, modprobe -q will fail silently. The filesystem will be mounted on /dev/1wire, because it represents the 1-wire slave devices; also, the bundled Debian init scripts mount it there. We have to create that directory in the init script in case of devtmpfs, and we have to create it in the rootfs for static /dev; for simplicity, just do both.

Users who want a setup without owserver need to remove the owserver init script post-build and need to give appropriate defaults to owfs.

---
v3: Create /dev/1wire for static /dev
v2: Suggestions from PeterK:
- prefix variables from defaults file with OWFS_;
- allow defaults file to override the server with other devices;
- add empty definition of OWFS_ARGS, to make it clearer that this variable can also be used in the defaults file.

+++ b/package/owfs/S30owfs

package/owfs/S30owfs new file +5 -0
@@ -0,0 +1,33 @@
+NAME="owfs"
+DAEMON="/usr/bin/${NAME}"
+PID_F="/run/${NAME}.pid"
+OWFS_MOUNTPOINT="/dev/1wire"
+OWFS_DEVICES="-s localhost:4304"

package/owfs/S30owfs line 15

Quoted 10 lines
package/owfs/S30owfs new file +10 -0
+OWFS_ARGS=""
+
+[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
+
+case "$1" in
+start)
+	printf "Starting ${NAME}: "
+	# Fuse may be in a module, so try to load it
+	modprobe -q fuse && printf "[fuse] "
+	mkdir -p ${MOUNTPOINT}

This should be OWFS_MOUNTPOINT.

Committed with that fixed, thanks.

Signature · 1 line
Bye, Peter Korsgaard