~ubuntu-branches/ubuntu/precise/nordugrid-arc/precise

« back to all changes in this revision

Viewing changes to src/services/cache_service/cache-service.in

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2011-10-24 02:19:37 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20111024021937-8whiie90uq2oqsok
Tags: 1.1.0-2
* Backport fixes for endian independent md5 checksum
* Filter out -Wl,-Bsymbolic-functions from default Ubuntu LDFLAGS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Init file for the A-REX cache service
4
 
#
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.
8
 
 
9
 
# chkconfig: 2345 87 13
10
 
# description: ARC cache service
11
 
# processname: arched
12
 
 
13
 
### BEGIN INIT INFO
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
18
 
# Default-Stop:      0 1 6
19
 
# Short-Description: ARC cache service
20
 
# Description:       ARC cache service
21
 
### END INIT INFO
22
 
 
23
 
# source function library
24
 
if [ -f /etc/init.d/functions ]; then
25
 
    . /etc/init.d/functions
26
 
    log_success_msg() {
27
 
        echo -n "$@"
28
 
        success "$@"
29
 
        echo
30
 
    }
31
 
    log_warning_msg() {
32
 
        echo -n "$@"
33
 
        warning "$@"
34
 
        echo
35
 
    }
36
 
    log_failure_msg() {
37
 
        echo -n "$@"
38
 
        failure "$@"
39
 
        echo
40
 
    }
41
 
elif [ -f /lib/lsb/init-functions ]; then
42
 
    . /lib/lsb/init-functions
43
 
else
44
 
    echo "Error: Cannot source neither init.d nor lsb functions"
45
 
    exit 1
46
 
fi
47
 
 
48
 
add_library_path() {
49
 
    location="$1"
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"
57
 
                else
58
 
                    LD_LIBRARY_PATH="$libdir64:$LD_LIBRARY_PATH"
59
 
                fi
60
 
            fi
61
 
            if [ -d "$libdir" ] ; then
62
 
                if [ "x$LD_LIBRARY_PATH" = "x" ]; then
63
 
                    LD_LIBRARY_PATH="$libdir"
64
 
                else
65
 
                    LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
66
 
                fi
67
 
            fi
68
 
        fi
69
 
    fi
70
 
}
71
 
 
72
 
prog=arched
73
 
RUN=yes
74
 
 
75
 
# sysconfig files
76
 
if [ -r /etc/sysconfig/nordugrid ]; then
77
 
    . /etc/sysconfig/nordugrid
78
 
elif [ -r /etc/default/nordugrid ]; then
79
 
    . /etc/default/nordugrid
80
 
fi
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
85
 
fi
86
 
 
87
 
# GLOBUS_LOCATION
88
 
GLOBUS_LOCATION=${GLOBUS_LOCATION:-@DEFAULT_GLOBUS_LOCATION@}
89
 
if [ ! -d "$GLOBUS_LOCATION" ]; then
90
 
    log_failure_msg "GLOBUS_LOCATION ($GLOBUS_LOCATION) not found"
91
 
    exit 1
92
 
fi
93
 
export GLOBUS_LOCATION
94
 
 
95
 
# ARC_LOCATION
96
 
ARC_LOCATION=${ARC_LOCATION:-@prefix@}
97
 
if [ ! -d "$ARC_LOCATION" ]; then
98
 
    log_failure_msg "ARC_LOCATION ($ARC_LOCATION) not found"
99
 
    exit 1
100
 
fi
101
 
export ARC_LOCATION
102
 
 
103
 
