diff mbox

owfs: add sysv init scripts

Message ID 1458936050-10660-1-git-send-email-arnout@mind.be
State Superseded
Headers show

Commit Message

Arnout Vandecappelle March 25, 2016, 8 p.m. UTC
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.

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

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
 package/owfs/S25owserver | 31 +++++++++++++++++++++++++++++++
 package/owfs/S30owfs     | 32 ++++++++++++++++++++++++++++++++
 package/owfs/owfs.mk     | 10 ++++++++++
 3 files changed, 73 insertions(+)
 create mode 100755 package/owfs/S25owserver
 create mode 100755 package/owfs/S30owfs

Comments

Peter Korsgaard March 25, 2016, 8:41 p.m. UTC | #1
>>>>> "Arnout" == Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> 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.

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

 > Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

Looks good, except:

> diff --git a/package/owfs/S30owfs b/package/owfs/S30owfs
 > new file mode 100755
 > index 0000000..552eb75
 > --- /dev/null
 > +++ b/package/owfs/S30owfs
 > @@ -0,0 +1,32 @@
 > +NAME="owfs"
 > +DAEMON="/usr/bin/${NAME}"
 > +PID_F="/run/${NAME}.pid"
 > +MOUNTPOINT="/dev/1wire"
 > +SERVER="localhost:4304"

I've never used owfs, but /dev/1wire sounds like an odd mount point to
me. I would have expected something under /mnt?

Googling around, I see the manual page suggests /mnt/1wire:

http://owfs.org/index.php?page=owfs

You will need to create the mount point during build time though, as
/mnt might not be writable.

The point of sourcing /etc/default/owfs is so the user can override the
defaults. How about sticking the MOUNTPOINT / SERVER into a OWFS_ARGS or
at least prefixing the variables with OWFS?
Arnout Vandecappelle March 25, 2016, 10:05 p.m. UTC | #2
On 03/25/16 21:41, Peter Korsgaard wrote:
>>>>>> "Arnout" == Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> 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.
>
>   > Users who want a setup without owserver need to remove the owserver
>   > init script post-build and need to give appropriate defaults to owfs.
>
>   > Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
>
> Looks good, except:
>
>> diff --git a/package/owfs/S30owfs b/package/owfs/S30owfs
>   > new file mode 100755
>   > index 0000000..552eb75
>   > --- /dev/null
>   > +++ b/package/owfs/S30owfs
>   > @@ -0,0 +1,32 @@
>   > +NAME="owfs"
>   > +DAEMON="/usr/bin/${NAME}"
>   > +PID_F="/run/${NAME}.pid"
>   > +MOUNTPOINT="/dev/1wire"
>   > +SERVER="localhost:4304"
>
> I've never used owfs, but /dev/1wire sounds like an odd mount point to
> me. I would have expected something under /mnt?

  /dev/1wire is what is used by the bundled debian init scripts. I didn't use 
the bundled init scripts because they are slightly more complicated than what we 
need and I wanted to add some features, like loading the fuse module.

  /mnt is annoying, because some scripts will (temporarily) mount something on 
/mnt (without subdir), thus hiding anything else mounted there. For example, 
many of our board readme's say to mount /dev/mmcblk0p1 /mnt as part of creating 
the SD card.

  In addition, owfs exports access to devices, so /dev seems like an appropriate 
place. /mnt, to me, is for mounting actual storage filesystems.

  I've also considered /sys/fs which already gets a couple of pseudofilesystems 
mounted on it, and the owfs nodes are a bit similar to sysfs nodes. However, 
/sys/fs really is for metadata of filesystems, not for adding actual devices.

  The contents of owfs really should be in /sys/devices. However, the 
organisation of the owfs tree is not really that similar to the sysfs tree, so 
it's not a great fit either.

  So, taking all of that into account, I chose to stick to the /dev/1wire that 
is also used by the bundled debian init scripts.

>
> Googling around, I see the manual page suggests /mnt/1wire:
>
> http://owfs.org/index.php?page=owfs
>
> You will need to create the mount point during build time though, as
> /mnt might not be writable.

  Oh yeah, another reason to put it on /dev or /sys.

>
> The point of sourcing /etc/default/owfs is so the user can override the
> defaults. How about sticking the MOUNTPOINT / SERVER into a OWFS_ARGS or
> at least prefixing the variables with OWFS?

  Yes, that's a good idea. I'm on it.

  Regards,
  Arnout

>
Peter Korsgaard March 25, 2016, 10:20 p.m. UTC | #3
>>>>> "Arnout" == Arnout Vandecappelle <arnout@mind.be> writes:

Hi,

>> I've never used owfs, but /dev/1wire sounds like an odd mount point to
 >> me. I would have expected something under /mnt?

 >  /dev/1wire is what is used by the bundled debian init scripts. I
 > didn't use the bundled init scripts because they are slightly more
 > complicated than what we need and I wanted to add some features, like
 > loading the fuse module.

 >  /mnt is annoying, because some scripts will (temporarily) mount
 > something on /mnt (without subdir), thus hiding anything else mounted
 > there. For example, many of our board readme's say to mount
 > /dev/mmcblk0p1 /mnt as part of creating the SD card.

Ok, /dev/1wire is ok with me.

 >> Googling around, I see the manual page suggests /mnt/1wire:
 >> 
 >> http://owfs.org/index.php?page=owfs
 >> 
 >> You will need to create the mount point during build time though, as
 >> /mnt might not be writable.

 >  Oh yeah, another reason to put it on /dev or /sys.

Do keep in mind that we still support BR2_ROOTFS_DEVICE_CREATION_STATIC,
so you need to create it at build time AND mkdir -p it in the init
script.

 >> The point of sourcing /etc/default/owfs is so the user can override the
 >> defaults. How about sticking the MOUNTPOINT / SERVER into a OWFS_ARGS or
 >> at least prefixing the variables with OWFS?

 >  Yes, that's a good idea. I'm on it.

Great, thanks!
diff mbox

Patch

diff --git a/package/owfs/S25owserver b/package/owfs/S25owserver
new file mode 100755
index 0000000..b8da768
--- /dev/null
+++ b/package/owfs/S25owserver
@@ -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
diff --git a/package/owfs/S30owfs b/package/owfs/S30owfs
new file mode 100755
index 0000000..552eb75
--- /dev/null
+++ b/package/owfs/S30owfs
@@ -0,0 +1,32 @@ 
+NAME="owfs"
+DAEMON="/usr/bin/${NAME}"
+PID_F="/run/${NAME}.pid"
+MOUNTPOINT="/dev/1wire"
+SERVER="localhost:4304"
+
+[ -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} -s ${SERVER} -m ${MOUNTPOINT} \
+		${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
diff --git a/package/owfs/owfs.mk b/package/owfs/owfs.mk
index 083939a..ca86b62 100644
--- a/package/owfs/owfs.mk
+++ b/package/owfs/owfs.mk
@@ -23,6 +23,10 @@  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
 else
 OWFS_CONF_OPTS += --disable-owfs
 endif
@@ -70,4 +74,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))