Clean up init script, make it LSB compliant
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 27 Apr 2007 21:07:45 +0000 (21:07 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 27 Apr 2007 21:07:45 +0000 (21:07 +0000)
ChangeLog
util/init_script

index 12e78a695e49bb908a6c33b32986fb3f0ffc7a4b..a69815813bf5fecdbf96bc67f27effe7003f44e4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
        * libfuse: call umount(8) directly instead of fusermount if
        possible
 
+       * Clean up init script, make it LSB compliant
+
 2007-04-26  Miklos Szeredi <miklos@szeredi.hu>
 
        * In multithreaded loop, use a semaphore instead of SIGHUP to wake
index 2d1bd29f8aa69f7035b166b9830b25433c7e14ac..331b33addb049de173bbf70712df7a33c3c57e7e 100755 (executable)
@@ -1,51 +1,87 @@
 #! /bin/sh
-#
-# fuse         Init script for Filesystem in Userspace
-#
-# Author:      Miklos Szeredi <miklos@szeredi.hu>
+### BEGIN INIT INFO
+# Provides:          fuse
+# Required-Start:    
+# Should-Start:      udev
+# Required-Stop:     
+# Default-Start:     S
+# Default-Stop:
+# Short-Description: Start and stop fuse.
+# Description:       Load the fuse module and mount the fuse control
+#      filesystem.
+### END INIT INFO
 
 set -e
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
-SCRIPTNAME=/etc/init.d/fuse
-DESC="FUSE"
 MOUNTPOINT=/sys/fs/fuse/connections
 
 # Gracefully exit if the package has been removed.
-which fusermount &>/dev/null || exit 0
-
-error()
-{
-       echo "Error $1" >&2
-       exit 1
-}
+which fusermount &>/dev/null || exit 5
 
 case "$1" in
-  start)
-       echo -n "Starting $DESC: "
+    start|restart|force-reload)
        if ! grep -qw fuse /proc/filesystems; then
-               modprobe fuse >/dev/null 2>&1 || error "loading fuse module"
+               echo -n "Loading fuse module"
+               if ! modprobe fuse >/dev/null 2>&1; then
+                       echo " failed!"
+                       exit 1
+               else
+                       echo "."
+               fi
+       else
+               echo "Fuse filesystem already available."
        fi
        if grep -qw fusectl /proc/filesystems && \
           ! grep -qw $MOUNTPOINT /proc/mounts; then
-               mount -t fusectl fusectl $MOUNTPOINT >/dev/null 2>&1 || \
-                       error "mounting control filesystem"
+               echo -n "Mounting fuse control filesystem"
+               if ! mount -t fusectl fusectl $MOUNTPOINT >/dev/null 2>&1; then
+                       echo " failed!"
+                       exit 1
+               else
+                       echo "."
+               fi
+       else
+               echo "Fuse control filesystem already available."
        fi
-       echo "done."
        ;;
-  stop)
-       echo -n "Stopping $DESC: "
+    stop)
+       if ! grep -qw fuse /proc/filesystems; then
+               echo "Fuse filesystem not loaded."
+               exit 7
+       fi
        if grep -qw $MOUNTPOINT /proc/mounts; then
-               umount $MOUNTPOINT >/dev/null 2>&1 || \
-                       error "unmounting control filesystem"
+               echo -n "Unmounting fuse control filesystem"
+               if ! umount $MOUNTPOINT >/dev/null 2>&1; then
+                       echo " failed!"
+               else
+                       echo "."
+               fi
+       else
+               echo "Fuse control filesystem not mounted."
        fi
        if grep -qw "^fuse" /proc/modules; then
-               rmmod fuse >/dev/null 2>&1 || error "unloading fuse module"
+               echo -n "Unloading fuse module"
+               if ! rmmod fuse >/dev/null 2>&1; then
+                       echo " failed!"
+               else
+                       echo "."
+               fi
+       else
+               echo "Fuse module not loaded."
+       fi
+       ;;
+    status)
+       echo -n "Checking fuse filesystem"
+       if ! grep -qw fuse /proc/filesystems; then
+               echo " not available."
+               exit 3
+       else
+               echo " ok."
        fi
-       echo "done."
        ;;
   *)
-       echo "Usage: $SCRIPTNAME {start|stop}" >&2
+       echo "Usage: $0 {start|stop|restart|force-reload|status}"
        exit 1
        ;;
 esac