readconfigvar() {
104
 
    fname=$1
105
 
    if [ ! -r "$fname" ]; then
106
 
        return
107
 
    fi
108
 
    bname="[$2]"
109
 
    vname=$3
110
 
    value=
111
 
    cat "$fname" | grep -e '^\[' -e "^${vname}=" | {
112
 
        while true; do
113
 
            read line
114
 
            if [ ! $? = 0 ] ; then
115
 
                return
116
 
            fi
117
 
            if [ "$line" = "$bname" ] ; then
118
 
                while true ; do
119
 
                    read line
120
 
                    if [ ! $? = 0 ] ; then
121
 
                        return
122
 
                    fi
123
 
                    lstart=`echo "$line" | head -c 1`
124
 
                    if [ "$lstart" = '[' ] ; then
125
 
                        return
126
 
                    fi
127
 
                    vlname=`echo "$line" | sed 's/=.*//;t;s/.*//'`
128
 
                    if [ "$vlname" = "$vname" ] ; then
129
 
                        val=`echo "$line" | sed 's/[^=]*=//'`
130
 
                        eval "echo $val"
131
 
                        return
132
 
                    fi
133
 
                done
134
 
            fi
135
 
        done
136
 
    }
137
 
}
138
 
 
139
 
# ARC_CONFIG
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
145
 
    fi
146
 
fi
147
 
 
148
 
PID_FILE=
149
 
 
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
154
 
    else
155
 
        LOCKFILE=/var/lock/$prog-cache-service
156
 
    fi
157
 
    if [ "x$PID_FILE" = "x" ]; then
158
 
        PID_FILE=/var/run/$prog-cache-service.pid
159
 
    fi
160
 
else
161
 
    LOCKFILE=$HOME/$prog-cache-service.lock
162
 
    if [ "x$PID_FILE" = "x" ]; then
163
 
        PID_FILE=$HOME/$prog-cache-service.pid
164
 
    fi
165
 
fi
166
 
 
167
 
