updated on Fri Jan 20 04:00:45 UTC 2012
[aur-mirror.git] / slurm-llnl / arch_rc.d.slurm
blob9ffb969e308ab112199d5072805f48b90f839aa2
1 #!/bin/bash
3 # description: SLURM is a simple resource management system which \
4 # manages exclusive access to a set of compute \
5 # resources and distributes work to those resources.
7 # processname: /usr/sbin/slurmd
8 # pidfile: /run/slurmd.pid
10 # processname: /usr/sbin/slurmctld
11 # pidfile: /run/slurmctld.pid
13 # config: /etc/default/slurm
16 BINDIR=/usr/bin
17 CONFDIR=/etc/slurm
18 LIBDIR=/usr/lib
19 SBINDIR=/usr/sbin
21 # Source main config
22 if [ ! -f /etc/rc.conf ]; then
23 echo "Could not find /etc/rc.conf. Are we using ARCH linux?"
24 exit 1
26 . /etc/rc.conf
28 # Source function library.
29 if [ ! -f /etc/rc.d/functions ]; then
30 echo "Could not find /etc/rc.d/functions. Is some other daemon launch mechanism used?"
31 exit 1
33 . /etc/rc.d/functions
35 STARTPROC=daemon
37 function rc_status() {
38 RETVAL=$?
40 function rc_exit () {
41 exit $RETVAL
43 RETVAL=0
46 if [ ! -x $BINDIR/scontrol ]; then
47 echo "Could not find $BINDIR/scontrol. Bad path?"
48 exit 1
51 # Source slurm specific configuration
52 # SLURMCTLD_OPTIONS defines slurmctld command line options. See "man slurmctld"
53 # SLURMD_OPTIONS defines slurmd command line options. See "man slurmd"
54 if [ -f /etc/default/slurm ] ; then
55 . /etc/default/slurm
56 else
57 SLURMCTLD_OPTIONS=""
58 SLURMD_OPTIONS=""
61 if [ ! -f $CONFDIR/slurm.conf ]; then
62 echo "Could not find $CONFDIR/slurm.conf. Bad path?"
63 exit 1
66 # setup library paths for slurm and munge support
67 export LD_LIBRARY_PATH=$LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
69 start() {
70 prog=$1
71 shift
72 stat_busy "Starting $prog"
73 unset HOME MAIL USER USERNAME
74 $SBINDIR/$prog $*
75 if [ $? -gt 0 ]; then
76 stat_fail
77 else
78 add_daemon $prog
79 stat_done
83 stop() {
84 stat_busy "Stopping $prog"
85 PID=`pidof -o %PPID $prog`
86 [ "$PID" ] && kill $PID &> /dev/null
87 if [ $? -gt 0 ]; then
88 stat_fail
89 else
90 rm_daemon $prog
91 stat_done
95 startall() {
96 for prog in `$BINDIR/scontrol show daemons`; do
97 optvar=`echo ${prog}_OPTIONS | tr "a-z" "A-Z"`
98 start $prog ${!optvar}
99 done
103 # status() with slight modifications to take into account
104 # instantiations of job manager slurmd's, which should not be
105 # counted as "running"
107 slurmstatus() {
108 local base=${1##*/}
109 local pid
110 local rpid
111 local pidfile
113 pidfile=`grep -i ${base}pid $CONFDIR/slurm.conf | grep -v '^ *#'`
114 if [ $? = 0 ]; then
115 pidfile=${pidfile##*=}
116 pidfile=${pidfile%#*}
117 else
118 pidfile=/run/${base}.pid
121 pid=`pidof -o $$ -o $$PPID -o %PPID -x $1 || \
122 pidof -o $$ -o $$PPID -o %PPID -x ${base}`
124 if [ -f $pidfile ]; then
125 read rpid < $pidfile
126 if [ "$rpid" != "" -a "$pid" != "" ]; then
127 for i in $pid ; do
128 if [ "$i" = "$rpid" ]; then
129 echo $"${base} (pid $pid) is running..."
130 return 0
132 done
133 elif [ "$rpid" != "" -a "$pid" = "" ]; then
134 # Due to change in user id, pid file may persist
135 # after slurmctld terminates
136 if [ "$base" != "slurmctld" ] ; then
137 echo $"${base} dead but pid file exists"
138 else
139 echo $"${base} is stopped"
141 return 1
146 if [ "$base" = "slurmctld" -a "$pid" != "" ] ; then
147 echo $"${base} (pid $pid) is running..."
148 return 0
151 echo $"${base} is stopped"
153 return 3
157 # stop slurm daemons,
158 # wait for termination to complete (up to 10 seconds) before returning
160 slurmstop() {
161 for prog in `$BINDIR/scontrol show daemons`; do
162 stop $prog
164 for i in 1 2 3 4
166 sleep $i
167 slurmstatus $prog
168 if [ $? != 0 ]; then
169 break
171 done
172 done
176 # The pathname substitution in daemon command assumes prefix and
177 # exec_prefix are same. This is the default, unless the user requests
178 # otherwise.
180 # Any node can be a slurm controller and/or server.
182 case "$1" in
183 start)
184 startall
186 startclean)
187 SLURMCTLD_OPTIONS="-c $SLURMCTLD_OPTIONS"
188 SLURMD_OPTIONS="-c $SLURMD_OPTIONS"
189 startall
191 stop)
192 slurmstop
194 status)
195 for prog in `$BINDIR/scontrol show daemons`; do
196 slurmstatus $prog
197 done
199 restart)
200 $0 stop
201 $0 start
203 condrestart)
204 if [ -f /var/lock/subsys/slurm ]; then
205 for prog in `$BINDIR/scontrol show daemons`; do
206 stop $prog
207 start $prog
208 done
211 reconfig)
212 for prog in `$BINDIR/scontrol show daemons`; do
213 killproc $prog -HUP
214 done
216 test)
217 for prog in `$BINDIR/scontrol show daemons`; do
218 echo "$prog runs here"
219 done
222 echo "Usage: $0 {start|startclean|stop|status|restart|reconfig|condrestart|test}"
223 exit 1
225 esac
227 rc_exit