File: globus-personal-gatekeeper.in

package info (click to toggle)
globus-gram-job-manager 14.35-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,800 kB
  • ctags: 1,868
  • sloc: ansic: 32,225; sh: 12,188; perl: 1,502; makefile: 643; yacc: 536; lex: 215
file content (640 lines) | stat: -rwxr-xr-x 15,746 bytes parent folder | download
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
#!/bin/sh

# 
# Copyright 1999-2006 University of Chicago
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 


PACKAGE=@PACKAGE@
VERSION=@VERSION@
DIRT_TIMESTAMP=1028570784
DIRT_BRANCH_ID=23

prefix="${GLOBUS_LOCATION-@prefix@}"
exec_prefix="@exec_prefix@"
sbindir="@sbindir@"
bindir="@bindir@"
libdir="@libdir@"
includedir="@includedir@"
datarootdir="@datarootdir@"
datadir="@datadir@"
libexecdir="@libexecdir@"
sysconfdir="@sysconfdir@"
sharedstatedir="@sharedstatedir@"
localstatedir="@localstatedir@"

PATH=${sbindir}:${bindir}:${PATH}

short_usage="globus-personal-gatekeeper [-help] [-start] [-list] [-killall] ..."

long_usage ()
{
    cat >&2 <<EOF

Syntax: globus-personal-gatekeeper [options]

    [options]
    -help
    -usage
    Displays usage

    -version
    Displays version

    -debug
    Displays extra output

    -start [-jmtype <type>] [-auditdir <dir>] [-port <port>] [-log[=DIRECTORY]] [-seg] [-acctfile file]
    Starts a new gatekeeper, mapping default service to a
    jobmanager. By default, the jobmanager is configured with
    jmtype=fork. The option -port can be used to restrict the
    gatekeeper to use a particular port. The default is to let the
    system choose a port. The -log switch causes the job manager
    to write log messages to files in DIRECTORY.
    If -seg is used, then the Scheduler Event Generator will be used to
    poll job state. The -auditdir switch tells the jobmanager where
    to store the audit-records. The -acctfile switch tells the gatekeeper
    where to log accounting records.

    -list
    Scans for active personal gatekeepers. If found, an
    authentication test is made to determine if the gatekeeper is
    still functioning.  If the authentictation test succeeds, the
    contact to that gatekeeper is printed out.

    -directory <contact>
    Returns the temporary directory used by the personal
    gatekeeper associated with <contact>. The directory contains
    grid-mapfile, log file, etc.

    -kill <contact>
    Finds and kills the personal gatekeeper associated with
    <contact>.

    -killall
    Finds all personal gatekeepers running on the local host and
    kills them.

EOF
}


globus_args_short_usage()
{
    cat 1>&2 <<EOF

Syntax : ${short_usage}

Use -help to display full usage.

EOF
}

globus_args_option_error()
{
    cat 1>&2 <<EOF

ERROR: option $1 : $2
EOF
    globus_args_short_usage
    exit 1
}

globus_args_unrecognized_option()
{
    globus_args_option_error $1 "unrecognized option"
    exit 1
}

debug=:

verify_setup ()
{
    hours=""
    ${debug} "verifying setup..."

    if test "$1" != 'kill'; then
        hours="-hours 1"
    fi
    #grid-proxy-info -exists $hours
    #
    #if [ $? -ne 0 ]; then
    #    echo "ERROR: no valid proxy, or lifetime to small (one hour)" >&2
    #    exit 1
    #fi

    ${debug} "done."
}


get_jm_arg_value()
{
    desired="$1"
    shift

    while [ "$#" -gt 0 ]; do
        if [ "$1" = "$desired" ]; then
            echo "$2"
            break
        fi
        shift;
    done
}

