-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathmanage
executable file
·186 lines (163 loc) · 4.45 KB
/
manage
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
#!/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 status show current service's status
##H sysboot start server from crond if not running
##H restart (re)start the service
##H start (re)start the service
##H rgraphs (re)start only the graphs service
##H graceful restart the service gracefully
##H stop stop the service
##H
##H For more details please refer to operations page:
##H https://twiki.cern.ch/twiki/bin/view/CMS/PhedexOperationsWebSite
if [ $(id -un) = cmsweb ]; then
echo "ERROR: please use another account" 1>&2
exit 1
fi
echo_e=-e bsdstart=bsdstart
case $(uname) in Darwin )
md5sum() { md5 -r ${1+"$@"}; }
echo_e= bsdstart=start
;;
esac
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
PHEDEX_PATTERN="/httpd -f $STATEDIR/server.conf"
GRAPHS_PATTERN="[/]tools/phedex-web.py"
COLOR_OK="\\033[0;32m"
COLOR_WARN="\\033[0;31m"
COLOR_NORMAL="\\033[0;39m"
for app in PHEDEX-{datasvc,web,webapp}; do
. $ROOT/apps/$app/etc/profile.d/init.sh
done
PHEDEX_GRAPHS_ROOT=$PHEDEX_WEB_ROOT/Documentation/WebSite/PlotConfig
GLOBAL_GRAPHS_ROOT=$WEBTOOLS_ROOT/lib/python`echo $PYTHON_VERSION | cut -f1,2 -d.`/site-packages/Tools/GraphTool
export PYTHONPATH=$PHEDEX_GRAPHS_ROOT/src:$GLOBAL_GRAPHS_ROOT/src:$PYTHONPATH
export GLOBAL_GRAPHS_ROOT # for the .xml files
export MPLCONFIGDIR=$STATEDIR
# Start just the graphs server.
start_graphs()
{
cd $STATEDIR
ulimit -v $(( 4096 * 1024 )) # max 4GB vsize
LD_PRELOAD=$JEMALLOC_ROOT/lib/libjemalloc.so python -u $PHEDEX_GRAPHS_ROOT/tools/phedex-web.py $STATEDIR/etc/graphs_website_prod.xml \
</dev/null 2>&1 | rotatelogs $LOGDIR/graphs-%Y%m%d-`hostname -s`.log 86400 >/dev/null 2>&1 &
}
# Stop just the graphs server.
kill_graphs()
{
for PID in $(pgrep -u $(id -u) -f "$GRAPHS_PATTERN" | sort -rn); do
PSLINE=$(ps -o pid=,$bsdstart=,args= $PID |
perl -n -e 'print join(" ", (split)[0..6])')
[ $(ps h $PID | wc -l) = 0 ] && break
echo "Stopping $PID ($PSLINE):"
kill -9 $PID
done
}
# Start service conditionally on crond restart.
sysboot()
{
if [ $(pgrep -u $(id -u) -f "$PHEDEX_PATTERN" | wc -l) = 0 ] ||
[ $(pgrep -u $(id -u) -f "$GRAPHS_PATTERN" | wc -l) = 0 ]; then
start
fi
}
# Start the service.
start()
{
cd $STATEDIR
echo "starting $ME"
$STATEDIR/etc/httpd restart </dev/null 2>&1
start_graphs
}
# Stop the service.
stop()
{
echo "stopping $ME"
for pat in "$PHEDEX_PATTERN" "$GRAPHS_PATTERN"; do
for PID in $(pgrep -u $(id -u) -f "$pat" | sort -n); do
PSLINE=$(ps -o pid=,$bsdstart=,args= $PID |
perl -n -e 'print join(" ", (split)[0..6])')
[ $(ps h $PID | wc -l) = 0 ] && break
echo "Stopping $PID ($PSLINE):"
kill -INT $PID
sleep 1
kill -9 $PID 2>/dev/null
done
done
}
# Check if the server is running.
status()
{
pid=$(pgrep -u $(id -u) -f "$PHEDEX_PATTERN" | sort -n)
if [ X"$pid" = X ]; then
echo $echo_e "$ME is ${COLOR_WARN}NOT RUNNING${COLOR_NORMAL}."
else
echo $echo_e "$ME is ${COLOR_OK}RUNNING${COLOR_NORMAL}, PID" $pid
fi
pid=$(pgrep -u $(id -u) -f "$GRAPHS_PATTERN" | sort -rn)
if [ X"$pid" = X ]; then
echo $echo_e "$ME grapher is ${COLOR_WARN}NOT RUNNING${COLOR_NORMAL}."
else
echo $echo_e "$ME grapher is ${COLOR_OK}RUNNING${COLOR_NORMAL}, PID" $pid
fi
}
graceful()
{
echo "restarting $ME gracefully"
$STATEDIR/etc/httpd graceful
}
# 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
}
# Main routine, perform action requested on command line.
case ${1:-status} in
sysboot )
sysboot
;;
start | restart )
check "$2"
stop
start
;;
status )
status
;;
stop )
check "$2"
stop
;;
graceful )
check "$2"
graceful
;;
rgraphs )
check "$2"
kill_graphs
start_graphs
;;
help )
perl -ne '/^##H/ && do { s/^##H ?//; print }' < $0
;;
version )
echo "$PHEDEX_WEB_VERSION $PHEDEX_DATASVC_VERSION $PHEDEX_WEBAPP_VERSION"
;;
* )
echo "$0: unknown action '$1', please try '$0 help' or documentation." 1>&2
exit 1
;;
esac