File: 280

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (254 lines) | stat: -rwxr-xr-x 7,045 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
#! /bin/sh
# PCP QA Test No. 280
# pmlogger_check basic sanity check
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

# if the primary logger is configured for logpush, we need to
# quietly move on and not dink with things ...
#
if pminfo -f pmcd.pmlogger.archive 2>&1 \
   | tee -a $seq_full \
   | grep -q '"primary".*"http://'
then
    _notrun "primary pmlogger configured for logpush"
    # NOTREACHED
fi

if which realpath >/dev/null 2>&1
then
    [ `realpath $PCP_ARCHIVE_DIR/$(hostname)` = "$PCP_ARCHIVE_DIR/$(hostname)" ] || _notrun "symlinks in PCP_ARCHIVE_DIR: `realpath $PCP_ARCHIVE_DIR/$(hostname)` != $PCP_ARCHIVE_DIR/$(hostname)"
fi

_filter()
{
    [ -z "$PCP_PMLOGGERCONTROL_PATH" ] && \
	PCP_PMLOGGERCONTROL_PATH="$PCP_SYSCONF_DIR/pmlogger/control"
    sed \
	-e 's/\.\.\.*/[dots]/' \
	-e 's/control.d\/.*:[0-9][0-9]*]/control:LINE]/' \
	-e 's/control:[0-9][0-9]*]/control:LINE]/' \
	-e 's/process [0-9][0-9]*/process PID/' \
	-e 's;/usr/var;/var;g' \
	-e "s/`hostname`/LOCALHOST/g" \
	-e "s/$LOCALHOST/LOCALHOST/g" \
	-e "s/localhost/LOCALHOST/g" \
	-e "s/local:/LOCALHOST/g" \
	-e '/^Reconfigured: .*pmlogconf./d' \
	-e '/^No reconfigure: .*pmlogconf./d' \
	-e '/^PMLOGGER_CHECK_SKIP_LOGCONF=yes:/d' \
	-e '/^Start \[/s/ 2[0-9:. -]*/ DATESTAMP/' \
	-e '/^End \[/s/ 2[0-9:. -]*/ DATESTAMP /' \
	-e 's;/private/;/;g' \
	-e "s;$LOGGING_DIR;\$PCP_ARCHIVE_DIR;" \
	-e "s;$PCP_PMLOGGERCONTROL_PATH;\$PCP_PMLOGGERCONTROL_PATH;" \
	-e 's/\.* done/. done/' \
	-e 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]/CHECK/' \
	-e 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]-[0-9][0-9]/CHECK/' \
	-e 's/-rw-r--r--\./-rw-r--r--/' \
    | _filter_cron_scripts
}

_filter_pmlc()
{
    sed -n \
	-e '/Unable to connect/{
s/local:/LOCALHOST/g
p
}' \
    # end
}

status=1	# failure is the default!
signal=$PCP_BINADM_DIR/pmsignal
LOCALHOST=`hostname`
LOGGING_DIR="$PCP_ARCHIVE_DIR"
trap "_cleanup; $sudo rm -f $tmp.* $LOGGING_DIR/$LOCALHOST/lock; exit \$status" 0 1 2 3 15

_stop_auto_restart pmcd
_stop_auto_restart pmlogger

_cleanup()
{
    _restore_config $PCP_ETC_DIR/pcp/pmlogger
    _service pmcd restart 2>&1 | tee -a $seq_full | _filter_pcp_restart
    _wait_for_pmcd
    _restore_auto_restart pmcd
    _service pmlogger restart 2>&1 | tee -a $seq_full | _filter_pcp_restart
    _wait_for_pmlogger
    _restore_auto_restart pmlogger
}

# remove babble from pmlc at startup
#
_cull_welcome()
{
    $PCP_AWK_PROG '
BEGIN								{ skip = 0 }
skip == 0 && /^Performance Co-Pilot Logger Control (pmlc)/	{ skip = 1 }
skip == 1 && $1 == "pmlc> "					{ skip = 0 }
skip == 0							{ print }'
}


PMLOGGER_CHECK_SKIP_LOGCONF=yes; export PMLOGGER_CHECK_SKIP_LOGCONF

# real QA test starts here
_save_config $PCP_ETC_DIR/pcp/pmlogger
_restore_pmlogger_control
umask 022

# start from a known state
#
if ! _service pmcd restart 2>&1; then _exit 1; fi \
| _filter_pcp_restart
_wait_for_pmcd || _exit 1
if ! _service pmlogger restart 2>&1; then _exit 1; fi \
| _filter_pcp_restart
_wait_for_pmlogger -P $LOGGING_DIR/$LOCALHOST/pmlogger.log || _exit 1

