Skip to content

Commit ec9c82c

Browse files
committed
Use the watch tool to periodically rotate log files.
1 parent df7fd22 commit ec9c82c

File tree

1 file changed

+11
-9
lines changed
  • rootfs/etc/services.d/logrotate

1 file changed

+11
-9
lines changed

rootfs/etc/services.d/logrotate/run

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -e # Exit immediately if a command exits with a non-zero status.
44

5+
# Run hourly.
6+
INTERVAL_IN_SECS=3600
7+
58
# Make sure we appear with a proper name under `ps`.
69
if [ ! -L "$0" ]; then
710
SV_NAME="$(basename "$(pwd)")"
@@ -10,17 +13,16 @@ if [ ! -L "$0" ]; then
1013
fi
1114

1215
log() {
13-
echo "[$(basename "$0")] $*"
16+
if [ -n "${1-}" ]; then
17+
echo "[$(basename "$0")] $*"
18+
else
19+
while read OUTPUT; do
20+
echo "[$(basename "$0")] $OUTPUT"
21+
done
22+
fi
1423
}
1524

1625
log "starting..."
17-
while true; do
18-
s6-applyuidgid -u $USER_ID -g $GROUP_ID -G ${SUP_GROUP_IDS:-$GROUP_ID} /usr/sbin/logrotate -s /config/logrotate.status /etc/logrotate.conf
19-
EXITVALUE=$?
20-
if [ $EXITVALUE != 0 ]; then
21-
log "exited abnormally with [$EXITVALUE]"
22-
fi
23-
sleep 3600
24-
done
26+
s6-applyuidgid -u $USER_ID -g $GROUP_ID -G ${SUP_GROUP_IDS:-$GROUP_ID} /usr/local/bin/watch -i "$INTERVAL_IN_SECS" /usr/sbin/logrotate -s /config/logrotate.status /etc/logrotate.conf | log
2527

2628
# vim:ft=sh:ts=4:sw=4:et:sts=4

0 commit comments

Comments
 (0)