prepare() {
168
 
 
169
 
    CMD="$ARC_LOCATION/sbin/$prog"
170
 
    if [ ! -x "$CMD" ]; then
171
 
        log_failure_msg "Missing executable"
172
 
        exit 1
173
 
    fi
174
 
 
175
 
    if [ ! -r "$ARC_CONFIG" ]; then
176
 
        log_warning_msg "ARC configuration not found (usually /etc/arc.conf)"
177
 
        exit 0
178
 
    fi
179
 
 
180
 
    # Creating configuration file of arched
181
 
    # Reading following information from config file:
182
 
    #  Debug level
183
 
    #  User name
184
 
    #  Log file is currently hard-coded
185
 
 
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`
198
 
    fi
199
 
    if [ -z "$X509_USER_KEY" ] ; then
200
 
        X509_USER_KEY=`readconfigvar "$ARC_CONFIG" common x509_user_key`
201
 
    fi
202
 
    if [ -z "$X509_CERT_DIR" ] ; then
203
 
        X509_CERT_DIR=`readconfigvar "$ARC_CONFIG" common x509_cert_dir`
204
 
    fi
205
 
    if [ -z "$GRIDMAP" ] ; then
206
 
        GRIDMAP=`readconfigvar "$ARC_CONFIG" common gridmap`
207
 
    fi
208
 
    if [ -z "$GLOBUS_TCP_PORT_RANGE" ] ; then
209
 
        GLOBUS_TCP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" common globus_tcp_port_range`
210
 
    fi
211
 
    if [ -z "$GLOBUS_UDP_PORT_RANGE" ] ; then
212
 
        GLOBUS_UDP_PORT_RANGE=`readconfigvar "$ARC_CONFIG" common globus_udp_port_range`
213
 
    fi
214
 
 
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
222
 
 
223
 
    # Required defaults
224
 
    if [ -z "$GRIDMAP" ] ; then
225
 
        GRIDMAP=/etc/grid-security/grid-mapfile
226
 
    fi
227
 
    if [ -z "$X509_USER_CERT" ] ; then
228
 
        X509_USER_CERT=/etc/grid-security/hostcert.pem
229
 
    fi
230
 
    if [ -z "$X509_USER_KEY" ] ; then
231
 
        X509_USER_KEY=/etc/grid-security/hostkey.pem
232
 
    fi
233
 
    if [ -z "$X509_CERT_DIR" ] ; then
234
 
        X509_CERT_DIR=/etc/grid-security/certificates
235
 
    fi
236
 
 
237
 
    # Web Service configuration
238
 
    host=`readconfigvar "$ARC_CONFIG" common hostname`
239
 
    cache_endpoint=https://$host:60001/cacheservice
240
 
 
241
 
    CACHE_CONFIG=`mktemp -t cache-service.xml.XXXXXX`
242
 
    if [ -z "$CACHE_CONFIG" ] ; then
243
 
        log_failure_msg "Failed to create temporary file"
244
 
        exit 1
245
 
    fi
246
 
 
247
 
    CMD="$CMD -c '$CACHE_CONFIG'"
248
 
 
249
 
    # VOMS_LOCATION
250
 
    VOMS_LOCATION=${VOMS_LOCATION:-@DEFAULT_VOMS_LOCATION@}
251
 
 
252
 
    # GRIDSITE_LOCATION
253
 
    GRIDSITE_LOCATION=${GRIDSITE_LOCATION:-@DEFAULT_GRIDSITE_LOCATION@}
254
 
 
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@
261
 
    else
262
 
        LD_LIBRARY_PATH=$ARC_LOCATION/@libsubdir@:$LD_LIBRARY_PATH
263
 
    fi
264
 
    export LD_LIBRARY_PATH
265
 
 
266
 
    case "$LOGLEVEL" in 
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" ;;
274
 
    esac
275
 
 
276
 
    if [ "$USERNAME" = "root" ] ; then
277
 
        USERNAME=""
278
 
    fi
279
 
 
280
 
    LOGFILE=${LOGFILE:-/var/log/arc/cache-service.log}
281
 
    if [ ! -d `dirname $LOGFILE` ]; then
282
 
        mkdir -p `dirname $LOGFILE`
283
 
    fi
284
 
    LOGSIZE=${LOGSIZE:--1 -1}
285
 
    LOGNUM=`echo "$LOGSIZE" | sed 's/^ *[-+0-9]* *//'`
286
 
    LOGSIZE=`echo "$LOGSIZE" | sed 's/^ *\([-+0-9]*\).*/\1/'`
287
 
 
288
 
    if [ ! -z "$USERNAME" ] ; then
289
 
        CMD="$CMD -u $USERNAME"
290
 
    fi
291
 
 
292
 
    # Cache service XML config
293
 
    CACHECFG="\
294
 
<?xml version=\"1.0\"?>\
295
 
<ArcConfig\
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\">\
299
 
  <Server>\
300
 
    <PidFile>$PID_FILE</PidFile>\
301
 
    <Logger>\
302
 
      <File>$LOGFILE</File>\
303
 
      <Level>$LOGLEVEL</Level>\
304
 
      <Backups>$LOGNUM</Backups>\
305
 
      <Maxsize>$LOGSIZE</Maxsize>\
306
 
    </Logger>\
307
 
  </Server>\
308
 
  <ModuleManager>\
309
 
    <Path>$ARC_LOCATION/@pkglibsubdir@/</Path>\
310
 
  </ModuleManager>\
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>\
318
 
  <Chain>\
319
 
    <Component name=\"tcp.service\" id=\"tcp\">\
320
 
      <next id=\"tls\"/>\
321
 
      <tcp:Listen><tcp:Port>60001</tcp:Port></tcp:Listen>\
322
 
    </Component>\
323
 
    <Component name=\"tls.service\" id=\"tls\">\
324
 
      <next id=\"http\"/>\
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>\
331
 
      </SecHandler>\
332
 
    </Component>\
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>\
337
 
    </Component>\
338
 
    <Component name=\"soap.service\" id=\"soap\">\
339
 
      <next id=\"plexer\"/>\
340
 
    </Component>\
341
 
    <Plexer name=\"plexer.service\" id=\"plexer\">\
342
 
      <next id=\"cacheservice\">^/cacheservice</next>\
343
 
    </Plexer>\
344
 
    <Service name=\"cacheservice\" id=\"cacheservice\">\
345
 
      <!-- Put sec handler in here so that sensible error message can\
346
 
           be returned -->\
347
 
      <SecHandler name=\"arc.authz\" id=\"map\" event=\"incoming\">\
348
 
        <PDP name=\"simplelist.pdp\" location=\"$GRIDMAP\"/>\
349
 
      </SecHandler>\
350
 
      <cacheservice:cache>\
351
 
        <cacheservice:config>$ARC_CONFIG</cacheservice:config>\
352
 
        <cacheservice:maxload>5</cacheservice:maxload>\
353
 
      </cacheservice:cache>\
354
 
    </Service>
355
 
  </Chain>\
356
 
</ArcConfig>\
357
 
"
358
 
 
359
 
    echo "$CACHECFG" > "$CACHE_CONFIG"
360
 
 
361
 
    if [ ! -z "$USERNAME" ] ; then
362
 
        [ -f $CACHE_CONFIG ] && chown $USERNAME $CACHE_CONFIG
363
 
    fi
364
 
}
365
 
 
366
 
