-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_clusters.sh
executable file
·115 lines (101 loc) · 2.33 KB
/
start_clusters.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# start_clusters.sh
# Startup script for Slurm
# Print usage with ./start_clusters -h
# Get path to script: https://stackoverflow.com/a/1482133/4880288
install_path="$(dirname -- "$( readlink -f -- "$0"; )";)"
source "${install_path}/script_common.sh"
num_clusters=1
num_nodes=10
slurmctld_flags=''
verbose=0
print_usage() {
printf "\
Usage: ./start_clusters.sh [-c<num_clusters>] [-h] [-n<num_nodes>] \
[-o<'slurmctld_flags'>] [-v]
-c: Number of clusters to start. Valid numbers: 1, 2, or 3.
-f: Path to alternate slurm.conf.
-h: Print this usage string.
-n: Number of nodes (slurmd's) to start. Valid numbers: 1-99.
-o: Flags to pass to slurmctld. Must be surrounded by quotes.
-v: Print verbose logs.
"
}
while getopts 'c:f:hn:o:uv' flag
do
case "${flag}" in
c) num_clusters=${OPTARG} ;;
f) slurm_conf=${OPTARG} ;;
h) print_usage
exit 1 ;;
n) num_nodes=${OPTARG} ;;
o) slurmctld_flags=${OPTARG} ;;
v) verbose=1 ;;
esac
done
if [ $verbose -ne 0 ]
then
echo "num_clusters=$num_clusters"
echo "num_nodes=$num_nodes"
echo "slurmctld_flags=$slurmctld_flags"
set -x
fi
# Validate options
validate_number $num_clusters 1 3 "-c"
validate_number $num_nodes 1 99 "-n"
if [ $num_clusters -eq 1 ]
then
echo "Starting cluster c1"
else
echo "Starting clusters c[1-$num_clusters]"
fi
sudo ./stop_clusters.sh
if [ -z "${slurm_conf}" ]
then
export SLURM_CONF="${install_path}/etc/slurm.conf"
else
export SLURM_CONF="${slurm_conf}"
fi
# Start slurmdbd
echo "Start slurmdbd"
"${install_path}"/sbin/slurmdbd
sleep 1
# Start slurmctld's
i=1
while [ $i -le $num_clusters ]
do
if [ -z "${slurm_conf}" ]
then
SLURM_CONF="${install_path}/c$i/etc/slurm.conf"
else
SLURM_CONF="${slurm_conf}"
fi
echo "Start slurmctld"
"${install_path}"/sbin/slurmctld -f $SLURM_CONF $slurmctld_flags
i=$(($i+1))
done
# Start slurmd's - start them all in parallel
i=1
while [ $i -le $num_clusters ]
do
node_inx=1
if [ -z "${slurm_conf}" ]
then
SLURM_CONF="${install_path}/c$i/etc/slurm.conf"
else
SLURM_CONF="${slurm_conf}"
fi
while [ $node_inx -le $num_nodes ]
do
nodename="n${i}-${node_inx}"
echo "Start node ${nodename}"
export NODE_NAME=${nodename}
sudo --background --preserve-env=NODE_NAME "${install_path}"/sbin/slurmd -f $SLURM_CONF -N ${nodename}
node_inx=$(($node_inx+1))
done
i=$(($i+1))
done
if [ $verbose -ne 0 ]
then
set +x
fi