forked from mknoxnv/ubuntu-slurm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslurmd.init
349 lines (318 loc) · 8.79 KB
/
slurmd.init
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/sh
#
# chkconfig: 345 90 10
# description: SLURM is a simple resource management system which \
# manages exclusive access o a set of compute \
# resources and distributes work to those resources.
#
# processname: /usr/sbin/slurmd
# pidfile: /var/run/slurm/slurmd.pid
#
# processname: /usr/sbin/slurmctld
# pidfile: /var/run/slurm/slurmctld.pid
#
# config: /etc/default/slurm
#
### BEGIN INIT INFO
# Provides: slurm
# Required-Start: $remote_fs $syslog $network munge
# Required-Stop: $remote_fs $syslog $network munge
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: slurm daemon management
# Description: Start slurm to provide resource management
### END INIT INFO
BINDIR=/usr/bin
CONFDIR=/etc/slurm
LIBDIR=/usr/lib
SBINDIR=/usr/sbin
# Source slurm specific configuration
if [ -f /etc/default/slurm ] ; then
. /etc/default/slurm
else
SLURMCTLD_OPTIONS=""
SLURMD_OPTIONS="-d /usr/sbin/slurmstepd"
fi
# Checking for slurm.conf presence
if [ ! -f $CONFDIR/slurm.conf ] ; then
if [ -n "$(echo $1 | grep start)" ] ; then
echo Not starting slurm
fi
echo slurm.conf was not found in $CONFDIR
echo Please follow the instructions in \
/usr/share/doc/slurm/README.Debian.gz
exit 0
fi
test -f $BINDIR/scontrol || exit 0
DAEMONLIST=$($BINDIR/scontrol show daemons 2>/dev/null)
if [ $? = 0 ] ; then
for prog in $DAEMONLIST ; do
test -f $SBINDIR/$prog || exit 0
done
else
if [ -n "$(echo $1 | grep start)" ] ; then
echo "Not starting slurm for problems in the configuration file"
else
echo "Problems in the configuration file"
fi
echo "${CONFDIR}/slurm.conf"
echo "If upgrading from version 1.2 it is recommended that you rebuild"
echo "your configuration file. Please read instructions in"
echo " /usr/share/doc/slurm/README.Debian"
echo "Otherwise use \"scontrol show daemons\" for more information"
exit 0
fi
#Checking for lsb init function
if [ -f /lib/lsb/init-functions ] ; then
. /lib/lsb/init-functions
else
echo Can\'t find lsb init functions
exit 1
fi
# setup library paths for slurm and munge support
export LD_LIBRARY_PATH=$LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
#Function to check for cert and key presence and key vulnerabilty
checkcertkey()
{
MISSING=""
keyfile=""
certfile=""
if [ "$1" = "slurmd" ] ; then
keyfile=$(grep JobCredentialPublicCertificate $CONFDIR/slurm.conf \
| grep -v "^ *#")
keyfile=${keyfile##*=}
keyfile=${keyfile%#*}
[ -e $keyfile ] || MISSING="$keyfile"
elif [ "$1" = "slurmctld" ] ; then
keyfile=$(grep JobCredentialPrivateKey $CONFDIR/slurm.conf | grep -v "^ *#")
keyfile=${keyfile##*=}
keyfile=${keyfile%#*}
[ -e $keyfile ] || MISSING="$keyfile"
fi
if [ "${MISSING}" != "" ] ; then
echo Not starting slurm
echo $MISSING not found
echo Please follow the instructions in \
/usr/share/doc/slurm/README.cryptotype-openssl
exit 0
fi
if [ -f "$keyfile" ] && [ "$1" = "slurmctld" ] ; then
keycheck=$(openssl-vulnkey $keyfile | cut -d : -f 1)
if [ "$keycheck" = "COMPROMISED" ] ; then
echo Your slurm key stored in the file $keyfile
echo is vulnerable because has been created with a buggy openssl.
echo Please rebuild it with openssl version \>= 0.9.8g-9
echo More information in /usr/share/doc/slurm/README.Debian
exit 0
fi
fi
}
get_daemon_description()
{
case $1 in
slurmd)
echo slurm compute node daemon
;;
slurmctld)
echo slurm central management daemon
;;
*)
echo slurm daemon
;;
esac
}
start() {
CRYPTOTYPE=$(grep CryptoType $CONFDIR/slurm.conf | grep -v "^ *#")
CRYPTOTYPE=${CRYPTOTYPE##*=}
CRYPTOTYPE=${CRYPTOTYPE%#*}
if [ "$CRYPTOTYPE" = "crypto/openssl" ] ; then
checkcertkey $1
fi
# Create run-time variable data
mkdir -p /var/run/slurm
chown slurm:slurm /var/run/slurm
# Checking if SlurmdSpoolDir is under run
if [ "$1" = "slurmd" ] ; then
SDIRLOCATION=$(grep SlurmdSpoolDir /etc/slurm/slurm.conf \
| grep -v "^ *#")
SDIRLOCATION=${SDIRLOCATION##*=}
SDIRLOCATION=${SDIRLOCATION%#*}
if [ "${SDIRLOCATION}" = "/var/run/slurm/slurmd" ] ; then
if ! [ -e /var/run/slurm/slurmd ] ; then
ln -s /var/lib/slurm/slurmd /var/run/slurm/slurmd
fi
fi
fi
# Checking if StateSaveLocation is under run
if [ "$1" = "slurmctld" ] ; then
SDIRLOCATION=$(grep StateSaveLocation /etc/slurm/slurm.conf \
| grep -v "^ *#")
SDIRLOCATION=${SDIRLOCATION##*=}
SDIRLOCATION=${SDIRLOCATION%#*}
if [ "${SDIRLOCATION}" = "/var/run/slurm/slurmctld" ] ; then
if ! [ -e /var/run/slurm/slurmctld ] ; then
ln -s /var/lib/slurm/slurmctld /var/run/slurm/slurmctld
fi
fi
fi
desc="$(get_daemon_description $1)"
log_daemon_msg "Starting $desc" "$1"
unset HOME MAIL USER USERNAME
#FIXME $STARTPROC $SBINDIR/$1 $2
STARTERRORMSG="$(start-stop-daemon --start --oknodo \
--exec "$SBINDIR/$1" -- $2 2>&1)"
STATUS=$?
log_end_msg $STATUS
if [ "$STARTERRORMSG" != "" ] ; then
echo $STARTERRORMSG
fi
touch /var/lock/slurm
}
stop() {
desc="$(get_daemon_description $1)"
log_daemon_msg "Stopping $desc" "$1"
STOPERRORMSG="$(start-stop-daemon --oknodo --stop -s TERM \
--exec "$SBINDIR/$1" 2>&1)"
STATUS=$?
log_end_msg $STATUS
if [ "$STOPERRORMSG" != "" ] ; then
echo $STOPERRORMSG
fi
rm -f /var/lock/slurm
}
startall() {
for PROG in $DAEMONLIST ; do
case $PROG in
slurmd)
OPTVAR=$SLURMD_OPTIONS
;;
slurmctld)
OPTVAR=$SLURMCTLD_OPTIONS
;;
*)
;;
esac
start $PROG $OPTVAR
done
}
getpidfile() {
dpidfile=`grep -i ${1}pid $CONFDIR/slurm.conf | grep -v '^ *#'`
if [ $? = 0 ]; then
dpidfile=${dpidfile##*=}
dpidfile=${dpidfile%#*}
else
dpidfile=/var/run/${1}.pid
fi
echo $dpidfile
}
#
# status() with slight modifications to take into account
# instantiations of job manager slurmd's, which should not be
# counted as "running"
#
slurmstatus() {
base=${1##*/}
pidfile=$(getpidfile $base)
pid=`pidof -o $$ -o $$PPID -o %PPID -x $1 || \
pidof -o $$ -o $$PPID -o %PPID -x ${base}`
if [ -f $pidfile ]; then
read rpid < $pidfile
if [ "$rpid" != "" -a "$pid" != "" ]; then
for i in $pid ; do
if [ "$i" = "$rpid" ]; then
echo "${base} (pid $pid) is running..."
return 0
fi
done
elif [ "$rpid" != "" -a "$pid" = "" ]; then
# Due to change in user id, pid file may persist
# after slurmctld terminates
if [ "$base" != "slurmctld" ] ; then
echo "${base} dead but pid file exists"
fi
return 1
fi
fi
if [ "$base" = "slurmctld" -a "$pid" != "" ] ; then
echo "${base} (pid $pid) is running..."
return 0
fi
echo "${base} is stopped"
return 3
}
#
# stop slurm daemons,
# wait for termination to complete (up to 10 seconds) before returning
#
slurmstop() {
for prog in $DAEMONLIST ; do
stop $prog
for i in 1 2 3 4
do
sleep $i
slurmstatus $prog
if [ $? != 0 ]; then
break
fi
done
done
}
#
# The pathname substitution in daemon command assumes prefix and
# exec_prefix are same. This is the default, unless the user requests
# otherwise.
#
# Any node can be a slurm controller and/or server.
#
case "$1" in
start)
startall
;;
startclean)
SLURMCTLD_OPTIONS="-c $SLURMCTLD_OPTIONS"
SLURMD_OPTIONS="-c $SLURMD_OPTIONS"
startall
;;
stop)
slurmstop
;;
status)
for prog in $DAEMONLIST ; do
slurmstatus $prog
done
;;
restart)
$0 stop
$0 start
;;
force-reload)
$0 stop
$0 start
;;
condrestart)
if [ -f /var/lock/subsys/slurm ]; then
for prog in $DAEMONLIST ; do
stop $prog
start $prog
done
fi
;;
reconfig)
for prog in $DAEMONLIST ; do
PIDFILE=$(getpidfile $prog)
start-stop-daemon --stop --signal HUP --pidfile \
"$PIDFILE" --quiet $prog
done
;;
test)
for prog in $DAEMONLIST ; do
echo "$prog runs here"
done
;;
*)
echo "Usage: $0 {start|startclean|stop|status|restart|reconfig|condrestart|test}"
exit 1
;;
esac