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 PLD 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 CPLD="$GREEN" # "PLD Linux Distribution" 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 initscript is invoked via bash, enable RedHat/Fedora compatibility
62 # RC_FEDORA is "set" if enabled and "unset" when not, but it's "value" is always empty
63 # this is useful for inline constructs
64 if [ "${BASH_VERSION+set}" = "set" ]; then
72 if [ -z "$VSERVER" -o "$VSERVER" = "detect" ]; then
74 while read _f _ctx; do
75 [ "$_f" = "VxID:" -o "$_f" = "s_context:" ] && break
76 done </proc/self/status
78 if [ -z "$_ctx" -o "$_ctx" = "0" ]; then
86 # VSERVER_ISOLATION_NET = isolation only inside of vserver guests
87 if [ -z "$VSERVER_ISOLATION_NET" -o "$VSERVER_ISOLATION_NET" = "detect" ]; then
88 VSERVER_ISOLATION_NET=no
89 if [ "$VSERVER" = "yes" ]; then
90 if [ -f /proc/self/nsproxy ]; then
93 while read _t _data; do
94 [ "$_t" = "net:" ] && break
95 done < /proc/self/nsproxy
97 if [ "${_data##*\(}" = "I)" ]; then
98 VSERVER_ISOLATION_NET=yes
100 elif [ -f /proc/self/ninfo ]; then
103 while read _t _data; do
104 [ "$_t" = "NCaps:" ] && break
105 done < /proc/self/ninfo
107 if [ "${_t}" = "NCaps:" ]; then
108 VSERVER_ISOLATION_NET=yes
111 # assume (very?) old kernel mode
112 VSERVER_ISOLATION_NET=yes
118 # we need to know in functions if we were called from a terminal
119 if [ -z "$ISATTY" ]; then
120 [ -t ] && ISATTY=yes || ISATTY=no
127 msg_usage " is_yes {value}"
133 yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
147 msg_usage " is_no {value}"
152 no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
163 # checks if file is empty
164 # empty lines and lines beginning with hash are ignored
166 [ -s "$1" ] || return 0
167 grep -vqE "^(#|[[:blank:]]*$)" "$1" && return 1 || return 0
170 # returns OK if $1 contains $2
172 [ "${1#*$2*}" = "$1" ] && return 1
176 # Apply sysctl settings, including files in /etc/sysctl.d
178 if [ -x /lib/systemd/systemd-sysctl ]; then
179 /lib/systemd/systemd-sysctl
184 for file in /usr/lib/sysctl.d/*.conf; do
185 [ -f /run/sysctl.d/${file##*/} ] && continue
186 [ -f /etc/sysctl.d/${file##*/} ] && continue
187 test -f "$file" && sysctl -q -e -p "$file"
189 for file in /run/sysctl.d/*.conf; do
190 [ -f /etc/sysctl.d/${file##*/} ] && continue
191 test -f "$file" && sysctl -q -e -p "$file"
193 for file in /etc/sysctl.d/*.conf; do
194 test -f "$file" && sysctl -q -e -p "$file"
196 sysctl -q -e -p /etc/sysctl.conf
199 if is_yes "$FASTRC" || is_yes "$IN_SHUTDOWN"; then
203 if is_no "$RC_LOGGING"; then
206 while [ "$1" != "${1##-}" ]; do
224 local _x _y _z v v1 old_IFS ver
228 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
237 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
239 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
241 while [ ${#ver} -lt 9 ]; do ver="0$ver"; done
247 local _x _y _z v v1 old_IFS ver
251 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
259 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
261 while [ ${#ver} -lt 6 ]; do ver="0$ver"; done
267 local _x _y _z v v1 old_IFS ver
271 # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
279 while [ ${#ver} -lt 3 ]; do ver="0$ver"; done
286 is_yes "$ISATTY" || return
288 if is_yes "$FASTRC" || is_no "$TPUT"; then
291 echo -ne "\033[$(($2+1))G"
294 echo -ne "\033[${2}A"
306 is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
309 termput setaf $NORMAL
318 if [ "$3" = "1" ]; then tput bold; else tput sgr0; fi
319 is_yes "$COLOR_INIT" && tput setaf "$2"
322 termput setaf $NORMAL
328 if [ ! -x /bin/printf ]; then
330 # FIXME: buggy when single or double quotes in message!
335 if [ $# -gt 0 ]; then
338 while [ $# -gt 0 ]; do
343 awk "BEGIN {printf \"$text\", \"$m\"; }"
347 # National language support function
349 local msg_echo nls_domain text message
351 nls_domain="$NLS_DOMAIN"
352 while [ "$1" != "${1##-}" ]; do
368 # empty message, so we return --misiek
369 if [ -z "$message" ]; then
374 if is_yes "$GETTEXT"; then
375 message=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${nls_domain:-rc-scripts}" "$message")
378 printf "$message" "$@"
385 if ! is_no "$BOOT_SPLASH" && ! is_yes "$VSERVER"; then
386 [ -x /bin/splash ] && /bin/splash "$action"
393 nls "ERROR: Networking is down. %s can't be run." "$1" >&2
397 show "Starting %s service" "$1"
400 msg_already_running() {
401 nls "%s service is already running." "$1"
405 show "Stopping %s service" "$1"
409 nls "%s service is not running." "$1"
413 show "Reloading %s service" "$1"
420 # Some functions to handle PLD Linux-style messages
424 if is_yes "$RC_UPTIME"; then
425 time=$(awk '{printf("[%8.2f] ", $1)}' /proc/uptime)
428 if is_no "$FASTRC" && is_yes "$GETTEXT"; then
429 text=$time$(nls -n "$@")
431 text=$time$(printf "$@")
434 while [ $((len++)) -lt $INIT_COL ]; do
437 if [ -n "$CHARS" ]; then
438 termput setaf $CCHARS
446 termput hpa $INIT_COL
449 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
450 # First is the text to display, second is color number to use (argument to
451 # tput setaf). If second argument is not given, default (2, green) will be
461 echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
469 echo -ne "$_ok${RC_FEDORA+\\r}${RC_FEDORA-\\n}"
477 echo -ne "$_fail${RC_FEDORA+\\r}${RC_FEDORA-\\n}"
486 # Check if $pid (could be plural) are running
489 [ -d "/proc/$1" ] && return 0
495 # - outside chroot get only those processes, which are outside chroot.
496 # - inside chroot get only those processes, which are inside chroot.
497 # - don't filter out pids which do not have corresponding running processes (process died etc)
498 # (note: some processes like named are chrooted but run outside chroot)
499 # - do nothing inside vserver
501 # no pids, exit early
502 [ $# -eq 0 ] && return
504 # filter by pid namespace if such dir exists for current process
505 # we do filter in containers as stacked containers are possible with LXC
506 if [ -d /proc/$$/ns ]; then
508 pids=$(filter_ns "$@") && set -- "$pids"
511 if is_yes "$VSERVER"; then
516 if [ $# -lt 1 -o ! -d /proc/1 ]; then
521 local root_dir good_pids="" good_add_pid
522 for root_pid in $@; do
523 root_dir=$(resolvesymlink /proc/${root_pid}/root)
524 if [ -n "$root_dir" ]; then
526 if [ -n "${SYSTEM_CHROOTS}" ]; then
527 for r_dir in ${SYSTEM_CHROOTS}; do
528 echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
531 [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
532 elif [ ! -d "/proc/$root_pid" ]; then
533 good_pids="$good_pids $root_pid"
539 # similar to filter_chroot, but filter based on /proc/PID/ns/pid value
541 local cur_ns=$(resolvesymlink /proc/$$/ns/pid)
542 [ "$cur_ns" ] || return 1
545 # add pids if it matches current pid namespace
546 # we should add pids what do not exist (dead processes),
547 # but not add pids whose namespace does not match
548 # (processes belonging to different NS do exist in /proc)
550 if [ ! -d /proc/$pid ]; then
554 ns=$(resolvesymlink /proc/$pid/ns/pid)
555 if [ "$ns" = "$cur_ns" ]; then
564 # run_cmd Message command_to_run
565 # run_cmd -a Message command_to_run
566 # run_cmd --user "username" "Message" command_to_run
568 local force_err=0 exit_code=0 errors user
569 while [ $# -gt 0 ]; do
584 local message=$1; shift
585 show "$message"; busy
589 export HOME=/tmp TMPDIR=/tmp
590 if is_no "$RC_LOGGING"; then
591 ${user:+setuidgid -s $user} "$@" 2>&1
593 ${user:+setuidgid -s $user} initlog -c "$*" 2>&1
597 log_success "$1 $message"
600 log_failed "$1 $message"
603 [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
607 _daemon_set_ulimits() {
608 local opt val ksh=${KSH_VERSION:+1}
609 set -- ${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}
610 while [ $# -gt 0 ]; do
631 # inner function used by daemon().
632 # do not call this directly, as it expects variables being inherited.
633 # also it expects to be called from subshell as it exports env.
634 # it expects options parsed by daemon() and command to be executed in "$@".
637 umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK};
638 export USER=root HOME=/tmp TMPDIR=/tmp
640 nice=${nice:-$DEFAULT_SERVICE_RUN_NICE_LEVEL}
643 # make nice level absolute, not to be dependant of nice level of shell where service started
644 nice=$(($nice - $(nice)))
646 if [ "$closefds" = 1 ]; then
650 elif [ "$redirfds" = 1 ]; then
659 if is_no "$RC_LOGGING"; then
661 if [ ! -x $prog ]; then
662 logger -t rc-scripts -p daemon.debug "daemon: Searching PATH for $prog, consider using full path in initscript"
666 if [ -x $a/$prog ]; then
675 # use setsid to detach from terminal,
676 # NOTE: setsid needs to be "outer" program
677 # otherwise start-stop-daemon would capture the setsid pid not the actual program
681 /sbin/start-stop-daemon -q --start \
683 ${pidfile:+--pidfile $pidfile} \
684 ${makepid:+--make-pidfile} \
685 ${user:+--chuid $user} \
686 ${chdir:+--chdir "$chdir"} \
687 ${fork:+--background} \
688 ${SERVICE_DROPCAPS:+--dropcap $SERVICE_DROPCAPS} \
692 if [ "$fork" = "1" ]; then
693 export PIDFILE="/dev/null"
694 if [ "$makepid" ] && [ "$pidfile" ]; then
695 export PIDFILE="$pidfile"
697 set -- /lib/rc-scripts/makepid "$@"
698 set -- /usr/bin/setsid "$@"
700 if [ -n "$user" -a "$user" != "root" ]; then
701 set -- /bin/runuser -u "$user" -- "$@"
704 nice -n $nice initlog -c "$*" 2>&1 </dev/null
708 # A function to start a program (now it's useful on read-only filesystem too)
710 local errors="" waitname="" waittime=0
712 local nice=$SERVICE_RUN_NICE_LEVEL
713 local fork user closefds redirfds pidfile makepid chdir=/
715 while [ $# -gt 0 ]; do
718 msg_usage " daemon [--check] [--user user] [--fork] [--chdir directory] [--closefds] [--redirfds] [--waitforname procname] [--waitfortime seconds] [--pidfile file] [--makepid] [+/-nicelevel] {program} <program args>"
722 # for compatibility with redhat/mandrake
723 nls "warning: --check option is ignored!"
752 pidfile="${1#--pidfile=}"
753 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
758 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
762 # makepid implies fork
779 [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
780 [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
785 [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS" && echo $$ > "/dev/cpuset/${SERVICE_CPUSET}/tasks"
786 if errors=$(_daemon_exec "$@"); then
787 # wait for process (or pidfile) to be created
788 if [ "$waittime" -gt 0 ]; then
789 # waitname can be empty, as if pidfile is in use, it is not relevant
790 waitproc "$waittime" "$waitname" "$pidfile"
792 log_success "$1 startup"
797 log_failed "$1 startup"
798 [ -n "$errors" ] && echo >&2 "$errors"
803 # wait (in seconds) for process (or pidfile) to be created
804 # example: waitproc 30 httpd /var/run/httpd.pid
806 local waittime=$1 procname=$2 pidfile=$3
808 local now=$(date +%s)
809 local maxtime=$(($now + $waittime))
811 if [ -z "$procname" -a -z "$pidfile" ]; then
812 msg_usage "waitproc: procname or pidfile must be specified"
816 while [ "$(date +%s)" -lt "$maxtime" ]; do
817 pid=$(pidofproc "$procname" "$pidfile")
818 [ -n "$pid" ] && break
820 # start-stop-daemon uses same delay
825 # A function to stop a program.
827 local notset killlevel base pid pidfile result delay=3 try
830 msg_usage " killproc [--pidfile|-p PIDFILE] [-d DELAY] {program} [-SIGNAME]"
834 while [ "$1" != "${1##-}" ]; do
842 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
859 # check for second arg to be kill level
866 # experimental start-stop-daemon based killing.
867 # works only with pidfile
868 if is_no "$RC_LOGGING" && [ "$pidfile" ]; then
869 local sig=${killlevel:--TERM} retry
870 # do not retry if signal is specified,
871 # as otherwise impossible to send HUP if process pid stays in pidfile.
872 # however, do retry if --waitfortime was specified
873 if [ "${killlevel+set}" = "set" ] && [ -z "$waittime" ]; then
874 # if we send HUP it's ok if process does not die
879 : ${waitretry=$(($waittime * 2))}
881 # 1. kill with $sig, wait $delay
882 # 2. kill with $sig, wait $waittime
883 # 3. kill with KILL, wait $waitretry
884 retry="--retry ${sig#-}/${delay}/${sig#-}/${waittime}/KILL/${waitretry}"
886 /sbin/start-stop-daemon -q --stop \
888 ${waitname:+--name $waitname} \
890 ${pidfile:+--pidfile $pidfile}
892 if [ "$result" -eq 0 ]; then
905 pid=$(pidofproc "$1" "$pidfile")
906 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
909 if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1; then
910 if [ "$notset" = "1" ]; then
911 if checkpid $pid 2>&1; then
912 # TERM first, then KILL if not dead
917 while [ $try -lt $delay ]; do
918 checkpid $pid || break
922 if checkpid $pid; then
923 # XXX: SIGKILL is sent already on 4th second!
924 # HARMFUL for example to mysqld (which is already workarounded)
931 if [ "$result" -eq 0 ]; then
933 log_failed "$1 shutdown"
936 log_success "$1 shutdown"
938 result=$(( ! $result ))
940 # use specified level only
941 if checkpid $pid > /dev/null 2>&1; then
944 if [ "$result" -eq 0 ]; then
946 log_success "$1 got $killlevel"
950 log_failed "$1 didn't get $killlevel"
955 log_failed "$1 shutdown"
960 log_failed "$1 shutdown"
964 if [ -n "$waitname" -a -n "$waittime" ]; then
968 pid=$(pidofproc "$waitname" "$pidfile")
969 [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
971 while [ "$i" -lt "$waittime" ]; do
973 checkpid $pid && sleep 1 || break
977 # Remove pid file if any.
978 if [ "$notset" = "1" ]; then
979 rm -f /var/run/${base}.pid
985 # A function to find the pid of a program.
987 local pid pidfile base=${1##*/}
989 [ -n "$2" ] && pidfile="$2"
993 msg_usage " pidofproc {program}"
997 # First try pidfile or "/var/run/*.pid"
999 /*)pidfile="${pidfile}";;
1000 *) pidfile="/var/run/$pidfile";;
1002 if [ -f "${pidfile}" ]; then
1004 for p in $(< "${pidfile}"); do
1005 [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
1009 # Next try "pidof" if pidfile is not specified
1010 if [ -z "$pid" ] && [ -z "$2" ]; then
1011 pid=$(pidof -o $$ -o $PPID -o %PPID -x "$1")
1014 pid=$(filter_chroot $pid)
1018 # status [--pidfile PIDFILE] {subsys} [{daemon}]"
1020 local pid subsys daemon cpuset_msg pidfile
1021 if [ "$1" = "--pidfile" -o "$1" = "-p" ]; then
1023 case "$pidfile" in /*);; *) pidfile="/var/run/$pidfile";; esac
1028 daemon=${2:-$subsys}
1032 msg_usage " status [--pidfile PIDFILE] {subsys} [{daemon}]"
1036 # if pidfile specified, pid must be there
1037 if [ "$pidfile" ]; then
1038 [ -f "$pidfile" ] && read pid < $pidfile
1039 # filter_chroot does not filter out dead pids, so this extra check, see t/status-pidfile.sh
1040 if [ ! -d "/proc/$pid" ]; then
1044 pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
1046 pid=$(filter_chroot $pid)
1050 if [ -n "$SERVICE_CPUSET" ] && is_yes "$CPUSETS"; then
1051 if grep -q "$pid" "/dev/cpuset/${SERVICE_CPUSET}/tasks"; then
1052 cpuset_msg=$(nls " in cpuset %s..." "$SERVICE_CPUSET")
1054 cpuset_msg=$(nls " outside of configured cpuset %s..." "$SERVICE_CPUSET")
1057 nls "%s (pid %s) is running%s" "$daemon" "$pid" "$cpuset_msg"
1061 # Next try "/var/run/*.pid" files; if pidfile is not set
1062 local base=${daemon##*/}
1063 if [ -z "$pidfile" -a -f /var/run/${base}.pid ]; then
1064 read pid < /var/run/${base}.pid
1065 pid=$(filter_chroot $pid)
1067 nls "%s dead but pid file (%s) exists" "$subsys" /var/run/${base}.pid
1072 # See if /var/lock/subsys/$subsys exists
1073 if [ -f /var/lock/subsys/$subsys ]; then
1074 nls "daemon %s dead but subsys (%s) locked" "$daemon" "$subsys"
1077 nls "%s is stopped" "$subsys"
1081 # Confirm whether we really want to run this service
1084 nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
1103 # module is needed (ie. is requested, is available and isn't loaded already)
1105 # module name without .o at end
1106 if ! lsmod | grep -q "$1"; then
1107 if ls -1R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "^${1}.\(\|k\)o\(\|.gz\)"; then
1117 local parsed single die args foo result
1119 while is_no "$parsed"; do
1138 if is_yes "${single}"; then
1140 show "Loading %s kernel module(s)" "$foo"
1143 if [ -x /sbin/modprobe ]; then
1144 /sbin/modprobe -s $args "$@"
1150 if is_yes "${single}"; then
1152 if [ $result = "0" ]; then
1153 is_yes "$single" && ok
1156 if is_yes "$die"; then
1157 nls "Could not load %s kernel module(s)" "$@"
1164 if is_no "$RC_LOGGING"; then
1174 initlog -n $0 -s "$1 $2" -e 1
1178 initlog -n $0 -s "$1 $2" -e 2
1182 # Check if any flavor of portmapper is running
1183 check_portmapper() {
1184 if [ -x /usr/sbin/rpcinfo ]; then
1185 if /usr/sbin/rpcinfo -p localhost >/dev/null 2>/dev/null; then
1190 elif [ -z "$(pidof portmap)" -a -z "$(pidof rpcbind)" ]; then
1196 # is_fsmounted fstype mntpoint
1197 # Check if filesystem fstype is mounted on mntpoint
1202 [ -n "$fstype" -a -n "$mntpoint" ] || return 1
1204 if [ -r /proc/mounts ]; then
1205 grep -qE "[[:blank:]]$mntpoint[[:blank:]]+$fstype[[:blank:]]" /proc/mounts
1208 if [ "$(stat -L -f -c %T $mntpoint 2>/dev/null)" = "$fstype" ]; then
1216 # __umount_loop awk_program fstab_file first_msg retry_msg umount_args
1217 # awk_program should process fstab_file and return a list of fstab-encoded
1218 # paths; it doesn't have to handle comments in fstab_file.
1220 local remaining sig=
1223 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1224 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1225 if [ "$retry" -eq 3 ]; then
1226 run_cmd "$3" fstab-decode umount $5 $remaining
1228 run_cmd "$4" fstab-decode umount $5 $remaining
1231 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1232 while [ "$count" -gt 0 ]; do
1233 [ -z "$remaining" ] && break
1236 remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
1238 [ -z "$remaining" ] && break
1239 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1241 retry=$(($retry -1))
1246 # Similar to __umount loop above, specialized for loopback devices
1247 __umount_loopback_loop() {
1248 local remaining devremaining sig=
1251 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1252 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1253 while [ -n "$remaining" -a "$retry" -gt 0 ]; do
1254 if [ "$retry" -eq 3 ]; then
1255 run_cmd "Unmounting loopback filesystems: " \
1256 fstab-decode umount $remaining
1258 run_cmd "Unmounting loopback filesystems (retry):" \
1259 fstab-decode umount $remaining
1261 for dev in $devremaining ; do
1262 losetup $dev > /dev/null 2>&1 && \
1263 run_cmd "Detaching loopback device $dev: " \
1266 remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
1267 devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
1268 [ -z "$remaining" ] && break
1269 fstab-decode /bin/fuser -k -m $sig $remaining >/dev/null
1271 retry=$(($retry -1))
1277 # If we have cachefile, use it.
1278 # If we don't, create memory variables and try to save silently,
1279 local cachefile='/var/cache/rc-scripts/msg.cache'
1282 if is_yes "$ISATTY"; then
1288 # We create $check variable which is used to invalidate the cache.
1289 # The $check contains user locale and terminal.
1290 local check="$term.$LC_MESSAGES.$INIT_COL"
1292 if [ -f "$cachefile" -a "$cachefile" -nt /etc/sysconfig/system -a "$cachefile" -nt /etc/sysconfig/init-colors ]; then
1293 if . "$cachefile" 2>/dev/null; then
1294 if [ "$check" = "$_check" ]; then
1301 _busy=$(progress "BUSY" "$CBUSY")
1302 _ok=$(progress "DONE")
1303 _started=$(progress "WORK")
1304 _fail=$(progress "FAIL" "$CFAIL")
1305 _died=$(progress "DIED" "$CFAIL")
1307 # we don't use heredoc, as ksh attempts to create tempfile then
1308 (> "$cachefile" ) 2>/dev/null || return
1309 echo "_busy='$_busy';" >> "$cachefile"
1310 echo "_ok='$_ok';" >> "$cachefile"
1311 echo "_started='$_started';" >> "$cachefile"
1312 echo "_fail='$_fail';" >> "$cachefile"
1313 echo "_died='$_died';" >> "$cachefile"
1314 echo "_check='$check';" >> "$cachefile"
1318 if [ -z "$GETTEXT" ]; then
1319 if [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
1326 if [ -z "$TPUT" ]; then
1327 if [ -d /usr/share/terminfo ] && [ -x /usr/bin/tput -o -x /bin/tput ]; then
1329 # check if we are on proper terminal
1330 tput longname >/dev/null 2>&1 || TPUT=no
1346 is_upstart_running() {
1361 _upstart_controlled() {
1364 alias upstart_controlled='_upstart_controlled $0 "$@"'
1370 # * Local variables:
1372 # * indent-tabs-mode: notnil