1 #!/bin/sh - keep it for file(1) to get bourne shell script result
2 # functions This file contains functions to be used by most or all
3 # shell scripts in the /etc/rc.d/init.d directory.
6 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
7 # Hacked by: Greg Galloway and Marc Ewing
8 # Modified for TLD Linux by:
9 # Marek Obuchowicz <elephant@pld-linux.org>
10 # Arkadiusz Miśkiewicz <misiek@pld-linux.org>
11 # Michał Kochanowicz <mkochano@pld-linux.org>
12 # Łukasz Pawelczyk <havner@pld-linux.org>
14 # First set up a default search path.
15 export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
18 if [ -z "$COLUMNS" -o -z "$LINES" ]; then
20 set -- $(stty size 2>/dev/null)
22 COLUMNS=${COLUMNS:-$2}
27 [ -z "$LINES" ] || [ "$LINES" -le 0 ] && LINES=40
28 [ -z "$COLUMNS" ] || [ "$COLUMNS" -le 0 ] && COLUMNS=80
30 INIT_COL=$((COLUMNS - 13))
41 # Bold definition (second parameter to termput setaf)
45 CBRACKETS="$CYAN" # brackets [ ] color
46 CDONE="$GREEN" # DONE and WORK color
47 CBUSY="$MAGENTA" # BUSY color
48 CFAIL="$RED" # FAIL and DIED color
49 CPOWEREDBY="$CYAN" # "Powered by" color
50 CTLD="$GREEN" # "TLD Linux" color
51 CI="$RED" # Capital I color (press I to enter interactive startup)
52 CRESMAN="$GREEN" # "Resource Manager" color
53 CHARS="" # Characters displayed on the beginning of show line
54 CCHARS="$NORMAL" # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example)
56 # Source configuration if available - may override default values
57 [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors
58 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
59 [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash
61 if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then
63 while read _f _ctx; do
64 [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break
65 done </proc/self/status
67 if [ -z "$_ctx" -o "$_ctx" = "0" ]; then
75 # VSERVER_ISOLATION_NET = isolation only inside of vserver guests
76 if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then
77 VSERVER_ISOLATION_NET=no
78 if [ "$VSERVER" = "yes" ]; then
79 if [ -f /proc/self/nsproxy ]; then
82 while read _t _data; do
83 [ "$_t" = "net:" ] && break
84 done < /proc/self/nsproxy
86 if [ "${_data##*\(}" = "I)" ]; then
87 VSERVER_ISOLATION_NET=yes
89 elif [ -f /proc/self/ninfo ]; then
92 while read _t _data; do
93 [ "$_t" = "NCaps:" ] && break
94 done < /proc/self/ninfo
96 if [ "${_t}" = "NCaps:" ]; then
97 VSERVER_ISOLATION_NET=yes
100 # assume (very?) old kernel mode
101 VSERVER_ISOLATION_NET=yes
107 # we need to know in functions if we were called from a terminal
108 if [ -z "$ISATTY" ]; then
109 [ -t ] && ISATTY=yes || ISATTY=no
116 msg_usage " is_yes {value}"
122 yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
136 msg_usage " is_no {value}"
141 no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
152 # checks if file is empty
153 # empty lines and lines beginning with hash are ignored
155 [ -s "$1" ] || return 0
156 grep -vqE "^(#|[[:blank:]]*$)" "$1" && return 1 || return 0
159 # returns OK if $1 contains $2
161 [ "${1#*$2*}" = "$1" ] && return 1
165 # Apply sysctl settings, including files in /etc/sysctl.d
167 if [ -x /lib/systemd/systemd-sysctl ]; then
168 /lib/systemd/systemd-sysctl
173 for file in /usr/lib/sysctl.d/*.conf; do
174 [ -f /run/sysctl.d/${file##*/} ] && continue
175 [ -f /etc/sysctl.d/${file##*/} ] && continue
176 test -f "$file" && sysctl -q -e -p "$file"
178 for file in /run/sysctl.d/*.conf; do
179 [ -f /etc/sysctl.d/${file##*/} ] && continue
180 test -f "$file" && sysctl -q -e -p "$file"
182 for file in /etc/sysctl.d/*.conf; do
183 test -f "$file" && sysctl -q -e -p "$file"
185 sysctl -q -e -p /etc/sysctl.conf
188 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
192 if is_no "$RC_LOGGING"; then
195 while [ "$1" != "${1##-}" ]; do
213 local _x _y _z v v1 old_IFS ver
217 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
226 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
228 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
230 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
236 local _x _y _z v v1 old_IFS ver
240 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
248 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
250 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
256 local _x _y _z v v1 old_IFS ver
260 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
268 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
275 is_yes "$ISATTY" || return
277 if is_yes "$FASTRC" || is_no "$TPUT"; then
280 echo -ne "\033[$(($2+1))G"
283 echo -ne "\033[${2}A"
295 is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
298 termput setaf $NORMAL
307 if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
308 is_yes "$COLOR_INIT" && tput setaf "$2"
311 termput setaf $NORMAL
317 if [ ! -x /bin/printf ]; then
319 # FIXME: buggy when single or double quotes in message!
324 if [ $# -gt 0 ]; then
327 while [ $# -gt 0 ]; do
332 awk "BEGIN {printf \"$text\", \"$m\"; }"
336 # National language support function
338 local msg_echo nls_domain text message
340 nls_domain="$NLS_DOMAIN"
341 while [ "$1" != "${1##-}" ]; do
357 # empty message, so we return --misiek
358 if [ -z "$message" ]; then
363 if is_yes "$GETTEXT"; then
364 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
367 printf "$message" "$@"
374 if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
375 [ -x /bin/splash ] && /bin/splash "$action"
382 nls "ERROR: Networking is down. %s can't be run." "$1" >&2
386 show "Starting %s service" "$1"
389 msg_already_running() {
390 nls "%s service is already running." "$1"
394 show "Stopping %s service" "$1"
398 nls "%s service is not running." "$1"
402 show "Reloading %s service" "$1"
409 # Some functions to handle TLD Linux-style messages
413 if is_yes "$RC_UPTIME"; then
414 time=$(awk '{printf("[%8.2f] ", $1)}' /proc/uptime)
417 if is_no "$FASTRC" && is_yes "$GETTEXT"; then
418 text=$time$(nls -n "$@")
420 text=$time$(printf "$@")
423 while [ $((len++)) -lt $INIT_COL ]; do
426 if [ -n "$CHARS" ]; then
427 termput setaf $CCHARS
435 termput hpa $INIT_COL
438 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
439 # First is the text to display, second is color number to use (argument to
440 # tput setaf). If second argument is not given, default (2, green) will be
450 echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
475 # Check if $pid (could be plural) are running
478 [ -d "/proc/$1" ] && return 0
484 # - outside chroot get only those processes, which are outside chroot.
485 # - inside chroot get only those processes, which are inside chroot.
486 # - don't filter out pids which do not have corresponding running processes (process died etc)
487 # (note: some processes like named are chrooted but run outside chroot)
488 # - do nothing inside vserver
490 # no pids, exit early
491 [ $# -eq 0 ] && return
493 # filter by pid namespace if such dir exists for current process
494 # we do filter in containers as stacked containers are possible with LXC
495 if [ -d /proc/$$/ns ]; then
497 pids=$(filter_ns "$@") && set -- "$pids"
500 if is_yes "$VSERVER"; then
505 if [ $# -lt 1 -o ! -d /proc/1 ]; then
510 local root_dir good_pids="" good_add_pid
511 for root_pid in $@; do
512 root_dir=$(resolvesymlink /proc/${root_pid}/root)
513 if [ -n "$root_dir" ]; then
515 if [ -n "${SYSTEM_CHROOTS}" ]; then
516 for r_dir in ${SYSTEM_CHROOTS}; do
517 echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
520 [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
521 elif [ ! -d "/proc/$root_pid" ]; then
522 good_pids="$good_pids $root_pid"
528 # similar to filter_chroot, but filter based on /proc/PID/ns/pid value
530 local cur_ns=$(resolvesymlink /proc/$$/ns/pid)
531 [ "$cur_ns" ] || return 1
534 # add pids if it matches current pid namespace
535 # we should add pids what do not exist (dead processes),
536 # but not add pids whose namespace does not match
537 # (processes belonging to different NS do exist in /proc)
539 if [ ! -d /proc/$pid ]; then
543 ns=$(resolvesymlink /proc/$pid/ns/pid)
544 if [ "$ns" = "$cur_ns" ]; then
553 # run_cmd Message command_to_run
554 # run_cmd -a Message command_to_run
555 # run_cmd --user "username" "Message" command_to_run
557 local force_err=0 exit_code=0 errors user
558 while [ $# -gt 0 ]; do
573 local message=$1; shift
574 show "$message"; busy
578 export HOME=/tmp TMPDIR=/tmp
579 if is_no "$RC_LOGGING"; then
580 ${user:+setuidgid -s $user} "$@" 2>&1
582 ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
586 log_success "$1 $message"
589 log_failed "$1 $message"
592 [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
596 _daemon_set_ulimits() {
597 local opt val ksh=${KSH_VERSION:+1}
598 set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
599 while [ $# -gt 0 ]; do
620 # A function to start a program (now it's useful on read-only filesystem too)
622 local errors="" prog="" end="" waitname="" waittime=""
624 local nice=$SERVICE_RUN_NICE_LEVEL
625 local fork user closefds redirfds pidfile makepid chdir=/
627 # NOTE: if you wonder how the shellish (by syntax) $prog works in ssd mode,
628 # then the answer is: it totally ignores $prog and uses "$@" itself.
630 while [ $# -gt 0 ]; do
633 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
637 # for compatibility with redhat/mandrake
638 nls "warning: --check option is ignored!"
668 pidfile="${1#--pidfile=}"
669 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
674 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
690 if [ -n "$user" -a "$user" != "root" ]; then
691 prog="/bin/su $user -s /bin/sh -c \""
693 if [ "$fork" = "1" ]; then
694 prog="/usr/bin/setsid ${prog:-sh -c \"}"
696 # If command to execute ends with quotation mark, add remaining
697 # arguments and close quotation.
698 if [ "$prog" != "${prog%\"}" ]; then
699 prog="$prog $*$end\""
706 [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
707 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
712 [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
714 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
715 export USER=root HOME=/tmp TMPDIR=/tmp
717 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
720 # make nice level absolute, not to be dependant of nice level of shell where service started
721 nice=$(($nice - $(nice)))
723 if [ "$closefds" = 1 ]; then
727 elif [ "$redirfds" = 1 ]; then
736 if is_no "$RC_LOGGING"; then
738 if [ ! -x $prog ]; then
739 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
743 if [ -x $a/$prog ]; then
752 # use setsid to detach from terminal,
753 # needs pidfile or ssd would check setsid program instead of real program
754 if [ "$pidfile" ]; then
755 set -- /usr/bin/setsid "$@"
759 /sbin/start-stop-daemon -q --start \
761 ${pidfile:+--pidfile $pidfile} \
762 ${makepid:+--make-pidfile} \
763 ${user:+--chuid $user} \
764 ${chdir:+--chdir "$chdir"} \
765 ${fork:+--background} \
766 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
770 nice -n $nice initlog -c "$prog" 2>&1 </dev/null
774 # wait for process (or pidfile) to be created
775 if [ "$waittime" -gt 0 ]; then
776 # waitname can be empty, as if pidfile is in use, it is not relevant
777 waitproc "$waittime" "$waitname" "$pidfile"
779 log_success "$1 startup"
784 log_failed "$1 startup"
785 [ -n "$errors" ] && echo >&2 "$errors"
790 # wait (in seconds) for process (or pidfile) to be created
791 # example: waitproc 30 httpd /var/run/httpd.pid
793 local waittime=$1 procname=$2 pidfile=$3
795 local now=$(date +%s)
796 local maxtime=$(($now + $waittime))
798 if [ -z "$procname" -a -z "$pidfile" ]; then
799 msg_usage "waitproc: procname or pidfile must be specified"
803 while [ "$(date +%s)" -lt "$maxtime" ]; do
804 pid=$(pidofproc "$procname" "$pidfile")
805 [ -n "$pid" ] && break
807 # start-stop-daemon uses same delay
812 # A function to stop a program.
814 local notset killlevel base pid pidfile result delay=3 try
817 msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
821 while [ "$1" != "${1##-}" ]; do
829 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
846 # check for second arg to be kill level
853 # experimental start-stop-daemon based killing.
854 # works only with pidfile
855 if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
856 local sig=${killlevel:--TERM} retry
857 # do not retry if signal is specified,
858 # as otherwise impossible to send HUP if process pid stays in pidfile.
859 # however, do retry if --waitfortime was specified
860 if [ "${killlevel+set}" = "set" ] && [ -z "$waittime" ]; then
861 # if we send HUP it's ok if process does not die
866 : ${waitretry=$(($waittime * 2))}
868 # 1. kill with $sig, wait $delay
869 # 2. kill with $sig, wait $waittime
870 # 3. kill with KILL, wait $waitretry
871 retry="--retry ${sig#-}/${delay}/${sig#-}/${waittime}/KILL/${waitretry}"
873 /sbin/start-stop-daemon -q --stop \
875 ${waitname:+--name $waitname} \
877 ${pidfile:+--pidfile $pidfile}
879 if [ "$result" -eq 0 ]; then
892 pid=$(pidofproc "$1" "$pidfile")
893 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
896 if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
897 if [ "$notset" = "1" ]; then
898 if checkpid $pid 2>&1; then
899 # TERM first, then KILL if not dead
904 while [ $try -lt $delay ]; do
905 checkpid $pid || break
909 if checkpid $pid; then
910 # XXX: SIGKILL is sent already on 4th second!
911 # HARMFUL for example to mysqld (which is already workarounded)
918 if [ "$result" -eq 0 ]; then
920 log_failed "$1 shutdown"
923 log_success "$1 shutdown"
925 result=$(( ! $result ))
927 # use specified level only
928 if checkpid $pid > /dev/null 2>&1; then
931 if [ "$result" -eq 0 ]; then
933 log_success "$1 got $killlevel"
937 log_failed "$1 didn't get $killlevel"
942 log_failed "$1 shutdown"
947 log_failed "$1 shutdown"
951 if [ -n "$waitname" -a -n "$waittime" ]; then
955 pid=$(pidofproc "$waitname" "$pidfile")
956 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
958 while [ "$i" -lt "$waittime" ]; do
960 checkpid $pid && sleep 1 || break
964 # Remove pid file if any.
965 if [ "$notset" = "1" ]; then
966 rm -f /var/run/${base}.pid
972 # A function to find the pid of a program.
974 local pid pidfile base=${1##*/}
976 [ -n "$2" ] && pidfile="$2"
980 msg_usage " pidofproc {program}"
984 # First try pidfile or "/var/run/*.pid"
986 /*)pidfile="${pidfile}";;
987 *) pidfile="/var/run/$pidfile";;
989 if [ -f "${pidfile}" ]; then
991 for p in $(< "${pidfile}"); do
992 [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
996 # Next try "pidof" if pidfile is not specified
997 if [ -z "$pid" ] && [ -z "$pidfile" ]; then
998 pid=$(pidof -o $$ -o $PPID -o %PPID -x "$1")
1001 pid=$(filter_chroot $pid)
1005 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
1007 local pid subsys daemon cpuset_msg pidfile
1008 if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
1010 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
1015 daemon=${2:-$subsys}
1019 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
1023 # if pidfile specified, pid must be there
1024 if [ "$pidfile" ]; then
1025 [ -f "$pidfile" ] && read pid < $pidfile
1026 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
1027 if [ ! -d "/proc/$pid" ]; then
1031 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
1033 pid=$(filter_chroot $pid)
1037 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
1038 if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
1039 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
1041 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
1044 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
1048 # Next try "/var/run/*.pid" files; if pidfile is not set
1049 local base=${daemon##*/}
1050 if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
1051 read pid < /var/run/${base}.pid
1052 pid=$(filter_chroot $pid)
1054 nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
1059 # See if /var/lock/subsys/$subsys exists
1060 if [ -f /var/lock/subsys/$subsys ]; then
1061 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
1064 nls "%s is stopped" "$subsys"
1068 # Confirm whether we really want to run this service
1071 nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
1090 # module is needed (ie. is requested, is available and isn't loaded already)
1092 # module name without .o at end
1093 if ! lsmod | grep -q "$1"; then
1094 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
1104 local parsed single die args foo result
1106 while is_no "$parsed"; do
1125 if is_yes "${single}"; then
1127 show "Loading %s kernel module(s)" "$foo"
1130 if [ -x /sbin/modprobe ]; then
1131 /sbin/modprobe -s $args "$@"
1137 if is_yes "${single}"; then
1139 if [ $result = "0" ]; then
1140 is_yes "$single" && ok
1143 if is_yes "$die"; then
1144 nls "Could not load %s kernel module(s)" "$@"
1151 if is_no "$RC_LOGGING"; then
1161 initlog -n $0 -s "$1 $2" -e 1
1165 initlog -n $0 -s "$1 $2" -e 2
1169 # Check if any flavor of portmapper is running
1170 check_portmapper() {
1171 if [ -x /usr/sbin/rpcinfo ]; then
1172 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1177 elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1183 # is_fsmounted fstype mntpoint
1184 # Check if filesystem fstype is mounted on mntpoint
1189 [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1191 if [ -r /proc/mounts ]; then
1192 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1195 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1203 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1204 # awk_program should process fstab_file and return a list of fstab-encoded
1205 # paths; it doesn't have to handle comments in fstab_file.
1207 local remaining sig=
1210 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1211 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1212 if [ "$retry" -eq 3 ]; then
1213 run_cmd "$3" fstab-decode umount $5 $remaining
1215 run_cmd "$4" fstab-decode umount $5 $remaining
1218 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1219 while [ "$count" -gt 0 ]; do
1220 [ -z "$remaining" ] && break
1223 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1225 [ -z "$remaining" ] && break
1226 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1228 retry=$(($retry -1))
1233 # Similar to __umount loop above, specialized for loopback devices
1234 __umount_loopback_loop() {
1235 local remaining devremaining sig=
1238 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1239 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1240 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1241 if [ "$retry" -eq 3 ]; then
1242 run_cmd "Unmounting loopback filesystems: " \
1243 fstab-decode umount $remaining
1245 run_cmd "Unmounting loopback filesystems (retry):" \
1246 fstab-decode umount $remaining
1248 for dev in $devremaining ; do
1249 losetup $dev > /dev/null 2>&1 && \
1250 run_cmd "Detaching loopback device $dev: " \
1253 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1254 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1255 [ -z "$remaining" ] && break
1256 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1258 retry=$(($retry -1))
1264 # If we have cachefile, use it.
1265 # If we don't, create memory variables and try to save silently,
1266 local cachefile='/var/cache/rc-scripts/msg.cache'
1269 if is_yes "$ISATTY"; then
1275 # We create $check variable which is used to invalidate the cache.
1276 # The $check contains user locale and terminal.
1277 local check="$term.$LC_MESSAGES.$INIT_COL"
1279 if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1280 if . "$cachefile" 2>/dev/null; then
1281 if [ "$check" = "$_check" ]; then
1288 _busy=$(progress "BUSY" "$CBUSY")
1289 _ok=$(progress "DONE")
1290 _started=$(progress "WORK")
1291 _fail=$(progress "FAIL" "$CFAIL")
1292 _died=$(progress "DIED" "$CFAIL")
1294 # we don't use heredoc, as ksh attempts to create tempfile then
1295 (> "$cachefile" ) 2>/dev/null || return
1296 echo "_busy='$_busy';" >> "$cachefile"
1297 echo "_ok='$_ok';" >> "$cachefile"
1298 echo "_started='$_started';" >> "$cachefile"
1299 echo "_fail='$_fail';" >> "$cachefile"
1300 echo "_died='$_died';" >> "$cachefile"
1301 echo "_check='$check';" >> "$cachefile"
1305 if [ -z "$GETTEXT" ]; then
1306 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1313 if [ -z "$TPUT" ]; then
1314 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1316 # check if we are on proper terminal
1317 tput longname >/dev/null 2>&1 || TPUT=no
1333 is_upstart_running() {
1348 _upstart_controlled() {
1351 alias upstart_controlled='_upstart_controlled $0 "$@"'
1357 # * Local variables:
1359 # * indent-tabs-mode: notnil