-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsvlog.sh
executable file
·70 lines (61 loc) · 2 KB
/
rsvlog.sh
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
#!/bin/sh
# Author: TJ Vanderpoel
# Licence: MIT
# This is a generic 'run' script meant to be linked in a log/ directory
# of a runit, daemontools, s6, or similar service.
# It requires svlogd available in the path.
# If the file './conf' exists, it can modify the behavior
# of the svlogd in these ways:
# SV_LOG_SYSLOG=<anything> (if set, uses syslog)
# SV_LOG_SYSLOG_PRIORITY=daemon.info (default daemon.info)
# If SV_LOG_SYSLOG is unset, these variables are used for the svlogd
# configuration
# USERGROUP=user:group (default rsvlog:adm)
# SV_LOGDIR=/path/to/log (default `basename $(dirname $PWD)`)
# CURRENT_LOG_FILE=filename.log (default 'current')
set -e
if [ $0 != "./run" ]; then
echo "This script meant to be linked as ./run in a service/log directory only!"
exit 1
fi
curdir=$(basename $(pwd))
if [ "$curdir" != "log" ]; then
echo "This script meant to be run from a service/log directory only!"
exit 1
fi
if [ -f ./conf ]; then
. ./conf
fi
if [ -n "$SV_LOG_SYSLOG" ]; then
prio=${SV_LOG_SYSLOG_PRIORITY:-daemon.info}
echo "Logging to Syslog with priority ${prio}"
exec logger -p $prio
fi
if [ "x$SV_LOGDIR" != "x" ]; then
logdir=$SV_LOGDIR
fi
if [ -w /var/log ]; then
user_group=${USERGROUP:-rsvlog:adm}
if [ "x$logdir" = "x" ]; then
logdir=$(basename $(dirname $(pwd)))
fi
[ -d "/var/log/$logdir" ] || mkdir -p "/var/log/$logdir"
[ -L ./main ] || [ -d ./main ] || ln -s "/var/log/$logdir" ./main
[ -L ./current ] || ln -s main/current
if [ "x$CURRENT_LOG_FILE" != "x" ]; then
[ -L "/var/log/$logdir/$CURRENT_LOG_FILE" ] || ln -s current "/var/log/$logdir/$CURRENT_LOG_FILE"
fi
usergroup=$(stat -c "%U:%G" "/var/log/$logdir")
if [ "$usergroup" != "$user_group" ]; then
chown -R $user_group "/var/log/$logdir"
fi
echo Logging as $user_group to /var/log/$logdir
exec chpst -u $user_group svlogd -t ./main
else
echo Logging in $PWD
if [ "x$CURRENT_LOG_FILE" != "x" ]; then
[ -L "$CURRENT_LOG_FILE" ] || ln -s current "$CURRENT_LOG_FILE"
fi
exec svlogd -t ./
fi
# vim: set noet ts=8 sw=8 sts=8