gdp / adm / gdplogd-wrapper.sh @ master
History | View | Annotate | Download (1.63 KB)
1 |
#!/bin/sh |
---|---|
2 |
# |
3 |
# Wrapper for starting up gdplogd |
4 |
# |
5 |
|
6 |
# allow environment to give us a different configuration; local overrides |
7 |
: ${GDP_VER=} |
8 |
{ test -r /etc/gdp.conf.sh && . /etc/gdp.conf.sh; } |
9 |
{ test -r /usr/local/etc/gdp.conf.sh && . /usr/local/etc/gdp.conf.sh; } |
10 |
{ test -r /etc/gdp${GDP_VER}.conf.sh && . /etc/gdp${GDP_VER}.conf.sh; } |
11 |
{ test -r /usr/local/etc/gdp${GDP_VER}.conf.sh && . /usr/local/etc/gdp${GDP_VER}.conf.sh; } |
12 |
|
13 |
# configure defaults |
14 |
: ${GDP_ROOT:=/usr} |
15 |
: ${GDP_LOG_DIR:=/var/log/gdp} |
16 |
: ${GDP_USER:=gdp} |
17 |
: ${GDPLOGD_ARGS:="-D*=10"} |
18 |
: ${GDPLOGD_BIN:=$GDP_ROOT/sbin/gdplogd$GDP_VER} |
19 |
: ${GDPLOGD_LOG:=$GDP_LOG_DIR/gdplogd.log} |
20 |
: ${LLOGGER:="llogger -s3"} |
21 |
|
22 |
# manifest constants (see <sysexits.h>) |
23 |
EX_USAGE=64 |
24 |
EX_UNAVAILABLE=69 |
25 |
EX_NOPERM=77 |
26 |
EX_CONFIG=78 |
27 |
|
28 |
# if we are running as root, start over as gdp |
29 |
test `whoami` = "root" && exec sudo -E -u $GDP_USER $0 "$@" |
30 |
|
31 |
debug=false |
32 |
if [ "x$1" = "x-D" ] |
33 |
then |
34 |
debug=true |
35 |
shift |
36 |
fi |
37 |
|
38 |
if ! $debug |
39 |
then |
40 |
# make sure log file exists so we can append to it |
41 |
test -f $GDPLOGD_LOG || cp /dev/null $GDPLOGD_LOG |
42 |
fifo=/tmp/gdp-logger.$$ |
43 |
cleanup() { |
44 |
rm $fifo |
45 |
} |
46 |
trap cleanup EXIT |
47 |
if ! mkfifo -m 600 $fifo |
48 |
then |
49 |
echo "[FATAL] Cannot create fifo $fifo" |
50 |
exit $EX_NOPERM |
51 |
fi |
52 |
|
53 |
${LLOGGER} -a $GDPLOGD_LOG < $fifo & |
54 |
|
55 |
# redirect remaining output to the log |
56 |
exec > $fifo 2>&1 |
57 |
fi |
58 |
|
59 |
echo "[INFO] Running $0 $@ as `whoami`" |
60 |
if [ `whoami` != $GDP_USER ] |
61 |
then |
62 |
echo "[WARN] Should be running as $GDP_USER" |
63 |
fi |
64 |
if [ $# -ne 0 ] |
65 |
then |
66 |
echo "[ERROR] Usage: $0 [-D]" |
67 |
exit $EX_USAGE |
68 |
fi |
69 |
|
70 |
echo "[INFO] Running $GDPLOGD_BIN $GDPLOGD_ARGS" |
71 |
$GDPLOGD_BIN $GDPLOGD_ARGS |
72 |
rc=$? |
73 |
echo "[FATAL] $0: $GDPLOGD_BIN exited with status $rc" |
74 |
exit $rc |