Add pkg/logwrite which writes and rotates log files

This process connects to memlogd and streams logs to individual files,
one per log. It keeps track of how many bytes have been written to each
file and rotates when the file size exceeds a defined threshold.

By default the maximum size of each file before rotation is 1MiB and
we keep up to 10 files per log.

Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
David Scott
2018-07-02 15:41:37 +01:00
parent 4b4d56913d
commit 565f787bb3
8 changed files with 323 additions and 24 deletions

View File

@@ -0,0 +1,14 @@
#!/bin/sh
for i in $(seq 1 20); do
if [ -e /var/log/fill-the-logs.out.0 ]; then
printf "logwrite test suite PASSED\n" > /dev/console
/sbin/poweroff -f
fi
sleep 1
done
printf "logwrite test suite FAILED\n" > /dev/console
echo "contents of /var/log:" > /dev/console
ls -l /var/log > /dev/console
/sbin/poweroff -f

View File

@@ -0,0 +1,24 @@
#!/bin/sh
# SUMMARY: Check that the logwrite package works
# LABELS:
# REPEAT:
set -e
# Source libraries. Uncomment if needed/defined
#. "${RT_LIB}"
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
NAME=logwrite
clean_up() {
rm -rf ${NAME}-*
}
trap clean_up EXIT
# Test code goes here
linuxkit build -disable-content-trust -format kernel+initrd -name "${NAME}" test.yml
RESULT="$(linuxkit run ${NAME})"
echo "${RESULT}"
echo "${RESULT}" | grep -q "suite PASSED"
exit 0

View File

@@ -0,0 +1,35 @@
kernel:
image: linuxkit/kernel:4.14.53
cmdline: "console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:6cc1442112980c889230b6449df09d5b48de6854
- linuxkit/runc:v0.4
- linuxkit/containerd:f2bc1bda1ab18146967fa1a149800aaf14bee81b
- linuxkit/ca-certificates:v0.4
- linuxkit/memlogd:883f0d46e7d3ae2d787e8acb496da115a4707cbc
services:
# A service which generates logs of log messages
- name: fill-the-logs
image: alpine
command: ["/bin/sh", "-c", "while /bin/true; do echo hello $(date); done" ]
- name: write-and-rotate-logs
image: linuxkit/logwrite:7859c102a963828fd9c5aa3837db9600483220c7
command: ["/usr/bin/logwrite", "-max-log-size", "1024"]
- name: check-the-logs
image: alpine:3.8
binds:
- /check.sh:/check.sh
- /dev/console:/dev/console
- /var/log:/var/log
command: ["sh", "./check.sh"]
pid: host
capabilities:
- CAP_SYS_BOOT
files:
- path: check.sh
source: ./check.sh
trust:
org:
- linuxkit
image:
- alpine:3.8