Tizen 2.1 base
[platform/upstream/sysvinit.git] / debian / src / initscripts / etc / init.d / umountfs
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          umountfs
4 # Required-Start:
5 # Required-Stop:     umountroot
6 # Default-Start:
7 # Default-Stop:      0 6
8 # Short-Description: Turn off swap and unmount all local file systems.
9 # Description:
10 ### END INIT INFO
11
12 PATH=/sbin:/usr/sbin:/bin:/usr/bin
13 . /lib/init/vars.sh
14
15 . /lib/lsb/init-functions
16
17 umask 022
18
19 do_stop () {
20         exec 9<&0 </proc/mounts
21
22         REG_MTPTS=""
23         TMPFS_MTPTS=""
24         while read -r DEV MTPT FSTYPE REST
25         do
26                 case "$MTPT" in
27                   /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/lib/init/rw)
28                         continue
29                         ;;
30                   /var/run)
31                         if [ yes = "$RAMRUN" ] ; then
32                                 continue
33                         fi
34                         ;;
35                   /var/lock)
36                         if [ yes = "$RAMLOCK" ] ; then
37                                 continue
38                         fi
39                         ;;
40                 esac
41                 case "$FSTYPE" in 
42                   proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
43                         continue
44                         ;;
45                   tmpfs)
46                         TMPFS_MTPTS="$MTPT $TMPFS_MTPTS"
47                         ;;
48                   *)
49                         REG_MTPTS="$MTPT $REG_MTPTS"
50                         ;;
51                 esac
52         done
53
54         exec 0<&9 9<&-
55         
56         #
57         # Make sure tmpfs file systems are umounted before turning off
58         # swap, to avoid running out of memory if the tmpfs filesystems
59         # use a lot of space.
60         #
61         if [ "$TMPFS_MTPTS" ]
62         then
63                 if [ "$VERBOSE" = no ]
64                 then
65                         log_action_begin_msg "Unmounting temporary filesystems"
66                         fstab-decode umount $TMPFS_MTPTS
67                         log_action_end_msg $?
68                 else
69                         log_daemon_msg "Will now unmount temporary filesystems"
70                         fstab-decode umount -v $TMPFS_MTPTS
71                         log_end_msg $?
72                 fi
73         fi
74
75         #
76         # Deactivate swap
77         #
78         if [ "$VERBOSE" = no ]
79         then
80                 log_action_begin_msg "Deactivating swap"
81                 swapoff -a >/dev/null
82                 log_action_end_msg $?
83         else
84                 log_daemon_msg "Will now deactivate swap"
85                 swapoff -a -v
86                 log_end_msg $?
87         fi
88
89         #
90         # Unmount local filesystems
91         #
92         if [ "$REG_MTPTS" ]
93         then
94                 if [ "$VERBOSE" = no ]
95                 then
96                         log_action_begin_msg "Unmounting local filesystems"
97                         fstab-decode umount -f -r -d $REG_MTPTS
98                         log_action_end_msg $?
99                 else
100                         log_daemon_msg "Will now unmount local filesystems"
101                         fstab-decode umount -f -v -r -d $REG_MTPTS
102                         log_end_msg $?
103                 fi
104         fi
105 }
106
107 case "$1" in
108   start)
109         # No-op
110         ;;
111   restart|reload|force-reload)
112         echo "Error: argument '$1' not supported" >&2
113         exit 3
114         ;;
115   stop)
116         do_stop
117         ;;
118   *)
119         echo "Usage: $0 start|stop" >&2
120         exit 3
121         ;;
122 esac
123
124 :