File cifs.init of Package cifs-utils.12585

#! /bin/sh
# Copyright (c) 1999-2014 SUSE Linux Products GmbH, Nuernberg, Germany.
# All rights reserved.
#
# Author: Thomas Fehr, 1999-2001
#         Lars Mueller <lmuelle@suse.com>, 2002-2014
#         Bjoern Jacke <bjacke@SerNet.de> 2004
#
# /etc/init.d/cifs
#   and its symbolic link
# /usr/sbin/rccifs
#
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
### BEGIN INIT INFO
# Provides:       cifs
# Required-Start: $network $syslog
# Should-Start:   nfs nmb
# Required-Stop:  $network $syslog
# Should-Stop:    nfs nmb
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: Import remote CIFS file systems
# Description:    Import remote CIFS file systems
### END INIT INFO

# To access CIFS servers beyond the network broadcast domain it may be
# necessary to also activate the nmb service. Also see section 'cifs
# and nmb service' in /usr/share/doc/packages/samba/README.SUSE

. /etc/rc.status
rc_reset

LC_ALL=en_US
SMB_CONF="/etc/samba/smb.conf"
CIFS_STATE_FILE="/run/cifs.state"
SLEEP=1
TIMEOUT=10

grep -q " cifs " /proc/mounts
test $? -eq 0 && cifs_used=yes || cifs_used=no

case "$1" in
	start)
		grep -q '^[[:space:]]*[^#].*[[:space:]]cifs[[:space:]]' /etc/fstab
		rc=$?
		if [ ${rc} -ne 0 ]; then
			echo -n >&2 "No filesystem of type cifs active in /etc/fstab. "
			rc_status -s
			exit 6
		fi
		echo -n "Mount CIFS File Systems "
		timer=${TIMEOUT}
		JOBS="none"
		printdot=""
		while [ "${JOBS}" ] && [ ${timer} -gt 0 ]; do
			if [ -z "${printdot}" ]; then
				echo -en "\nfrom /etc/fstab "
				mount -at cifs >/dev/null &
				PID=$!
			fi
			test -e /proc/$PID || JOBS=""
			if [ "${JOBS}" ]; then
				timer=$[${timer}-1]
				echo -n "."
				sleep ${SLEEP}
				printdot="yes"
			fi
		done
		test "${printdot}" && echo -n " "
		if [ "${JOBS}" -a ${timer} -eq 0 ]; then
			echo -n >&2 " Error: timeout while mount. "
			rc_failed
		fi
		rc_status -v
		touch ${CIFS_STATE_FILE}
		;;
	stop)
		echo -n "Umount CIFS File Systems "
		if [ "${cifs_used}" = "yes" ]; then
			#
			# Unmount in background due to possible long timeouts
			#
			timer=${TIMEOUT}
			JOBS="none"
			printdot=""
			while [ "${JOBS}" ] && [ ${timer} -gt 0 ]; do
				if [ -z "${printdot}" ]; then
					umount -at cifs &
					PID=$!
				fi
				test -e /proc/$PID || JOBS=""
				if [ "${JOBS}" ]; then
					timer=$[${timer}-1]
					echo -n "."
					sleep ${SLEEP}
					printdot="yes"
				fi
			done
			test "${printdot}" && echo -n " "
			if [ "${JOBS}" -a ${timer} -eq 0 ]; then
				echo -n >&2 " Error: timeout while umount. "
				rc_failed
			fi
		fi
		rc_status -v
		;;
	try-restart|condrestart)
		if test "$1" = "condrestart"; then
			echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
		fi
		$0 status
		if test $? = 0; then
			$0 restart
		else 
			rc_reset
		fi
		rc_status
		;;
	force-reload|restart)
		$0 stop
		$0 start
		rc_status
		;;
	reload)
		echo -n "Reload mounted CIFS File Systems "
		rc_failed 3
		rc_status -v
		;;
	status)
		echo -n "Checking for mounted CIFS File Systems "
		if [ "${cifs_used}" = "yes" ]; then
			mount -t cifs | while read service on mountpoint type vfstype rest; do
				echo
				echo -n "${service} on ${mountpoint} type ${vfstype} "
			done
		else
			rc_failed 3
		fi
		rc_status -v
		;;
	probe)
		test ${CIFSTAB} -nt ${CIFS_STATE_FILE} -o \
			${SMB_CONF} -nt ${CIFS_STATE_FILE} && echo restart
		;;
	*)
		echo "Usage: $0 {start|stop|status|force-reload|reload|restart|reload|probe}"
		exit 1
		;;
esac
rc_exit