forked from dmwm/deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkqueue_task
executable file
·120 lines (104 loc) · 3.03 KB
/
workqueue_task
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
#!/bin/sh
##H Usage: manage ACTION [SECURITY-STRING]
##H
##H Available actions:
##H help show this help
##H version get current version of the service
##H location_refresh refresh location info for input data
##H reqmgr_sync sync with RequsetManager (get requests & report back)
##H housekeep perform internal housekeeping actions
##H pushcouchapp <couchdb url> push workqueue couchapp to couchdb
##H
##H For more details please refer to operations page:
##H https://twiki.cern.ch/twiki/bin/view/CMS/GlobalWorkQueue
if [ $(id -un) = cmsweb ]; then
echo "ERROR: please use another account" 1>&2
exit 1
fi
ME=$(basename $(dirname $0))
TOP=$(cd $(dirname $0)/../../.. && pwd)
ROOT=$(cd $(dirname $0)/../.. && pwd)
CFGDIR=$(dirname $0)
LOGDIR=$TOP/logs/$ME
STATEDIR=$TOP/state/$ME
CFGFILE=$CFGDIR/GlobalWorkQueueConfig.py
AUTHDIR=$TOP/current/auth/workqueue
. $ROOT/apps/$ME/etc/profile.d/init.sh
export WORKQUEUE_ROOT
export WMCORE_ROOT=$WORKQUEUE_ROOT
export YUI_ROOT
export WMAGENT_CONFIG=${CFGFILE}
export WQ_CLI="${WORKQUEUE_ROOT}/bin/wmagent-workqueue"
logcmd="rotatelogs $LOGDIR/workqueue-%Y%m%d.log 86400 2>&1"
# Verify the security string.
check()
{
CHECK=$(echo "$1" | md5sum | awk '{print $1}')
if [ $CHECK != 94e261a5a70785552d34a65068819993 ]; then
echo "$0: cannot complete operation, please check documentation." 1>&2
exit 2;
fi
}
# check for a service certificate to use
add_cert()
{
if [ -e $AUTHDIR/dmwm-service-cert.pem ] && [ -e $AUTHDIR/dmwm-service-key.pem ]; then
export X509_USER_CERT=$AUTHDIR/dmwm-service-cert.pem
export X509_USER_KEY=$AUTHDIR/dmwm-service-key.pem
fi
}
run()
{
if [ $(pgrep -u $(id -u) -f "${WQ_CLI} $1" | wc -l) = 0 ]; then
cd $STATEDIR
${WQ_CLI} $@
else
echo "Another process of ${WQ_CLI} is still running. Skipping."
exit 4
fi
}
# Main routine, perform action requested on command line.
case ${1:-status} in
help )
perl -ne '/^##H/ && do { s/^##H ?//; print }' < $0
;;
version )
echo ${WORKQUEUE_VERSION:-unknown}
;;
location_refresh )
# PHEDEX cant handle proxy certs yet...
add_cert
run --locations 2>&1 | $logcmd
;;
reqmgr_sync )
cd $STATEDIR
add_cert
run --reqmgr 2>&1 | $logcmd
;;
housekeep )
cd $STATEDIR
add_cert
run --clean 2>&1 | $logcmd
;;
interactive )
cd $STATEDIR
add_cert
${WQ_CLI} -i
;;
pushcouchapp )
url=$2
[ -n "$url" ] ||
{ echo "You must specify the couchdb url"; exit 1; }
# need to use localhost interface to get admin role to allow push
file=$(python -c 'import tempfile as t; print t.mkstemp(suffix = ".py")[1]')
cat ${WMAGENT_CONFIG} > ${file}
perl -p -i -e "s{config.WorkQueueManager.couchurl.*}{config.WorkQueueManager.couchurl = \"$url\"}g" ${file}
WMAGENT_CONFIG=${file}
wmagent-couchapp-init --skip-cron
rm -f ${file}
;;
* )
echo "$0: unknown action '$1', please try '$0 help' or documentation." 1>&2
exit 1
;;
esac