aboutsummaryrefslogtreecommitdiff
path: root/util/init_script
blob: 0ca395f9c583bffadee658c880d203d2de0735c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /bin/sh
#
# fuse		Init script for Filesystem in Userspace
#
# Author:	Miklos Szeredi <miklos@szeredi.hu>

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
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	if ! grep -qw fuse /proc/filesystems; then
		modprobe fuse >/dev/null 2>&1 || error "loading fuse module"
	fi
	if grep -qw fusectl /proc/filesystems && \
	   ! grep -qw $MOUNTPOINT /proc/mounts; then
		mount -t fusectl none $MOUNTPOINT >/dev/null 2>&1 || \
			error "mounting control filesystem"
	fi
	echo "done."
	;;
  stop)
	echo -n "Stopping $DESC: "
	if grep -qw $MOUNTPOINT /proc/mounts; then
		umount $MOUNTPOINT >/dev/null 2>&1 || \
			error "unmounting control filesystem"
	fi
	if grep -qw "^fuse" /proc/modules; then
		rmmod fuse >/dev/null 2>&1 || error "unloading fuse module"
	fi
	echo "done."
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop}" >&2
	exit 1
	;;
esac

exit 0