diff --git a/configs/openafs-client b/configs/openafs-client index af827a3..b96d2b4 100644 --- a/configs/openafs-client +++ b/configs/openafs-client @@ -4,9 +4,18 @@ # ENABLE_AFSDB and ENABLE_DYNROOT determine whether AFSDB support and # Dynroot support (dynamically generated /afs), respectively, should be # enabled in the AFS client. -ENABLE_AFSDB="yes" +ENABLE_AFSDB="no" ENABLE_DYNROOT="yes" +# File where mount commands for futher restore will be stored +BINDS_STORAGE="/tmp/openrc.openafs-client.binds.storage" + +# umount all `mount --bind`'s on stop - to remove any locks on fs +UNBIND_ON_STOP="yes" + +# and restore them on start +RESTORE_ON_START="yes" + # AFS client configuration options: # --------------------------------------------------------------------------- # possible AFS client afsd configuration options (from 1.3.74) are @@ -49,4 +58,3 @@ LARGE="-fakestat -stat 2800 -dcache 2400 -daemons 5 -volumes 128" MEDIUM="-fakestat -stat 2000 -dcache 800 -daemons 3 -volumes 70" SMALL="-fakestat -stat 300 -dcache 100 -daemons 2 -volumes 50" OPTIONS="AUTOMATIC" - diff --git a/scripts/openafs-client b/scripts/openafs-client index 6c18b06..420c81f 100755 --- a/scripts/openafs-client +++ b/scripts/openafs-client @@ -2,6 +2,8 @@ # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +opts="${opts} unbind restore" + depend() { need net after openafs-server @@ -30,7 +32,7 @@ choose_afsdoptions() { start() { ebegin "Starting OpenAFS client" - failed=1 + local failed=1 eindent @@ -53,6 +55,11 @@ start() { else cleanstart failed=$? + + if [[ ${failed} -eq 0 ]] && [[ "${RESTORE_ON_START}" == "yes" ]]; then + restore + fi + eend $failed fi @@ -85,14 +92,82 @@ cleanstart() fi } +unbind() { + local binds= path= options= errors=0 + ebegin "Saving /afs binds to ${BINDS_STORAGE}" + + binds=$(mount | grep '/afs on .*bind' | \ + sed -r 's|/afs on (.+) type none \(((([[:alnum:]]+),?)+)\)$|\1 \2|;') + + if [[ -z "${binds}" ]]; then + eend 0 + return 0 + fi + + if [[ -f "${BINDS_STORAGE}" ]]; then + ewarn "Moving existing '${BINDS_STORAGE}' to '${BINDS_STORAGE}.old'" + mv -f "${BINDS_STORAGE}" "${BINDS_STORAGE}.old" + fi + + eindent + set ${binds}; + + while [ $# -gt 0 ]; do + path=$1 + options=$2 + shift; shift; + + ebegin "Unmounting and saving '${path}' (${options})" + + if ! umount "${path}"; then + ewarn "Failed to umount /afs bind: ${path}" + errors=$(( $errors + 1 )) + eend 1 + else + echo "/bin/mount -o ${options} /afs \"${path}\"" \ + >> "${BINDS_STORAGE}" + eend $? + fi + done + + eoutdent + + eend ${errors} + return ${errors} +} + +restore() { + ebegin "Restoring /afs binds from ${BINDS_STORAGE}" + local mount_command= errors=0 + [[ -f "${BINDS_STORAGE}" ]] || return 0 + + while read -r mount_command; do + if ! eval ${mount_command}; then + ewarn "Bind restore '${mount_command}' failed"; + errors=$(( $errors + 1 )) + fi + done < ${BINDS_STORAGE} + + if [[ ${errors} -gt 0 ]]; then + ewarn "${errors} binds failed to restore"; + else + rm -f "${BINDS_STORAGE}" + fi + + eend ${errors} + return ${errors} +} + stop() { ebegin "Stopping OpenAFS client" - failed=1 + local failed=1 eindent + [[ "${UNBIND_ON_STOP}" == "yes" ]] && unbind # Three stage process: unmount / stop daemon / unload module ebegin "Unmounting /afs" + if ! umount /afs; then eend 1 else diff --git a/scripts/openafs-server b/scripts/openafs-server index 0e047e2..3425979 100755 --- a/scripts/openafs-server +++ b/scripts/openafs-server @@ -36,17 +36,13 @@ stop() { # This kindly kills all server processes if ! /usr/bin/bos shutdown localhost -localauth -wait; then - eend 1 - else start-stop-daemon --quiet --stop --pidfile /var/run/bosserver.pid - failed=$? - eend $failed fi + failed=$? + eend ${failed} eoutdent - if [ $failed != 0 ]; then - return 1 - fi + [ ${failed} -ne 0 ] && return 1 }