killem ()
{
    found=false
    foundit=false

    user=${LOGNAME}
    user=${user:-$USER}
    user=${user:-`whoami`}
    for dir in `ls -1d ${file_location}/${file_prefix}* 2> /dev/null`
    do
        if [ -n "${dir}" ]; then
            found=true
            contact=
            if [ -r ${dir}/gatekeeper.log ]; then
                contact="`grep 'GRAM contact' ${dir}/gatekeeper.log |
                    tail -1 |
                    sed 's/^.*GRAM contact: //'`"
                ${debug} "found contact= [${contact}]"
            fi

            dokill=false
            if [ -z "$1" ]; then
                dokill=true
            else
                if [ "$1" = "$contact" ]; then
                    dokill=true
                    foundit=true
                fi
            fi

            if [ $dokill = true ]; then

                echo "killing gatekeeper: \"${contact}\""
                if [ -r ${dir}/gatekeeper.pid ]; then
                    pid=`cat ${dir}/gatekeeper.pid`
                    kill -9 $pid &
                fi
                cd
                statedir="${TMPDIR:-/tmp}/${user}/`echo \"${dir}\" | sed -e 's|.*/||'`"
                if [ -r ${dir}/jobmanager.conf ]; then
                    host=`globus_hostname`
                    args=`cat "${dir}/jobmanager.conf"`
                    service_tag="`eval get_jm_arg_value -service-tag $args`"
                    if [ "$service_tag" = "" ]; then
                        service_tag=untagged
                    fi
                    lrm="`eval get_jm_arg_value -type $args`"
                    tagged="$HOME/.globus/job/$host/$lrm.$service_tag"
                    pidfile="$tagged.pid"
                    sockfile="$tagged.sock"
                    lockfile="$tagged.lock"
                    credfile="$tagged.cred"
                    jmpid=""
                    if [ -r "$pidfile" ]; then
                        read jmpid < "$pidfile"
                    fi
                    if [ "$jmpid" != "" ]; then
                        kill $jmpid
                    fi
                    [ -e "$pidfile" ] && rm "$pidfile"
                    [ -e "$sockfile" ] && rm "$sockfile"
                    [ -e "$lockfile" ] && rm "$lockfile"
                    [ -e "$credfile" ] && rm "$credfile"
                fi

                rm -rf ${dir} &
                rm -rf "${statedir}" &
            fi
        fi
    done

    if [ $found = false ]; then
        echo "No personal gatekeepers found on this host."
    fi

    if [ -n "$1" -a ${foundit} = false ]; then
        echo "Could not find the personal gatekeeper you specified."
    fi
}


