cobalt.init.cray 4.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
#
# Cobalt
#
# chkconfig: 2345 18 09
# description: Cobalt resource manager/scheduler
# modified for use on Cray systems

prefix=/usr
exec_prefix=/usr/bin
CONFIGPATH=/etc
CONFIGFILE="${CONFIGPATH}/cobalt.conf"
DAEMONDIR=/usr/sbin
PIDPATH=/var/run/
HOSTNAME=`hostname`

# Configure DB2 environment
# . /discovery/db.src

umask 022

COMPONENT_LIST="slp system_script_forker alps_script_forker cqm bgsched alpssystem"
Paul Rich's avatar
Paul Rich committed
23
if [ -e '/etc/sysconfig/cobalt' ]
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
then
  source /etc/sysconfig/cobalt
fi


# ANL Local:
#MPIRUN_VERBOSE=1
#export MPIRUN_VERBOSE
#LD_LIBRARY_PATH=/bgsys/drivers/ppcfloor/lib64:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH

# Starts the component specified as the first argument.
# Optional second argument used for extra arguments to 
# pass to the component.
start_component () {
    component=$1
    if [ -n $2 ] ; then
	component_args=$2
    else
	component_args=''
    fi

    pid=`pgrep -f ${component}.py`
    echo -n "Starting ${component}: "
    if [ -z "$pid" ]
    then
        (
         date=`/bin/date`
Paul Rich's avatar
Paul Rich committed
52
53
         echo "--- $date: START ${component} ---" >>/var/log/cobalt/${component}_${HOSTNAME}.out
         nohup "${DAEMONDIR}/${component}.py" $component_args --config-files "${CONFIGFILE}" >>/var/log/cobalt/${component}_${HOSTNAME}.out 2>&1 &
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
        )
        echo "done"
        return 0
    else
        echo "failed -- $component already running (pid $pid)"
        return 1
    fi
}

# Stops the component specified as the first argument.
stop_component () {
    component=$1
#   if [ -f "${PIDPATH}/${component}.pid" ] ; then
       echo -n "Stopping ${component}: "
#       kill -INT `cat ${PIDPATH}/${component}.pid`
	pkill -f ${DAEMONDIR}/${component}.py
        echo "done"
#       rm -f "${PIDPATH}/${component}.pid"
#   else
#       echo "${component} not running"
#   fi
    return 0
}

stat_component () {
    component=$1
    pid=`pgrep -f ${component}.py`
    echo -n "Component: $component: "
    if [ -z "$pid" ]
    then
      echo STOPPED
      return 3
    else
      echo RUNNING
      return 0
    fi
    return 0
}

case "$1" in
  start)
    # ANL Localization: No scriptm on surveyor
    if [ -e /var/lock/subsys/cobalt ]
    then
      echo Cobalt already started
      exit 0
    fi
    for component in $COMPONENT_LIST; do
        #if [ "$component" == "bgqsystem" ] ; then
        #        source ~bgqsysdb/sqllib/db2profile
        #else
        #        source ~db2cat/sqllib/db2profile
        #fi
	start_component $component
    done
    touch /var/lock/subsys/cobalt
    ;;
  start-component )
    for component in $*
    do
      if [ $component != "start-component" ]
      then
        start_component $component
      fi
    done
    touch /var/lock/subsys/cobalt
    ;;
  stop-component )
    for component in $*
    do
      if [ $component != "stop-component" ]
      then
        stop_component $component
      fi
    done
    ;;
  start-debug)
    # ANL Localization: No scriptm on surveyor
    # for component in slp brooklyn cqm bgsched bgforker bgsystem scriptm cdbwriter; do
    for component in $COMPONENT_LIST; do
	start_component $component
    done
    touch /var/lock/subsys/cobalt
    ;;
  stop)
    # ANL Localization: No scriptm on surveyor
    # for component in slp cqm bgsched bgforker bgsystem scriptm cdbwriter; do
    for component in $COMPONENT_LIST; do
	stop_component $component
    done
    rm -f /var/lock/subsys/cobalt
    ;;
  stop-debug) 
    # ANL Localization: No scriptm on surveyor
    # for component in slp brooklyn cqm bgsched bgforker bgsystem scriptm cdbwriter; do
    for component in $COMPONENT_LIST; do
	stop_component $component
    done
    rm -f /var/lock/subsys/cobalt
    ;;
  restart)
    if [ $# -gt 1 ] ; then  #specific components to be restarted
	shift
	for component in $@; do 
	    case "$component" in 
	      cqm|bgsched|alpssystem)
		stop_component $component
		start_component $component
		;;
	      slp|bg_runjob_forker|user_script_forker|system_script_forker|alps_script_forker)
		echo "${component} cannot be restarted with jobs running"
		;;
	    esac
	done
    else  #restart all components
	$0 stop
	$0 start
    fi
    ;;
  status)
    count=0
    running=0
    failed=0
    for component in $COMPONENT_LIST; do
        count=$(($count + 1))
        stat_component $component
        if [ 0 -ne $? ]
        then
            failed=$(($failed + 1))
        else
            running=$(($running + 1))
        fi
    done
    if [ $running -eq $count ]
    then
        echo All Components Running
        exit 0
    elif [ $failed -eq $count ]
    then 
        echo All Components Stopped
        exit 3
    else
        exit 4
    fi
    ;;
  force-reload)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|force-reload|start-component <component>|stop-component <component>}"
    echo "Default daemons are: $COMPONENT_LIST"
    exit 1
esac

exit 0