-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiorelay-mount-nodezero.sh
executable file
·81 lines (74 loc) · 2.48 KB
/
iorelay-mount-nodezero.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
###############################################################################
#
# Copyright (C) 2007-2008 Lawrence Livermore National Security, LLC.
# Produced at Lawrence Livermore National Laboratory.
# Written by Jim Garlick <[email protected]>.
#
# UCRL-CODE-235358
#
# This file is part of chaos-spankings, a set of spank plugins for SLURM.
#
# This 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.
#
# This is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
#
# iorelay-mount-nodezero - mount / from first slurm node on /mnt
#
# Run as root in private namespace.
#
declare -r prog=iorelay-mount-nodezero
declare -r sshcmd=/usr/libexec/iorelay-mrsh-sshfs-wrap
die ()
{
echo "$prog: $1" >&2
exit 1
}
warn ()
{
echo "$prog: $1" >&2
}
usage ()
{
echo "Usage: $prog -m mntpt -u username"
exit 1
}
[ -n "$SLURM_NODELIST" ] || die "SLURM_NODELIST is not set"
relayhost=$(echo $SLURM_NODELIST | glob-hosts -n1)
[ -n "$relayhost" ] || die "could not determine relayhost"
[ "$(hostname)" = "$relayhost" ] && exit 0 # silently exit if relayhost
mntpt=""
username=""
while getopts "u:m:" opt; do
case ${opt} in
m) mntpt=${OPTARG} ;;
u) username=${OPTARG} ;;
*) usage ;;
esac
done
shift $((${OPTIND} - 1))
[ $# = 0 ] || usage
[ -n "$mntpt" ] || usage
[ -d $mntpt ] || die "not a directory: $mntpt"
[ -n "$username" ] || usage
uid=$(id -u $username 2>&1) || die "no such user: $username"
[ "$uid" != 0 ] || die "sshfs as root is unsupported"
grep -q sshfs /proc/mounts && die "sshfs is already mounted"
# NOTE: work around missing -n option in sshfs/fusermount
mv -f /etc/mtab /etc/mtab-iorelay || die "failed to back up /etc/mtab"
sshfs -o ssh_command=${sshcmd} ${username}@${relayhost}/ ${mntpt}
result=$?
mv -f /etc/mtab-iorelay /etc/mtab || warn "failed to restore /etc/mtab"
[ $result = 0 ] || die "sshfs mount ${username}@${relayhost}/ ${mntpt} failed"
exit 0