-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbs.init
executable file
·207 lines (190 loc) · 4.24 KB
/
sbs.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
#! /bin/sh
### BEGIN INIT INFO
# Provides: sbs
# Required-Start: $syslog $time $remote_fs
# Required-Stop: $syslog $time $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple batch system
# Description: Debian init for the simple batch system
### END INIT INFO
#
# sbs.init: The simple batch system daemons
#
# chkconfig: 2345 97 03
# description: Simple batch system daemons
#
# processname: sbsd
# xpidfile: /var/run/sbsd-*.pid
#
#set -x
PROG=/usr/sbin/sbsd
NAME=sbs
CONFIG_PATH=/etc/sbs
PID_FILE_BASE=/var/run/sbsd-
# Sanity checks.
[ -x $PROG ] || exit 0
#CMD=echo
RETVAL=0
# $1 qeue name $2 additional parms. creates the queue if required
start_one()
{
$CMD $PROG -c -q $1
$CMD $PROG -q $1 $2
echo "starting $PROG for queue $1"
}
# $1 queue name
stop_one()
{
if [ -f $PID_FILE_BASE$1.pid ] ; then
$CMD kill -TERM `cat $PID_FILE_BASE$1.pid`
else
echo "sbsd for queue $1 is probably not running"
fi
}
# $1 queue name
status_one()
{
if [ -f $PID_FILE_BASE$1.pid ] ; then
$CMD kill -0 `cat $PID_FILE_BASE$1.pid`
if [ $? -eq 0 ] ; then
echo "sbsd for queue $1 is running"
else
echo "sbsd for queue $1 is not running"
fi
else
echo "sbsd for queue $1 is not running"
fi
}
# $1 name of a configuration.
start1()
{
if [ -f $CONFIG_PATH/$1.conf ] ; then
QUEUE=''
NICE=''
WORKERS=''
ACTVE=''
TIMEOUT=''
. $CONFIG_PATH/$1.conf
if [ -n $QUEUE ] ; then
SBS_ARGS=''
if [ -n "$NICE" ] ; then
SBS_ARGS="$SBS_ARGS -n $NICE"
fi
if [ -n "$WORKERS" ] ; then
SBS_ARGS="$SBS_ARGS -w $WORKERS"
fi
if [ -n "$ACTIVE" ] ; then
SBS_ARGS="$SBS_ARGS -a $ACTIVE"
fi
if [ -n "$TIMEOUT" ] ; then
SBS_ARGS="$SBS_ARGS -t $TIMEOUT"
fi
if [ -n "$LOAD" ] ; then
SBS_ARGS="$SBS_ARGS -l $LOAD"
fi
start_one $QUEUE "$SBS_ARGS"
else
echo "Sorry no QUEUE defined in $CONFIG_PATH/$1.conf"
fi
else
echo "Sorry, $CONFIG_PATH/$1.conf does not exist"
fi
}
# $1 name of a configuration.
start()
{
if [ -z "$1" ] ; then
echo "starting the simple batch system"
for i in $CONFIG_PATH/*.conf ; do
start1 `basename $i .conf`
done
echo "done."
else
start1 $1
fi
}
# $1 name of a configuration
stop1()
{
if [ -f $CONFIG_PATH/$1.conf ] ; then
QUEUE=''
. $CONFIG_PATH/$1.conf
if [ -n $QUEUE ] ; then
stop_one $QUEUE
else
echo "Sorry no QUEUE defined in $CONFIG_PATH/$1.conf"
fi
else
echo "Sorry, $CONFIG_PATH/$1.conf does not exist"
fi
}
# $1 name of a configuration or nothing
stop()
{
if [ -z "$1" ] ; then
echo "stopping the simple batch system"
for i in $CONFIG_PATH/*.conf ; do
stop1 `basename $i .conf`
done
echo "done."
else
stop1 $1
fi
}
# $1 name of a configuration
status1()
{
if [ -f $CONFIG_PATH/$1.conf ] ; then
QUEUE=''
. $CONFIG_PATH/$1.conf
if [ -n $QUEUE ] ; then
status_one $QUEUE
else
echo "Sorry no QUEUE defined in $CONFIG_PATH/$1.conf"
fi
else
echo "Sorry, $CONFIG_PATH/$1.conf does not exist"
fi
}
status()
{
if [ -z "$1" ] ; then
echo "checking the simple batch system"
for i in $CONFIG_PATH/*.conf ; do
status1 `basename $i .conf`
done
echo "done."
fi
}
restart()
{
stop $1
start $1
}
main()
{
if [ ! -d $CONFIG_PATH/ ] ; then
echo "Configuration path \"$CONFIG_PATH\" does not exist"
exit 0
fi
case "$1" in
start)
start $2
;;
stop)
stop $2
;;
status)
status $2
;;
reload|restart)
restart $2
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
}
main $1 $2
exit $RETVAL