start() {
367
 
    if [ "$RUN" != "yes" ] ; then
368
 
        echo "cache-service disabled in configuration"
369
 
        return 0
370
 
    fi
371
 
 
372
 
    echo -n "Starting $prog: "
373
 
 
374
 
    # Check if we are already running
375
 
    if [ -f $PID_FILE ]; then
376
 
        read pid < $PID_FILE
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)"
381
 
                return 0
382
 
            fi
383
 
        fi
384
 
        rm -f "$PID_FILE" "$LOCKFILE"
385
 
    fi
386
 
 
387
 
    prepare
388
 
 
389
 
    eval "$CMD"
390
 
    RETVAL=$?
391
 
    rm -f "$CACHE_CONFIG"
392
 
 
393
 
    if [ $RETVAL -eq 0 ]; then
394
 
        touch $LOCKFILE
395
 
        log_success_msg
396
 
    else
397
 
        log_failure_msg
398
 
    fi
399
 
    return $RETVAL
400
 
}
401
 
 
402
 
stop() {
403
 
    echo -n "Stopping $prog: "
404
 
 
405
 
    if [ -f "$PID_FILE" ]; then
406
 
        read pid < "$PID_FILE"
407
 
        if [ ! -z "$pid" ] ; then
408
 
            kill "$pid"
409
 
            RETVAL=$?
410
 
            if [ $RETVAL -eq 0 ]; then
411
 
                log_success_msg
412
 
            else
413
 
                log_failure_msg
414
 
            fi
415
 
 
416
 
            sleep 1
417
 
            kill -9 "$pid" 1>/dev/null 2>&1
418
 
            rm -f "$PID_FILE" "$LOCKFILE"
419
 
        else
420
 
            RETVAL=1
421
 
            log_failure_msg "$prog shutdown - pidfile is empty"
422
 
        fi
423
 
    else
424
 
        RETVAL=0
425
 
        log_success_msg "$prog shutdown - already stopped"
426
 
    fi
427
 
    return $RETVAL
428
 
}
429
 
 
430
 
status() {
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..."
436
 
                return 0
437
 
            fi
438
 
            echo "$1 stopped but pid file exists"
439
 
            return 1
440
 
        fi
441
 
    fi
442
 
    if [ -f $LOCKFILE ]; then
443
 
        echo "$1 stopped but lockfile exist"
444
 
        return 2
445
 
    fi
446
 
    echo "$1 is stopped"
447
 
    return 3
448
 
}
449
 
 
450
 
restart() {
451
 
    stop
452
 
    start
453
 
}
454
 
 
455
 
case "$1" in
456
 
    start)
457
 
        start
458
 
        ;;
459
 
    stop)
460
 
        stop
461
 
        ;;
462
 
    status)
463
 
        status
464
 
        ;;
465
 
    restart | force-reload)
466
 
        restart
467
 
        ;;
468
 
    reload)
469
 
        ;;
470
 
    condrestart | try-restart)
471
 
        [ -f $LOCKFILE ] && restart || :
472
 
        ;;
473
 
    *)
474
 
        echo "Usage: $0 {start|stop|status|restart|force-reload|reload|condrestart|try-restart}"
475
 
        exit 1
476
 
        ;;
477
 
esac
478
 
 
479
 
exit $?