3
# Init file for the A-REX cache service
5
# This startup script takes ARC0 configuration file as
6
# its input and generates ARC1 arched configuration file
7
# which contains commands to start A-REX cache service.
9
# chkconfig: 2345 87 13
10
# description: ARC cache service
14
# Provides: cache-service
15
# Required-Start: $local_fs $remote_fs
16
# Required-Stop: $local_fs $remote_fs
17
# Default-Start: 2 3 4 5
19
# Short-Description: ARC cache service
20
# Description: ARC cache service
23
# source function library
24
if [ -f /etc/init.d/functions ]; then
25
. /etc/init.d/functions
41
elif [ -f /lib/lsb/init-functions ]; then
42
. /lib/lsb/init-functions
44
echo "Error: Cannot source neither init.d nor lsb functions"
50
if [ ! "x$location" = "x" ] ; then
51
if [ ! "$location" = "/usr" ] ; then
52
libdir="$location/lib"
53
libdir64="$location/lib64"
54
if [ -d "$libdir64" ] ; then
55
if [ "x$LD_LIBRARY_PATH" = "x" ]; then
56
LD_LIBRARY_PATH="$libdir64"
58
LD_LIBRARY_PATH="$libdir64:$LD_LIBRARY_PATH"
61
if [ -d "$libdir" ] ; then
62
if [ "x$LD_LIBRARY_PATH" = "x" ]; then
63
LD_LIBRARY_PATH="$libdir"
65
LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
76
if [ -r /etc/sysconfig/nordugrid ]; then
77
. /etc/sysconfig/nordugrid
78
elif [ -r /etc/default/nordugrid ]; then
79
. /etc/default/nordugrid
81
if [ -r /etc/sysconfig/cache-service ]; then
82
. /etc/sysconfig/cache-service
83
elif [ -r /etc/default/cache-service ]; then
84
. /etc/default/cache-service
88
GLOBUS_LOCATION=${GLOBUS_LOCATION:-@DEFAULT_GLOBUS_LOCATION@}
89
if [ ! -d "$GLOBUS_LOCATION" ]; then
90
log_failure_msg "GLOBUS_LOCATION ($GLOBUS_LOCATION) not found"
93
export GLOBUS_LOCATION
96
ARC_LOCATION=${ARC_LOCATION:-@prefix@}
97
if [ ! -d "$ARC_LOCATION" ]; then
98
log_failure_msg "ARC_LOCATION ($ARC_LOCATION) not found"
105
if [ ! -r "$fname" ]; then
111
cat "$fname" | grep -e '^\[' -e "^${vname}=" | {
114
if [ ! $? = 0 ] ; then
117
if [ "$line" = "$bname" ] ; then
120
if [ ! $? = 0 ] ; then
123
lstart=`echo "$line" | head -c 1`
124
if [ "$lstart" = '[' ] ; then
127
vlname=`echo "$line" | sed 's/=.*//;t;s/.*//'`
128
if [ "$vlname" = "$vname" ] ; then
129
val=`echo "$line" | sed 's/[^=]*=//'`
140
if [ "x$ARC_CONFIG" = "x" ]; then
141
if [ -r $ARC_LOCATION/etc/arc.conf ]; then
142
ARC_CONFIG=$ARC_LOCATION/etc/arc.conf
143
elif [ -r /etc/arc.conf ]; then
144
ARC_CONFIG=/etc/arc.conf
150
if [ `id -u` = 0 ] ; then
151
# Debian does not have /var/lock/subsys
152
if [ -d /var/lock/subsys ]; then
153
LOCKFILE=/var/lock/subsys/$prog-cache-service
155
LOCKFILE=/var/lock/$prog-cache-service
157
if [ "x$PID_FILE" = "x" ]; then
158
PID_FILE=/var/run/$prog-cache-service.pid
161
LOCKFILE=$HOME/$prog-cache-service.lock
162
if [ "x$PID_FILE" = "x" ]; then
163
PID_FILE=$HOME/$prog-cache-service.pid
169
CMD="$ARC_LOCATION/sbin/$prog"
170
if [ ! -x "$CMD" ]; then
171
log_failure_msg "Missing executable"
175
if [ ! -r "$ARC_CONFIG" ]; then
176
log_warning_msg "ARC configuration not found (usually /etc/arc.conf)"
180
# Creating configuration file of arched
181
# Reading following information from config file:
184
# Log file is currently hard-coded
186
#LOGFILE=`readconfigvar "$ARC_CONFIG" grid-manager logfile`
187
LOGLEVEL=`readconfigvar "$ARC_CONFIG" grid-manager debug`
188
LOGSIZE=`readconfigvar "$ARC_CONFIG" grid-manager logsize`
189
USERNAME=`readconfigvar "$ARC_CONFIG" grid-manager user`
190
X509_USER_CERT=`readconfigvar "$ARC_CONFIG" grid-manager x509_user_cert`
191
X509_USER_KEY=`readconfigvar "$ARC_CONFIG" grid-manager x509_user_key`
192
X509_CERT_DIR=`readconfigvar "$ARC_CONFIG" grid-manager x509_cert_dir`
193
GRIDMAP=`readconfigvar "$ARC_CONFIG" grid-manager gridmap`
194
GLOBUS_TCP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" grid-manager globus_tcp_port_range`
195
GLOBUS_UDP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" grid-manager globus_udp_port_range`
196
if [ -z "$X509_USER_CERT" ] ; then
197
X509_USER_CERT=`readconfigvar "$ARC_CONFIG" common x509_user_cert`
199
if [ -z "$X509_USER_KEY" ] ; then
200
X509_USER_KEY=`readconfigvar "$ARC_CONFIG" common x509_user_key`
202
if [ -z "$X509_CERT_DIR" ] ; then
203
X509_CERT_DIR=`readconfigvar "$ARC_CONFIG" common x509_cert_dir`
205
if [ -z "$GRIDMAP" ] ; then
206
GRIDMAP=`readconfigvar "$ARC_CONFIG" common gridmap`
208
if [ -z "$GLOBUS_TCP_PORT_RANGE" ] ; then
209
GLOBUS_TCP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" common globus_tcp_port_range`
211
if [ -z "$GLOBUS_UDP_PORT_RANGE" ] ; then
212
GLOBUS_UDP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" common globus_udp_port_range`
215
# Exporting collected variables
216
if [ ! -z "$X509_USER_CERT" ] ; then export X509_USER_CERT ; fi
217
if [ ! -z "$X509_USER_KEY" ] ; then export X509_USER_KEY ; fi
218
if [ ! -z "$X509_CERT_DIR" ] ; then export X509_CERT_DIR ; fi
219
if [ ! -z "$GRIDMAP" ] ; then export GRIDMAP ; fi
220
if [ ! -z "$GLOBUS_TCP_PORT_RANGE" ] ; then export GLOBUS_TCP_PORT_RANGE ; fi
221
if [ ! -z "$GLOBUS_UDP_PORT_RANGE" ] ; then export GLOBUS_UDP_PORT_RANGE ; fi
224
if [ -z "$GRIDMAP" ] ; then
225
GRIDMAP=/etc/grid-security/grid-mapfile
227
if [ -z "$X509_USER_CERT" ] ; then
228
X509_USER_CERT=/etc/grid-security/hostcert.pem
230
if [ -z "$X509_USER_KEY" ] ; then
231
X509_USER_KEY=/etc/grid-security/hostkey.pem
233
if [ -z "$X509_CERT_DIR" ] ; then
234
X509_CERT_DIR=/etc/grid-security/certificates
237
# Web Service configuration
238
host=`readconfigvar "$ARC_CONFIG" common hostname`
239
cache_endpoint=https://$host:60001/cacheservice
241
CACHE_CONFIG=`mktemp -t cache-service.xml.XXXXXX`
242
if [ -z "$CACHE_CONFIG" ] ; then
243
log_failure_msg "Failed to create temporary file"
247
CMD="$CMD -c '$CACHE_CONFIG'"
250
VOMS_LOCATION=${VOMS_LOCATION:-@DEFAULT_VOMS_LOCATION@}
253
GRIDSITE_LOCATION=${GRIDSITE_LOCATION:-@DEFAULT_GRIDSITE_LOCATION@}
255
add_library_path "$LFC_LOCATION"
256
add_library_path "$GRIDSITE_LOCATION"
257
add_library_path "$VOMS_LOCATION"
258
add_library_path "$GLOBUS_LOCATION"
259
if [ "x$LD_LIBRARY_PATH" = "x" ]; then
260
LD_LIBRARY_PATH=$ARC_LOCATION/@libsubdir@
262
LD_LIBRARY_PATH=$ARC_LOCATION/@libsubdir@:$LD_LIBRARY_PATH
264
export LD_LIBRARY_PATH
267
0) LOGLEVEL="FATAL" ;;
268
1) LOGLEVEL="ERROR" ;;
269
2) LOGLEVEL="WARNING" ;;
270
3) LOGLEVEL="INFO" ;;
271
4) LOGLEVEL="VERBOSE" ;;
272
5) LOGLEVEL="DEBUG" ;;
273
*) LOGLEVEL="WARNING" ;;
276
if [ "$USERNAME" = "root" ] ; then
280
LOGFILE=${LOGFILE:-/var/log/arc/cache-service.log}
281
if [ ! -d `dirname $LOGFILE` ]; then
282
mkdir -p `dirname $LOGFILE`
284
LOGSIZE=${LOGSIZE:--1 -1}
285
LOGNUM=`echo "$LOGSIZE" | sed 's/^ *[-+0-9]* *//'`
286
LOGSIZE=`echo "$LOGSIZE" | sed 's/^ *\([-+0-9]*\).*/\1/'`
288
if [ ! -z "$USERNAME" ] ; then
289
CMD="$CMD -u $USERNAME"
292
# Cache service XML config
294
<?xml version=\"1.0\"?>\
296
xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\
297
xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\"
298
xmlns:cacheservice=\"urn:cacheservice_config\">\
300
<PidFile>$PID_FILE</PidFile>\
302
<File>$LOGFILE</File>\
303
<Level>$LOGLEVEL</Level>\
304
<Backups>$LOGNUM</Backups>\
305
<Maxsize>$LOGSIZE</Maxsize>\
309
<Path>$ARC_LOCATION/@pkglibsubdir@/</Path>\
311
<Plugins><Name>mcctcp</Name></Plugins>\
312
<Plugins><Name>mcctls</Name></Plugins>\
313
<Plugins><Name>mcchttp</Name></Plugins>\
314
<Plugins><Name>mccsoap</Name></Plugins>\
315
<Plugins><Name>identitymap</Name></Plugins>\
316
<Plugins><Name>arcshc</Name></Plugins>\
317
<Plugins><Name>cacheservice</Name></Plugins>\
319
<Component name=\"tcp.service\" id=\"tcp\">\
321
<tcp:Listen><tcp:Port>60001</tcp:Port></tcp:Listen>\
323
<Component name=\"tls.service\" id=\"tls\">\
325
<KeyPath>$X509_USER_KEY</KeyPath>\
326
<CertificatePath>$X509_USER_CERT</CertificatePath>\
327
<CACertificatesDir>$X509_CERT_DIR</CACertificatesDir>\
328
<SecHandler name=\"identity.map\" id=\"map\" event=\"incoming\">\
329
<PDP name=\"allow.pdp\"><LocalList>$GRIDMAP</LocalList></PDP>\
330
<PDP name=\"allow.pdp\"><LocalName>nobody</LocalName></PDP>\
333
<Component name=\"http.service\" id=\"http\">\
334
<next id=\"soap\">POST</next>\
335
<next id=\"plexer\">GET</next>\
336
<next id=\"plexer\">PUT</next>\
338
<Component name=\"soap.service\" id=\"soap\">\
339
<next id=\"plexer\"/>\
341
<Plexer name=\"plexer.service\" id=\"plexer\">\
342
<next id=\"cacheservice\">^/cacheservice</next>\
344
<Service name=\"cacheservice\" id=\"cacheservice\">\
345
<!-- Put sec handler in here so that sensible error message can\
347
<SecHandler name=\"arc.authz\" id=\"map\" event=\"incoming\">\
348
<PDP name=\"simplelist.pdp\" location=\"$GRIDMAP\"/>\
350
<cacheservice:cache>\
351
<cacheservice:config>$ARC_CONFIG</cacheservice:config>\
352
<cacheservice:maxload>5</cacheservice:maxload>\
353
</cacheservice:cache>\
359
echo "$CACHECFG" > "$CACHE_CONFIG"
361
if [ ! -z "$USERNAME" ] ; then
362
[ -f $CACHE_CONFIG ] && chown $USERNAME $CACHE_CONFIG
367
if [ "$RUN" != "yes" ] ; then
368
echo "cache-service disabled in configuration"
372
echo -n "Starting $prog: "
374
# Check if we are already running
375
if [ -f $PID_FILE ]; then
377
if [ "x$pid" != "x" ]; then
378
ps -p "$pid" -o comm 2>/dev/null | grep "^$prog$" 1>/dev/null 2>/dev/null
379
if [ $? -eq 0 ] ; then
380
log_success_msg "already running (pid $pid)"
384
rm -f "$PID_FILE" "$LOCKFILE"
391
rm -f "$CACHE_CONFIG"
393
if [ $RETVAL -eq 0 ]; then
403
echo -n "Stopping $prog: "
405
if [ -f "$PID_FILE" ]; then
406
read pid < "$PID_FILE"
407
if [ ! -z "$pid" ] ; then
410
if [ $RETVAL -eq 0 ]; then
417
kill -9 "$pid" 1>/dev/null 2>&1
418
rm -f "$PID_FILE" "$LOCKFILE"
421
log_failure_msg "$prog shutdown - pidfile is empty"
425
log_success_msg "$prog shutdown - already stopped"
431
if [ -f "$PID_FILE" ]; then
432
read pid < "$PID_FILE"
433
if [ "$pid" != "" ]; then
434
if ps -p "$pid" > /dev/null; then
435
echo "$1 (pid $pid) is running..."
438
echo "$1 stopped but pid file exists"
442
if [ -f $LOCKFILE ]; then
443
echo "$1 stopped but lockfile exist"
465
restart | force-reload)
470
condrestart | try-restart)
471
[ -f $LOCKFILE ] && restart || :
474
echo "Usage: $0 {start|stop|status|restart|force-reload|reload|condrestart|try-restart}"