#!/bin/sh #------------------------------------------------------------------------------ # /etc/init.d/nfsserver - start script for nfsserver services on eisfair # # Creation: 2002-10-09 M.Schimanski # Last Update: $Id$ # # Copyright (c) 2001-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # 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 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ ### BEGIN INIT INFO # Provides: nfsserver # Required-Start: $network $named $rpcbind # Required-Stop: $network $rpcbind # Should-Start: # Should-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Short-Description: the kernel based NFS daemon ### END INIT INFO # read eislib etc. . /etc/init.d/functions # set package name package_name='nfs-server' # debug mode true/false #debug=true if ${debug:-false} then exec 2> /tmp/${package_name}-init-trace$$.log set -x ask_debug=true export ask_debug fi # make bash_completion happy bash_completion_string="Usage: ${0} {start|stop|status|restart}" # --------------------------------------------------------------------------- # usage # --------------------------------------------------------------------------- usage() { cat </dev/null } #------------------------------------------------------------------------------ # remove obsolete nfsclient run file #------------------------------------------------------------------------------ clean_nfsclient() { local _clean_installed_version # check nfsclient version _clean_installed_version=$(/usr/bin/eisman check nfsclient 1.0.0) if [ "${_clean_installed_version}" = 'not-installed' ] && [ -f ${nfsclient_run} ] then /usr/bin/rm -f ${nfsclient_run} fi } #------------------------------------------------------------------------------ # mount nfsdfs #------------------------------------------------------------------------------ mount_nfsdfs() { if /usr/bin/grep -q 'nfsd' /proc/filesystems && [ ! -f /proc/fs/nfsd/exports ] then /usr/bin/mount -t nfsd nfsd /proc/fs/nfsd fi } #------------------------------------------------------------------------------ # umount nfsdfs #------------------------------------------------------------------------------ umount_nfsdfs() { if [ -f /proc/fs/nfsd/exports ] && /usr/bin/grep -q 'nfsd' /proc/filesystems then /usr/bin/umount /proc/fs/nfsd fi } #------------------------------------------------------------------------------ # mount rpc_pipefs #------------------------------------------------------------------------------ mount_rpc_pipefs() { # check if the file system is there yet case $(stat -c "%t" -f "${rpc_pipefs_dir}") in *67596969*) return 0 ;; esac /usr/bin/mount -t rpc_pipefs rpc_pipefs "${rpc_pipefs_dir}" } #------------------------------------------------------------------------------ # umount rpc_pipefs #------------------------------------------------------------------------------ umount_rpc_pipefs() { case $(stat -c "%t" -f "${rpc_pipefs_dir}") in *67596969*) /usr/bin/umount "${rpc_pipefs_dir}" ;; esac } #------------------------------------------------------------------------------ # NFSv4 mount binds #------------------------------------------------------------------------------ mount_bind_nfsv4_shares() { local _mbns_nfs4_share local _mbns_nfs4_short_share if [ "${NFS_SERVER_SUPPORT_NFS4}" = 'yes' -a -s ${nfs4_mountbind_cmds} ] then /usr/bin/cat ${nfs4_mountbind_cmds} | /usr/bin/grep -v "^#" | while read line do _mbns_nfs4_share=$(echo "${line}" | cut -d' ' -f2) /usr/bin/mount | /usr/bin/grep -q " ${_mbns_nfs4_share} " if [ $? -ne 0 ] then _mbns_nfs4_short_share=$(echo "${_mbns_nfs4_share}" | sed "s#^${default_nfs4_exportpath}##") boot_mesg " * Mounting (bind) NFSv4 share '${_mbns_nfs4_short_share}' ..." /usr/bin/mount --bind ${line} /usr/bin/mount | /usr/bin/grep -q " ${_mbns_nfs4_share} " evaluate_retval fi done fi } #------------------------------------------------------------------------------ # NFSv4 umount binds #------------------------------------------------------------------------------ umount_bind_nfsv4_shares() { local _ubns_nfs4_share local _ubns_nfs4_short_share # /tmp/path/to/share-1 on /srv/nfs4exports/SHARE-NAME/share-1 type none (rw,bind) /usr/bin/mount | /usr/bin/grep " ${default_nfs4_exportpath}/" | /usr/bin/sort -r | while read line do # umount NFSv4 mount bind _ubns_nfs4_share="$(echo ${line} | /usr/bin/cut -d' ' -f3)" if [ -n "${_ubns_nfs4_share}" ] then _ubns_nfs4_short_share=$(echo "${_ubns_nfs4_share}" | sed "s#^${default_nfs4_exportpath}##") boot_mesg " * Unmounting (bind) NFSv4 share '${_ubns_nfs4_short_share}' ..." /usr/bin/umount ${_ubns_nfs4_share} evaluate_retval fi done } #------------------------------------------------------------------------------ # kill proc #------------------------------------------------------------------------------ kill_proc() { proc=${1} for COUNT in 1 2 3 4 5 6 do if [ ${COUNT} -le 3 ] then # stop program the soft way (-15) /sbin/killproc -TERM ${proc} 2>/dev/null else # stop program the hard way (-9) /sbin/killproc -KILL ${proc} 2>/dev/null fi if ! checkproc ${proc} then # program stopped successfully kill_ret=0 break else sleep 1 fi done return ${kill_ret:-1} } #------------------------------------------------------------------------------ # start nfsserver #------------------------------------------------------------------------------ start_nfs_server() { local _start_rpcprogs local _start_coptions local _start_options # See if rpcbind is running if [ -x /usr/sbin/rpcinfo ] then /usr/sbin/rpcinfo -p >/dev/null 2>&1 ret=${?} if [ ${ret} -ne 0 ] then boot_mesg " * Not starting: rpcbind is not running ..." echo_failure exit 0 fi fi if [ ${NFS_SERVER_SHARE_N:-0} -gt 0 ] then if [ ! -d "${default_nfs4_exportpath}" -a "${NFS_SERVER_SHARE_N}" -gt 0 -a "${NFS_SERVER_SUPPORT_NFS4}" = 'yes' ] then boot_mesg " * Recreate export path '${default_nfs4_exportpath}' ..." /var/install/config.d/nfs-server.sh --quiet if [ -d "${default_nfs4_exportpath}" ] then echo_ok else echo_failure fi fi # load kernel modules if necessary for MNAME in sunrpc lockd nfsd do # check if kernel module has already been loaded load_modules ${MNAME} done # mount nfsdfs mount_nfsdfs # create NFSv4 mount binds mount_bind_nfsv4_shares # export NFS shares /usr/sbin/exportfs -r > /dev/null 2>&1 if [ "${NFS_SERVER_SUPPORT_NFS4}" = 'yes' ] then if mount_rpc_pipefs then pidofproc -s /usr/sbin/rpc.idmapd case "${?}" in 0) if ! basename $0 | grep -qE "^S[0-9][0-9]" then boot_mesg " * NFS daemon 'rpc.idmapd' is already running ..." echo_warning fi ;; 3) boot_mesg " * Starting NFS daemon 'rpc.idmapd' ..." loadproc /usr/sbin/rpc.idmapd ;; esac # boot_mesg " * Starting NFS daemon 'rpc.svcgssd' ..." # loadproc /usr/sbin/rpc.svcgssd fi fi nfsd_options='' # set number of rpc.nfsd threads: 3 if [ "${NFS_SERVER_SUPPORT_NFS3}" = 'no' ] then nfsd_options='--no-nfs-version 2 --no-nfs-version 3 3' elif [ "${NFS_SERVER_SUPPORT_NFS4}" = 'no' ] then nfsd_options='--no-nfs-version 4 3' fi boot_mesg " * Starting NFS daemon 'rpc.nfsd' ..." /usr/sbin/rpc.nfsd 0 loadproc /usr/sbin/rpc.nfsd ${nfsd_options} evaluate_retval mountd_options='' if [ "${NFS_SERVER_SUPPORT_NFS3}" = 'no' ] then mountd_options='--no-nfs-version 2 --no-nfs-version 3' elif [ "${NFS_SERVER_SUPPORT_NFS4}" = 'no' ] then mountd_options='--no-nfs-version 4' fi pidofproc -s /usr/sbin/rpc.mountd case "${?}" in 0) boot_mesg " * NFS daemon 'rpc.mountd' is already running ..." echo_warning ;; 3) boot_mesg " * Starting NFS daemon 'rpc.mountd' ..." loadproc /usr/sbin/rpc.mountd ${mountd_options} ;; esac # send reboot notifications to NFS peers /usr/sbin/sm-notify fi } #------------------------------------------------------------------------------ # stop nfsserver #------------------------------------------------------------------------------ stop_nfs_server() { local _stop_rpcprogs local _stop_options local _stop_proc # unexport NFS shares /usr/sbin/exportfs -au > /dev/null 2>&1 # remove NFSv4 mount binds umount_bind_nfsv4_shares pidofproc -s /usr/sbin/rpc.mountd case "${?}" in 0) boot_mesg " * Stopping NFS daemon 'rpc.mountd' ..." kill_proc /usr/sbin/rpc.mountd evaluate_retval ;; esac pidofproc -s /usr/sbin/rpc.idmapd case "${?}" in 0) # boot_mesg " * Stopping NFS daemon 'rpc.svcgssd' ..." # killproc /usr/sbin/rpc.svcgssd # evaluate_retval boot_mesg " * Stopping NFS daemon 'rpc.idmapd' ..." kill_proc /usr/sbin/rpc.idmapd evaluate_retval ;; esac pidofproc -s /usr/sbin/rpc.nfsd case "${?}" in 0) boot_mesg " * Stopping NFS daemon 'rpc.nfsd' ..." kill_proc /usr/sbin/rpc.nfsd evaluate_retval ;; esac # make sure sm-notify is run on restart, # as we have dropped some locks # send reboot notifications to NFS peers rm -f /var/run/sm-notify.pid # umount rpc_pipefs umount_rpc_pipefs # umount nfsdfs umount_nfsdfs # remove run status file if [ -f ${nfsserver_run} ] then /usr/bin/rm -f ${nfsserver_run} fi } #------------------------------------------------------------------------------ # status of nfsserver #------------------------------------------------------------------------------ status_nfs_server() { local _status_rpcprogs local _status_options local _status_pid check_nfs=$(/usr/bin/grep "^nfs " /proc/modules) if [ -n "${check_nfs}" ] then boot_mesg "NFS kernel module 'nfs' loaded." ${INFO} else boot_mesg "NFS kernel module 'nfs' not loaded." ${INFO} fi statusproc /usr/sbin/rpc.statd statusproc /usr/sbin/rpc.mountd statusproc /usr/sbin/rpc.nfsd if [ "${NFSSERVER_SUPPORT_NFS4}" = 'yes' ] then statusproc /usr/sbin/rpc.idmapd fi } #============================================================================== # main #============================================================================== EXEC_CMD="$0 $*" configfile=/etc/config.d/${package_name} nfsclient_run=/run/nfsclient.run nfsserver_run=/run/${package_name}.run nfspmap_file=/run/${package_name}-pmap.list rpc_pipefs_dir=/var/lib/nfs/rpc_pipefs default_nfs4_exportpath=/srv/nfs4exports nfs4_mountbind_cmds=/var/lib/nfs/nfs4-mountbinds . ${configfile} # get parameters _quiet=false while [ 1 ] do case "$1" in *-debug ) # force debug mode NFSSERVER_DO_DEBUG='yes' shift ;; *-quiet ) # suppress output _quiet=true shift ;; * ) cmd=$1 break ;; esac done case ${cmd} in start) clean_nfsclient start_nfs_server ;; stop ) stop_nfs_server ;; status ) status_nfs_server ;; restart ) stop_nfs_server sleep 2 start_nfs_server ;; * ) usage exit 0 ;; esac #============================================================================== # end #============================================================================== exit 0