X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fscripts%2Flustre;h=baa0430dab444e8cb4416a40c20f7119b55d77d4;hb=2b294992edce5af7b79d4300ed3aa1ea6a8db850;hp=e6cca001a4fb8ad21e5b6259bfa566d8a2ced5c0;hpb=113303973ec9f8484eb2355a1a6ef3c4c7fd6a56;p=fs%2Flustre-release.git diff --git a/lustre/scripts/lustre b/lustre/scripts/lustre old mode 100755 new mode 100644 index e6cca00..baa0430 --- a/lustre/scripts/lustre +++ b/lustre/scripts/lustre @@ -1,170 +1,603 @@ -#!/bin/sh +#!/bin/bash # -# lustre This shell script takes care of starting and stopping Lustre +# lustre This shell script takes care of starting and stopping +# the lustre services. # -# chkconfig: - 99 1 -# description: Lustre Lite network File System. -# This starts both Lustre client and server functions. -# processname: lconf -# config: /etc/lustre/config.xml -# pidfile: /var/run/lustre.pid -### BEGIN INIT INFO -# Provides: lustre -# Required-Start: $network +sshd -# Required-Stop: $network -# Should-Start: -# Should-Stop: -# Default-Start: -# Default-Stop: 0 1 2 3 4 5 6 -# Short-Description: Lustre Lite network File System. -# Description: This starts both Lustre client and server functions. -### END INIT INFO - - -SERVICE=${0##*/} - -: ${LUSTRE_CFG:=/etc/lustre/lustre.cfg} -[ -f ${LUSTRE_CFG} ] && . ${LUSTRE_CFG} -[ -f /etc/sysconfig/lustre ] && . /etc/sysconfig/lustre +# chkconfig: - 60 20 +# description: Part of the lustre file system. +# probe: true +# config: /etc/sysconfig/lustre -: ${LUSTRE_CONFIG_XML:=/etc/lustre/config.xml} -: ${LCONF:=/usr/sbin/lconf} -: ${LCTL:=/usr/sbin/lctl} -# Some distros use modprobe.conf.local -if [ -f /etc/modprobe.conf.local ]; then - : ${MODPROBE_CONF:=/etc/modprobe.conf.local} -else - : ${MODPROBE_CONF:=/etc/modprobe.conf} -fi -# Be sure the proper directories are in PATH. -export PATH="/sbin:$PATH" - -case "$SERVICE" in - [SK][[:digit:]][[:digit:]]lustre | lustre) - SERVICE="lustre" - : ${LCONF_START_ARGS:="${LUSTRE_CONFIG_XML}"} - : ${LCONF_STOP_ARGS:="--force --cleanup ${LUSTRE_CONFIG_XML}"} - ;; - *) - : ${LCONF_START_ARGS:="--group ${SERVICE} --select ${SERVICE}=${HOSTNAME} ${LUSTRE_CONFIG_XML}"} - : ${LCONF_STOP_ARGS:="--group ${SERVICE} --select ${SERVICE}=${HOSTNAME} --failover --cleanup ${LUSTRE_CONFIG_XML}"} - ;; -esac -LOCK=/var/lock/subsys/$SERVICE +PATH=/sbin:/usr/sbin:/bin:/usr/bin # Source function library. -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -fi +. /etc/rc.d/init.d/functions # Source networking configuration. -if [ -f /etc/sysconfig/network ] ; then - . /etc/sysconfig/network +if [ ! -f /etc/sysconfig/network ]; then + exit 0 fi -check_start_stop() { - # Exit codes now LSB compliant - # Check that networking is up. - exit 'not running' - [ "${NETWORKING}" = "no" ] && exit 7 +. /etc/sysconfig/network - # exit 'not installed' - [ -x ${LCONF} -a -x ${LCTL} ] || exit 5 +LDEV=${LDEV:-"/usr/sbin/ldev"} +ZPOOL_LAYOUT=/usr/bin/zpool_layout +UDEVADM=${UDEVADM:-/sbin/udevadm} - if [ ${LUSTRE_CONFIG_XML:0:1} = "/" ] ; then - if [ ! -f ${LUSTRE_CONFIG_XML} ] ; then - echo "${0##*/}: Configuration file ${LUSTRE_CONFIG_XML} not found; skipping." - # exit 'not configured' - exit 6 - fi +# Check that networking is up. +[ "${NETWORKING}" = "no" ] && exit 0 + +# Check for and source configuration file otherwise set defaults +[ -f /etc/sysconfig/lustre ] && . /etc/sysconfig/lustre +FSCK_ARGS=${FSCK_ARGS:-""} +MOUNT_OPTIONS=${MOUNT_OPTIONS:-""} +LOCAL_SRV=${LOCAL_SRV:-"`$LDEV -l 2>/dev/null`"} +FOREIGN_SRV=${FOREIGN_SRV:-"`$LDEV -f 2>/dev/null`"} +REQUIRE_MMP_FEATURE=${REQUIRE_MMP_FEATURE:-${FOREIGN_SRV:+"yes"}} +LOCAL_MOUNT_DIR=${LOCAL_MOUNT_DIR:-"/mnt/lustre/local"} +FOREIGN_MOUNT_DIR=${FOREIGN_MOUNT_DIR:-"/mnt/lustre/foreign"} +SETUP_DEVICES=${SETUP_DEVICES:-""} +ZPOOL_LAYOUT_BUSES=${ZPOOL_LAYOUT_BUSES:-""} +ZPOOL_LAYOUT_PORTS=${ZPOOL_LAYOUT_PORTS:-""} +ZPOOL_LAYOUT_MAP=${ZPOOL_LAYOUT_MAP:-""} +MOUNT_DELAY=${MOUNT_DELAY:-2} +LOAD_ZFS=${LOAD_ZFS:-""} + +if [ -z "$TUNE2FS" ] ; then + TUNE2FS=`which tunefs.ldiskfs 2>/dev/null` + if [ -z "$TUNE2FS" ] ; then + TUNE2FS=`which tune2fs 2>/dev/null` + fi +fi + +if [ -z "$PFSCK" ] ; then + PFSCK=`which pfsck.ldiskfs 2>/dev/null` + if [ -z "$PFSCK" ] ; then + PFSCK=`which fsck 2>/dev/null` fi +fi - # Create /var/lustre directory - # This is used by snmp agent for checking lustre services - # status online/offline/online pending/offline pending. +shopt -s nullglob - [ -d ${STATUS_DIR:=/var/lustre} ] || mkdir -p $STATUS_DIR - STATUS=${STATUS_DIR}/sysStatus +start_zfs_services () +{ + if [ -n "$ZPOOL_LAYOUT_BUSES" -a -n "$ZPOOL_LAYOUT_PORTS" ] ; then + MAP_ARG=${ZPOOL_LAYOUT_MAP:+"-m $ZPOOL_LAYOUT_MAP"} + $ZPOOL_LAYOUT -t -b "$ZPOOL_LAYOUT_BUSES" \ + -p "$ZPOOL_LAYOUT_PORTS" $MAP_ARG + fi + if [ "$LOAD_ZFS" = "yes" ] && ! modprobe zfs ; then + echo "Failed to load zfs module. Aborting." + exit 1 + fi } -start() { - if [ -x "/usr/sbin/clustat" -a "${SERVICE}" = "lustre" ] ; then - if [ ! -f "/etc/lustre/start-despite-clumanager" ] ; then - cat >&2 </dev/null 2>&1 ; then + result=0 + elif [ -n "$pool" ] ; then + zpool import $pool $args 2>/dev/null + result=$? fi - check_start_stop - echo -n "Starting $SERVICE: " - if [ $UID -ne 0 ]; then - echo "Lustre should be started as root" - RETVAL=4 # insufficent privileges - return + if [ $result -ne 0 ] ; then + echo "Unexpected return code from import of pool $pool: $result" fi - # Cat the modprobe file and place all lines that follow a trailing backslash on the same line - ROUTER=`cat ${MODPROBE_CONF} | sed ':a;N;$!ba;s#\\\[:space:]*\\n##g' | grep lnet | grep forwarding=\"enabled\"` - if [[ ! -z ${ROUTER} ]]; then - modprobe lnet - ${LCTL} network configure + return $result +} + +export_zpool () +{ + local label=$1 + local pool=`$LDEV -z $label` + zpool export $pool 2>/dev/null +} + +# Trigger udev and wait for it to settle. +udev_trigger() +{ + if [ -x ${UDEVADM} ]; then + ${UDEVADM} trigger --action=change --subsystem-match=block + ${UDEVADM} settle else - ${LCONF} ${LCONF_START_ARGS} + /sbin/udevtrigger + /sbin/udevsettle fi - RETVAL=$? - echo $SERVICE - if [ $RETVAL -eq 0 ]; then - touch $LOCK - echo "online" >$STATUS - else - echo "online pending" >$STATUS +} + +# Usage: run_preexec_check [ start | restart | condrestart ] +# The single parameter will be passed to the PREEXEC_SCRIPT +run_preexec_check () +{ + if [ -n "$PREEXEC_CHECK" ] && ! $PREEXEC_CHECK ; then + echo "Pre-exec check \"$PREEXEC_CHECK\" failed. Aborting." + exit 1 + fi + + if [ -n "$PREEXEC_SCRIPT" ] && ! "$PREEXEC_SCRIPT" "$1" ; then + echo "Pre-exec script \"$PREEXEC_SCRIPT\" failed. Aborting." + exit 1 fi } -stop() { - check_start_stop - echo -n "Shutting down $SERVICE: " - if [ $UID -ne 0 ]; then - echo "Lustre should be stopped as root" - RETVAL=4 # insufficent privileges - return +# Usage: run_postexec_check [ start | restart | condrestart ] +# The single parameter will be passed to the PREEXEC_SCRIPT +run_postexec_check () +{ + if [ -n "$POSTEXEC_CHECK" ] && ! $POSTEXEC_CHECK ; then + echo "Post-exec check \"$POSTEXEC_CHECK\" failed. Aborting." + exit 1 fi - # Cat the modprobe file and place all lines that follow a trailing backslash on the same line - ROUTER=`cat ${MODPROBE_CONF} | sed ':a;N;$!ba;s#\\\[:space:]*\\n##g' | grep lnet | grep forwarding=\"enabled\"` - if [[ ! -z ${ROUTER} ]]; then - MODULE_LOADED=`lsmod | awk ' { print $1 } ' | grep lnet` - if [[ ! -z ${MODULE_LOADED} ]]; then - ${LCTL} network unconfigure + + if [ -n "$POSTEXEC_SCRIPT" ] && ! "$POSTEXEC_SCRIPT" "$1" ; then + echo "Post-exec script \"$POSTEXEC_SCRIPT\" failed. Aborting." + exit 1 + fi +} + +# Usage: adjust_scsi_timeout +adjust_scsi_timeout () +{ + local dev=$1 + + if [ -n "$SCSI_DEVICE_TIMEOUT" ]; then + # make sure that it is actually a SCSI (sd) device + local name=`basename $dev` + local proc=/sys/block/${name}/device/timeout + local driver=`readlink /sys/block/${name}/device/driver` + if [ -n "$driver" ] && [ "`basename $driver`" == "sd" ]; then + if ! echo $SCSI_DEVICE_TIMEOUT >$proc; then + echo "FAILED: could not adjust ${dev} timeout" + return 1 + fi fi - ${LCTL} modules | awk '{ print $2 }' | xargs rmmod >/dev/null 2>&1 - # do it again, in case we tried to unload ksocklnd too early - ${LCTL} modules | awk '{ print $2 }' | xargs rmmod + fi + return 0 +} - else - ${LCONF} ${LCONF_STOP_ARGS} +# Usage: fsck_test [ ... ] +# Checks all devices in parallel if FSCK_ARGS is set. +fsck_test () +{ + local devices="$*" + + # Filter out non-absolute paths, which are probably ZFS datasets + devices=`echo $devices |xargs -n 1|grep '^/'|xargs` + + if [ -n "${FSCK_ARGS}" -a -n "$devices" ]; then + if [ -x $PFSCK ] ; then + echo "$PFSCK $devices -- ${FSCK_ARGS}" + $PFSCK $devices -- ${FSCK_ARGS} + if [ $? -ne 0 -a $? -ne 1 ] ; then + echo "FAILED: $PFSCK -- ${FSCK_ARGS}: $?" + return 1 + fi + else + echo "$PFSCK not found" + return 1 + fi fi - RETVAL=$? - echo $SERVICE - rm -f $LOCK - if [ $RETVAL -eq 0 ]; then - echo "offline" >$STATUS + return 0 +} + +# Usage: test_feature_flag +test_feature_flag() +{ + local dev=$1 + local flag=$2 + local result=1 + local feature + + for feature in `$TUNE2FS -l $dev 2>/dev/null \ + | grep features: | sed -e 's/^.*: //'`; do + if [ "$feature" == "$flag" ]; then + result=0 + break + fi + done + + return $result +} + +# Usage: mmp_test +# Returns 0 if it is set or not required, 1 if unset and required or error. +mmp_test () +{ + local dev=$1 + local result=0 + + if [ "$REQUIRE_MMP_FEATURE" == "yes" ]; then + if [ -x $TUNE2FS ]; then + if ! test_feature_flag $dev "mmp"; then + echo "mmp feature flag is not set on $dev" + result=1 + fi + else + echo "$TUNE2FS not found" + result=1 + fi + fi + + return $result +} + +# Usage: label_to_mountpt