# these sometimes get left around and are owned by root
$sudo rm -f $PCP_VAR_DIR/config/pmlogger/*.{tmp,saved} 2>/dev/null

echo
echo "Ping primary logger ..." | tee -a $seq_full
echo 'connect primary' >$tmp.pmlc
_try_pmlc

echo
echo "Expect this should do nothing ..." | tee -a $seq_full
touch $tmp.log
$sudo chown $PCP_USER:$PCP_GROUP $tmp.log

# need to be a place the user $PCP_USER can cd to from pmlogger_check
#
cd /var/tmp
$sudo -u $PCP_USER -g $PCP_GROUP sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_check -V -l $tmp.log"
cd $here
[ -f $tmp.log ] && $sudo cat $tmp.log | tee -a $seq_full | _filter
_try_pmlc

pid=`_get_primary_logger_pid`
if [ -z "$pid" ]
then
    echo "Error: cannot find PID for primary logger"
    LC_TIME=POSIX ls -l $PCP_TMP_DIR/pmlogger
    pminfo -f pmcd.pmlogger
    exit
fi

echo
echo "Kill off primary logger ..." | tee -a $seq_full
if ! _service pmlogger stop 2>&1; then _exit 1; fi | _filter_pcp_stop
_wait_pmlogger_end $pid || _exit 1
_try_pmlc expect-failure
cat $tmp.out $tmp.err | _filter_pmlc | _cull_welcome
pmafm $LOGGING_DIR/$LOCALHOST/Latest remove >$tmp.cmd 2>&1 \
&& $sudo sh $tmp.cmd

# delay to minimize risk of archive name clash
#
sleep 2

echo
echo "Expect this to re-start the primary logger ..." | tee -a $seq_full
cd /var/tmp
#debug# echo "PCP_PMLOGGERCONTROL_PATH=$PCP_PMLOGGERCONTROL_PATH"
#debug# ls -l $PCP_PMLOGGERCONTROL_PATH
$sudo -u $PCP_USER -g $PCP_USER sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_check -V -l $tmp.log"
cd $here
[ -f $tmp.log ] && $sudo cat $tmp.log | tee -a $seq_full | _filter
_try_pmlc

# if it is present, get systemctl on the same page ...
#
if ! _service pmlogger start 2>&1; then _exit 1; fi | _filter_pcp_start
_wait_for_pmlogger -P $LOGGING_DIR/$LOCALHOST/pmlogger.log || _exit 1

pid=`_get_primary_logger_pid`
if [ -z "$pid" ]
then
    echo "Error: cannot find PID for primary logger"
    LC_TIME=POSIX ls -l $PCP_TMP_DIR/pmlogger
    pminfo -f pmcd.pmlogger
    exit
fi

echo
echo "Kill off primary logger ..." | tee -a $seq_full
if ! _service pmlogger stop 2>&1; then _exit 1; fi | _filter_pcp_stop
_wait_pmlogger_end $pid || _exit 1
_try_pmlc expect-failure
cat $tmp.out $tmp.err | _filter_pmlc | _cull_welcome
pmafm $LOGGING_DIR/$LOCALHOST/Latest remove >$tmp.cmd 2>&1 \
&& $sudo sh $tmp.cmd

# delay to minimize risk of archive name clash
#
sleep 2

echo
echo "Expect this to quietly re-start the primary logger ..." | tee -a $seq_full
cd /var/tmp
$sudo -u $PCP_USER -g $PCP_USER sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_check -l $tmp.log"
cd $here
[ -f $tmp.log ] && $sudo cat $tmp.log | tee -a $seq_full | _filter
_try_pmlc

echo
echo "Expect this to get a mutex failure ..." | tee -a $seq_full
$sudo touch $LOGGING_DIR/$LOCALHOST/lock
cd /var/tmp
$sudo -u $PCP_USER -g $PCP_USER sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_check -l $tmp.log"
cd $here
if [ -f $tmp.log ]
then
    $sudo cat $tmp.log | tee -a $seq_full | _filter \
    | $PCP_AWK_PROG '
/-r.-r.-r.-/	{ $3 = "USER"; $4 = "GROUP"; $6 = "Mmm"; $7 = "D"; $8 = "YYYY" }
		{ print }'
fi

echo
echo "Expect this to cleanup an old lock file ..." | tee -a $seq_full
$sudo rm -f $LOGGING_DIR/$LOCALHOST/lock
$sudo touch -t 199701020304.00 $LOGGING_DIR/$LOCALHOST/lock
cd /var/tmp
$sudo -u $PCP_USER -g $PCP_USER sh -c "umask 022; $PCP_BINADM_DIR/pmlogger_check -l $tmp.log"
cd $here
for i in 1 2 3 4 5 6 7 8 9 10
do
    if [ -f $tmp.log ]
    then
	$sudo cat $tmp.log \
	| tee -a $seq_full \
	| _filter \
	| $PCP_AWK_PROG '
/-r.-r.-r.-/	{ $3 = "USER"; $4 = "GROUP" }
		{ print }'
	break
    fi
    sleep 1
done

if [ ! -f $tmp.log ]
then
    echo "Hmm, $tmp.log not created after 10 seconds ..."
    ls -l $tmp.*
    ls -l $LOGGING_DIR $LOGGING_DIR/$LOCALHOST/lock
fi

$sudo rm -f $LOGGING_DIR/$LOCALHOST/lock

# success, all done
status=0
exit