Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / adm / gdp-rest-wrapper.sh @ master

History | View | Annotate | Download (1.57 KB)

1 45121ec5 Eric Allman
#!/bin/sh
2
{ test -r /usr/local/etc/gdp.conf.sh && . /usr/local/etc/gdp.conf.sh; } ||
3
	{ test -r /etc/gdp.conf.sh && . /etc/gdp.conf.sh; }
4
5
#
6
#  Wrapper for starting up gdp-rest
7
#
8
9
# configure defaults
10
: ${GDP_ROOT:=/usr}
11
: ${GDP_LOG_DIR:=/var/log/gdp}
12 f3360cb5 Eric Allman
: ${GDP_USER:=gdp}
13 45121ec5 Eric Allman
: ${GDP_REST_ARGS:="-D*=10"}
14
: ${GDP_REST_BIN:=$GDP_ROOT/sbin/gdp-rest}
15
: ${GDP_REST_LOG:=$GDP_LOG_DIR/gdp-rest.log}
16 f3360cb5 Eric Allman
: ${LLOGGER:="llogger -s3"}
17 45121ec5 Eric Allman
18 f3360cb5 Eric Allman
# manifest constants (see <sysexits.h>)
19
EX_USAGE=64
20
EX_UNAVAILABLE=69
21 8404f1db Rick Pratt
EX_TEMPFAIL=75
22 f3360cb5 Eric Allman
EX_NOPERM=77
23
EX_CONFIG=78
24
25
# if we are running as root, start over as gdp
26
test `whoami` = "root" && exec sudo -u $GDP_USER $0 "$@"
27
28
debug=false
29
if [ "x$1" = "x-D" ]
30
then
31
	debug=true
32
	shift
33
fi
34
35
if ! $debug
36
then
37
	# make sure log file exists so we can append to it
38
	test -f $GDP_REST_LOG || cp /dev/null $GDP_REST_LOG
39
	fifo=/tmp/gdp-logger.$$
40
	cleanup() {
41
		rm $fifo
42
	}
43
	trap cleanup EXIT
44
	if ! mkfifo -m 600 $fifo
45
	then
46
		echo "[FATAL] Cannot create fifo $fifo"
47
		exit $EX_NOPERM
48
	fi
49
50
	${LLOGGER} -a $GDP_REST_LOG < $fifo &
51
52
	# redirect remaining output to the log
53
	exec > $fifo 2>&1
54
fi
55
56
echo "[INFO] Running $0 $@ as `whoami`"
57
if [ `whoami` != $GDP_USER ]
58
then
59
	echo "[WARN] Should be running as $GDP_USER"
60
fi
61
if [ $# -ne 0 ]
62
then
63
	echo "[ERROR] Usage: $0 [-D]"
64
	exit $EX_USAGE
65
fi
66
67 8404f1db Rick Pratt
rc=$EX_TEMPFAIL
68
while [ $rc -eq $EX_TEMPFAIL ];
69
do
70
	echo "[INFO] Running $GDP_REST_BIN $GDP_REST_ARGS"
71
	$GDP_REST_BIN $GDP_REST_ARGS
72
	rc=$?
73
	if [ $rc -eq $EX_TEMPFAIL ];
74
	then
75
		echo "[WARN] $0: $GDP_REST_BIN DNS lookup failure, will retry"
76
		sleep 30
77
	fi
78
done
79
80 f3360cb5 Eric Allman
echo "[FATAL] $0: $GDP_REST_BIN exited with status $rc"
81
exit $rc