blob: 2c2b2ccf9d16c43803f7485f135d0259aea89e36 (
plain)
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
|
#!/bin/bash
outfile=$RSYSLOG_OUT_LOG
terminate=false
function handle_sigusr1 {
echo "Received SIGUSR1, will terminate after the next message" >> $outfile
>&2 echo "[stderr] Received SIGUSR1, will terminate after the next message"
terminate=true
}
trap "handle_sigusr1" SIGUSR1
function handle_sigterm {
echo "Received SIGTERM, terminating" >> $outfile
>&2 echo "[stderr] Received SIGTERM, terminating"
exit 1
}
trap "handle_sigterm" SIGTERM
echo "Starting" >> $outfile
# Write also to stderr (useful for testing the 'output' setting)
>&2 echo "[stderr] Starting"
# Tell rsyslog we are ready to start processing messages
echo "OK"
read log_line
while [[ -n "$log_line" ]]; do
echo "Received $log_line" >> $outfile
>&2 echo "[stderr] Received $log_line"
if [[ $terminate == true ]]; then
# Terminate prematurely by closing pipe, without confirming the message
echo "Terminating without confirming the last message" >> $outfile
>&2 echo "[stderr] Terminating without confirming the last message"
exit 0
fi
# Tell rsyslog we are ready to process the next message
echo "OK"
read log_line
done
echo "Terminating normally" >> $outfile
>&2 echo "[stderr] Terminating normally"
exit 0
|