# ocfs2-tools description "LliureX network net ocfs2" start on (started networking) #stop on ( llx-cluster-ocfs2-stop ) #emits llx-cluster-ocfs2-stop task script MAX_TIME=120 SLEEP_TIME=2 RUNNING_TIME=0 RUNNING_TIME_SEARCH_OCFS2=0 RUNNING_TIME_SEARCH_ISCSI=0 RUNNING_TIME_SEARCH_MULTIPATH=0 STOP_SERVICE_OCFS2="N" STOP_SERVICE_ISCSI="N" STOP_SERVICE_MULTIPATH="N" STOP_SERVICE="N" OCFS2_DISK_TMP="" OCFS2_MOUNT_FSTAB="/ocfs2" eval `n4d-vars getvalues OCFS2_NET_EXPORT_DIRS` eval `n4d-vars getvalues OCFS2_DISK` # VAR_LIST="OCFS2_NET_EXPORT_DIRS OCFS2_DISK OCFS2_MOUNT_FSTAB" # LLX_GETVAR="/usr/sbin/llxcfg-showvars" # eval `${LLX_GETVAR} ${VAR_LIST}` if [ -x "/sbin/iscsid" ] && [ -x "/sbin/mount.ocfs2" ]; then while : ; do STOP_SERVICE_ISCSI="N" if pidof iscsid; then STOP_SERVICE_ISCSI="Y" sleep $SLEEP_TIME break fi if [ $RUNNING_TIME_SEARCH_ISCSI -gt $MAX_TIME ]; then exit 0 fi sleep $SLEEP_TIME RUNNING_TIME_SEARCH_ISCSI=$(($RUNNING_TIME_SEARCH_ISCSI + $SLEEP_TIME)) done fi if [ -x "/sbin/multipathd" ] && [ -x "/sbin/multipath" ]; then while : ; do STOP_SERVICE_MULTIPATH="N" if pidof multipathd; then STOP_SERVICE_MULTIPATH="Y" sleep $SLEEP_TIME break fi if [ $RUNNING_TIME_SEARCH_MULTIPATH -gt $MAX_TIME ]; then exit 0 fi sleep $SLEEP_TIME RUNNING_TIME_SEARCH_MULTIPATH=$(($RUNNING_TIME_SEARCH_MULTIPATH + $SLEEP_TIME)) done fi if [ -x "/sbin/mount.ocfs2" ]; then while : ; do STOP_SERVICE_OCFS2="N" if [ -e /sys/kernel/config/cluster/ocfs2 ] && [ -e /dlm ]; then STOP_SERVICE_OCFS2="Y" fi if [ "$STOP_SERVICE_OCFS2" = "Y" ]; then if [ -x "/sbin/multipath" ]; then for mpath in $(ls /dev/mapper/); do if tunefs.ocfs2 -Q "%N" /dev/mapper/$mpath 2>/dev/null >/dev/null; then COUNT_PARTS=$(/sbin/dmsetup info /dev/mapper/$mpath | awk '$1 = /Open count:/ {print $3}') MAJOR_PART=$(/sbin/dmsetup info /dev/mapper/$mpath | awk '$1 = /Major, minor:/ {print $3}' | tr -d ",") MINOR_PART=$(/sbin/dmsetup info /dev/mapper/$mpath | awk '$1 = /Major, minor:/ {print $4}' | tr -d ",") if [ $COUNT_PARTS -gt 0 ] && [ $MAJOR_PART ] && [ $MINOR_PART ]; then /sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -d -p -part' -j $MAJOR_PART -m $MINOR_PART fi OCFS2_DISK_TMP="/dev/mapper/$mpath" break fi done fi if [ -z "$OCFS2_DISK_TMP" ]; then for mpath in $(sfdisk -s | tac | tail -n +2 | awk -F":" '{print $1}'); do if tunefs.ocfs2 -Q "%N" $mpath 2>/dev/null >/dev/null; then OCFS2_DISK_TMP="$mpath" break fi done fi break fi if [ $RUNNING_TIME_SEARCH_OCFS2 -gt $MAX_TIME ]; then exit 0 fi sleep $SLEEP_TIME RUNNING_TIME_SEARCH_OCFS2=$(($RUNNING_TIME_SEARCH_OCFS2 + $SLEEP_TIME)) done fi if [ -x "/sbin/mount.ocfs2" ] && [ $OCFS2_DISK_TMP ]; then [ ! -d "$OCFS2_MOUNT_FSTAB" ] && mkdir -p "$OCFS2_MOUNT_FSTAB" CHECK_MOUNT_OCFS2=$(LC_ALL=C awk -v dev="$OCFS2_DISK_TMP" -v fstab="$OCFS2_MOUNT_FSTAB" '$1 == dev && $2 == fstab && $3 == "ocfs2" { print "yes" }' /proc/mounts) if [ "$CHECK_MOUNT_OCFS2" != "yes" ]; then mount -t ocfs2 -o acl,defaults $OCFS2_DISK_TMP $OCFS2_MOUNT_FSTAB || true fi if [ "$OCFS2_DISK_TMP" != "$OCFS2_DISK" ]; then OCFS2_DISK="$OCFS2_DISK_TMP" fi while : ; do STOP_SERVICE="N" CHECK_MOUNT_OCFS2=$(LC_ALL=C awk -v dev="$OCFS2_DISK_TMP" -v fstab="$OCFS2_MOUNT_FSTAB" '$1 == dev && $2 == fstab && $3 == "ocfs2" { print "yes" }' /proc/mounts) if [ "$CHECK_MOUNT_OCFS2" = "yes" ]; then STOP_SERVICE="Y" fi if [ "$STOP_SERVICE" = "Y" ] && [ $OCFS2_MOUNT_FSTAB ]; then #if [ "$(LC_ALL=C awk '$2 == "/export/net" { print "found" }' /proc/mounts)" = "found" ]; then # umount /export/net || true #fi logger -t OCFS2 -s "Mounting $OCFS2_NET_EXPORT_DIR" for ocfs_dir in $OCFS2_NET_EXPORT_DIRS; do CHECK_OCFS2_DIR_MOUNT=$(LC_ALL=C awk -v dev="$OCFS2_DISK_TMP" -v ocfsdir="/net/$ocfs_dir" '$1 == dev && $2 == ocfsdir { print "yes" }' /proc/mounts) if [ "$CHECK_OCFS2_DIR_MOUNT" = "yes" ]; then continue fi [ ! -d $ocfs_dir ] && mkdir $ocfs_dir 2>/dev/null || true if [ ! -d "$OCFS2_MOUNT_FSTAB/$ocfs_dir" ]; then rsync -ax --acls "/net/$ocfs_dir" $OCFS2_MOUNT_FSTAB/ || true fi if [ -d "$OCFS2_MOUNT_FSTAB/$ocfs_dir" ]; then mount --bind "$OCFS2_MOUNT_FSTAB/$ocfs_dir" "/net/$ocfs_dir" || true logger -t OCFS2 -s "Mounted /net/$ocfs_dir" fi done [ -e /etc/ocfs2/mount.ocfs2 ] && . /etc/ocfs2/mount.ocfs2 exit 0 fi if [ $RUNNING_TIME -gt $MAX_TIME ]; then exit 0 fi sleep $SLEEP_TIME RUNNING_TIME=$(($RUNNING_TIME + $SLEEP_TIME)) done fi end script