findit ()
{
    foundit=false
    for dir in `ls -1d ${file_location}/${file_prefix}* 2>/dev/null`
    do
        if [ -n "${dir}" ]; then
            found=true
            contact=
            if [ -r ${dir}/gatekeeper.log ]; then
                contact="`grep 'GRAM contact' ${dir}/gatekeeper.log |
                    tail -1 |
                    sed 's/^.*GRAM contact: //'`"

                if [ "$1" = "$contact" ]; then
                    foundit=true
                    echo "${dir}"
                fi
            fi
        fi
    done

    if [ ${foundit} = false ]; then
        echo "Could not find the personal gatekeeper you specified."
    fi
}


listem ()
{
    found=false
    foundold=false
    for dir in `ls -1d ${file_location}/${file_prefix}* 2> /dev/null`
    do
        if [ -n "${dir}" ]; then
            found=true
            contact=
            if [ -r ${dir}/gatekeeper.log ]; then
                contact="`grep 'GRAM contact' ${dir}/gatekeeper.log |
                    tail -1 |
                    sed 's/^.*GRAM contact: //'`"
                ${debug} "found contact= [${contact}]"
                globusrun -a -r "${contact}" 1>/dev/null 2>/dev/null
                if [ $? -eq 0 ]; then
                    echo "${contact}"
                else
                    ${debug} "could not authenticate to the contact -- old"
                    foundold=true
                fi
            fi
        fi
    done

    if [ $found = false ]; then
        echo ""
        echo "no personal gatekeepers found on this host"
    fi

    if [ $foundold = true ]; then
        echo ""
        echo "Found old non-functioning personal gatekeeper(s). Please use"
        echo "this command with the -killall option to clean them up."
    fi
}


cleanup ()
{
    if [ ${docleanup} = true ]; then
        rm -rf ${scratch}
        rm -rf ${statefiledir}
        docleanup=false
    fi
}



jmtype=fork
port=
docleanup=false
startnew=false

globus_hostname()
{
    if command -v globus-hostname > /dev/null 2>&1; then
        globus-hostname | cut -d. -f1
    elif command -v hostname > /dev/null 2>&1; then
        hostname | cut -d. -f1
    elif command -v uname > /dev/null 2>&1; then
        uname -n | cut -d. -f1
    fi
}

host=`globus_hostname`
file_location="$HOME/.globus"
file_prefix="gram.$host"
log=never
seg=0
startargs=''
single=''
logdir=""
valgrind=0

while [ -n "$1" ]; do
    case "$1" in
    -help | -h | --help | -usage | --usage)
        long_usage
        exit 0
        ;;
    -version|--version)
        if [ "X${PROGRAM_NAME}" != "X" -a \
              "X${PROGRAM_VERSION}" != "X" ]; then
            echo "${PROGRAM_NAME}: ${PROGRAM_VERSION}"
        elif [ "X${PACKAGE}" != "X" -a \
               "X${VERSION}" != "X" ]; then
            echo "${PACKAGE}: ${VERSION}"
        else
            echo "No version information available."
        fi
        exit 0
        ;;
    -versions|--versions)
        __AT__=@
        if [ -n "${PACKAGE}" -a -n "${VERSION}" -a \
             -n "${DIRT_TIMESTAMP}" -a -n "${DIRT_BRANCH_ID}" -a \
             "X${DIRT_TIMESTAMP}" != "X${__AT__}DIRT_TIMESTAMP${__AT__}" -a \
             "X${DIRT_BRANCH_ID}" != "X${__AT__}DIRT_BRANCH_ID${__AT__}" ];
        then
            echo "${PACKAGE}: ${VERSION} (${DIRT_TIMESTAMP}-${DIRT_BRANCH_ID})"
        else
            echo "No DiRT information available."
        fi
        exit 0;
        ;;

    -kill)
    if test -z "$2" ; then
        echo "ERROR: -kill option requires a contact string" >&2
        exit 1
    fi
    verify_setup kill
    killem "$2"
    exit 0
    ;;
    -killall)
    verify_setup kill
    killem ""
    exit 0
    ;;
    -list)
    listem
    exit 0
    ;;
    -directory)
    findit "$2"
    exit 0
    ;;
    -start)
    startnew=true
    shift
    while [ -n "$1" ]; do
        case $1 in
        -jmtype)
                jmtype="$2"
                shift
                ;;
        -log)
                logdir="$HOME"
                ;;
        -log=*)
                logdir=`expr "$1" : "-log=\(.*\)"`
                if [ "$logdir" = "" ]; then
                    logdir="$HOME"
                fi
                ;;
        -single)
                single="$1"
                ;;
        -valgrind)
                valgrind=1
                ;;
        -port)
                port="$2"
                shift
                ;;
        -seg)
                seg=1
                ;;
        -auditdir)
                auditdir="$2"
                shift
                ;;
        -acctfile)
                acctfile="$2"
                shift;
                ;;
        *)
                if [ $(expr index "$1" " ") = 0 ]; then
		    startargs="$startargs $1"
                else
		    startargs="$startargs '$1'"
                fi
                ;;
        esac
        shift
    done
    break
    ;;
    -debug)
    debug=echo
    ;;
    *)
    globus_args_unrecognized_option "$1"
    ;;
    esac
    shift
done

if [ $startnew != true ]; then
    globus_args_short_usage
    exit 1
fi

user=${LOGNAME:-$USER}
user=${user:-`id -un`}

if test -z "${user}"; then
    echo "ERROR: globus-personal-gatekeeper: can not determine user name" >&2
    exit 1
fi

verify_setup

scratch="${file_location}/${file_prefix}.$$"
statefiledir="${TMPDIR:-/tmp}/${user}/${file_prefix}.$$"

trap cleanup 0 1 2 3 6 9 12 15


docleanup=true
mkdir -p "${scratch}"
mkdir -p "${statefiledir}"

if test $? != 0; then
    echo "Error making state file dir (${statefiledir})." 1>&2
    exit 1
fi

for file in gridmap services.conf gatekeeper.conf jobmanager.conf gatekeeper.log ; do
    rm -f ${scratch}/${file}
done

subject=`grid-proxy-info -identity 2> /dev/null`
if [ $? != 0 ] || [ x"$subject" = x ]; then
    subject=`grid-cert-info -subject 2> /dev/null`
fi
if [ x"$subject" = x ]; then
    echo "Unable to determine security identity"
    exit 1
fi

cat > ${scratch}/gridmap <<EOF
"${subject}" ${user}
EOF

if [ x"$JOBMANAGER_PATH" = x ]; then
    job_manager_path="$(command -v globus-job-manager)"
else
    job_manager_path="$JOBMANAGER_PATH/globus-job-manager"
fi

if [ $valgrind -eq 1 ]; then
    valgrind=`which valgrind`
    if [ $? -ne 0 ]; then
        echo "Error: can't find valgrind" 1>&2
        exit 1
    fi
cat > ${scratch}/jobmanager <<EOF
stderr_log,local_cred - $valgrind valgrind --leak-check=full --leak-resolution=high --show-reachable=yes --log-file=${HOME}/valgrind.%p.log ${job_manager_path} -conf ${scratch}/jobmanager.conf
EOF
else
cat > ${scratch}/jobmanager <<EOF
stderr_log,local_cred - ${job_manager_path} globus-job-manager -conf ${scratch}/jobmanager.conf
EOF
fi

cat > ${scratch}/gatekeeper.conf <<EOF
-gridmap ${scratch}/gridmap
-home ${GLOBUS_LOCATION:-@exec_prefix@}
-e ${sbindir}
-logfile ${scratch}/gatekeeper.log
-grid_services ${scratch}
-d
EOF

if [ -n "$port" ]; then
    echo "-port $port" >> ${scratch}/gatekeeper.conf
fi

if [ ! -z "${acctfile}" ]; then
    echo "-acctfile $acctfile" >> ${scratch}/gatekeeper.conf
fi


if [ -x ${libexecdir}/config.guess ]; then
    host_info=`${libexecdir}/config.guess`

    host_cputype=`echo $host_info | awk -F'-' '{print $1}'`
    host_manufacturer=`echo $host_info | awk -F'-' '{print $2}'`
else
    host_cputype=`uname -m`
    host_manufacturer=unknown
fi
host_osname=`uname -s`
host_osversion=`uname -r`
if [ "$logdir" != "" ]; then
    log_line=`echo "-stdio-log \"$logdir\""`
    log_levels="-log-levels 'FATAL|ERROR'"
fi

if [ -x "${bindir}/globus-version" ]; then
  globus_toolkit_version="`${bindir}/globus-version`"
else
  globus_toolkit_version="Unknown"
fi

cat > ${scratch}/jobmanager.conf <<EOF
-home ${GLOBUS_LOCATION:-@exec_prefix@}
-type ${jmtype}
-globus-gatekeeper-subject "${subject}"
-globus-host-cputype ${host_cputype}
-globus-host-manufacturer ${host_manufacturer}
-globus-host-osname ${host_osname}
-globus-host-osversion ${host_osversion}
$log_line
$log_levels
-state-file-dir ${statefiledir}
${startargs}
$single
${X509_CERT_DIR:+-x509-cert-dir "$X509_CERT_DIR"}
-globus-toolkit-version "$globus_toolkit_version"
-service-tag "$$"
EOF


if [ ! -z "${auditdir}" ]; then
    cat >> ${scratch}/jobmanager.conf <<EOF
-audit-directory ${auditdir}
EOF
fi

if test $seg -eq 1; then
    echo "-seg-module $jmtype" >> ${scratch}/jobmanager.conf
fi

echo "-globus-job-dir ${TMPDIR:-/tmp}" >> ${scratch}/jobmanager.conf

docleanup=false

globus-gatekeeper -c ${scratch}/gatekeeper.conf -test \
    1>/dev/null 2>/dev/null
x=$?
if [ $x -ne 0 ]; then
    echo "ERROR: gatekeeper was not properly configured" >&2
    docleanup=true
    exit 1
fi

globus-gatekeeper -c ${scratch}/gatekeeper.conf < /dev/null > /dev/null 2>/dev/null  &
x=$?
pid=$!
if [ $x -ne 0 ]; then
    echo "ERROR: gatekeeper did not start up properly" >&2
    docleanup=true
    exit 1
fi
echo "$pid" > ${scratch}/gatekeeper.pid

contact=
shallexit=
count=0
while [ ${count} -lt 10 -a -z "${contact}" -a -z "${shallexit}" ]; do
    sleep 1
    contact="`grep 'GRAM contact' ${scratch}/gatekeeper.log`"
    shallexit="`grep FAILED_PLEASE_EXIT ${scratch}/gatekeeper.log`"
    count=$((${count} + 1))
done

if [ ${count} -ge 10 -o -n "${shallexit}" ]; then
    echo "ERROR: gatekeeper did not start up properly" >&2
    docleanup=true
    exit 1
else
    host=`echo "$contact" | cut -d: -f5`
    port=`echo "$contact" | cut -d: -f6`

    cat >> ${scratch}/jobmanager.conf <<EOF
-globus-gatekeeper-host $host
-globus-gatekeeper-port $port
EOF
    echo "$contact" | sed -e 's/^.*GRAM contact:/GRAM contact:/'
fi


exit 0