#!/bin/sh

if ! auto-root-check $0; then
    exit 1
fi

case $(auto-os-release) in
FreeBSD*)
    # Thorough restart that should resolve stale NFS mounts and
    # client I/O errors
    if grep -q '^nfsuserd_enable="YES"' /etc/rc.conf; then
	service nfsuserd stop
    fi
    service nfsd stop
    if grep -q '^rpc_lockd_enable="YES"' /etc/rc.conf; then
	service lockd stop
    fi
    if grep -q '^rpc_statd_enable="YES"' /etc/rc.conf; then
	service statd stop
    fi

    # rpcbind is not strictly strictly necessary for NFSv4-only servers
    # man mountd, -R flag
    service rpcbind onerestart
    service mountd onerestart
    
    if grep -q '^rpc_statd_enable="YES"' /etc/rc.conf; then
	service statd start
    fi
    if grep -q '^rpc_lockd_enable="YES"' /etc/rc.conf; then
	service lockd start
    fi
    service nfsd start
    if grep -q '^nfsuserd_enable="YES"' /etc/rc.conf; then
	service nfsuserd start
    fi
    ;;

RHEL7|RHEL8)
    # FIXME: Make this more thorough, as the FreeBSD case
    systemctl restart nfs
    ;;

*)
    auto-unsupported-release $0
    exit 1
    ;;

esac
