mirror of
https://github.com/openglow-org/forgefirm.git
synced 2026-09-29 17:41:15 -07:00
Unified logging: rsyslog as the system logger, the ForgeFIRM log tree
rsyslog replaces busybox syslogd/klogd (VIRTUAL-RUNTIME_base-utils-syslog, trimmed PACKAGECONFIG) and becomes the only log writer: the appended /etc/rsyslog.conf sets the inputs and the ff_line format and includes the per-logger rules that `forgectrl --render-syslog` renders from the machine settings at boot. forgefirm-logrotate becomes forgefirm-logging: render before rsyslog starts (S19), sweep the pre-syslog log files into /data/forgefirm/legacy-logs once, and rotate the tree at boot and hourly by rename + HUP instead of copytruncate. Pins bumped to the pushed forgectrl (syslog emitter, Logs tab, export), grblHAL-glowforge (syslog emitter) and python3-gfhardware apps (syslog handlers, capture dir); the CI harnesses set FFLOG_STDERR=1 so failure diagnostics keep the controller's log lines. BRINGUP carries the bench validation checklist (Next work item 14); this is an image change and rides the next flash.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: forgefirm-logging
|
||||
# Required-Start: $local_fs
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop:
|
||||
# Short-Description: ForgeFIRM logging tree: rsyslog rules, rotation
|
||||
### END INIT INFO
|
||||
|
||||
# Runs before rsyslog (S19 < S20):
|
||||
# 1. renders the per-logger rsyslog rules and log directories from the
|
||||
# machine settings (forgectrl --render-syslog) - this is why a log
|
||||
# level changed in the control panel applies at the next reboot;
|
||||
# 2. moves log files from before the syslog tree out of the way, once;
|
||||
# 3. rotates at boot (bounds carry-over bloat), then hourly from a small
|
||||
# background loop (the image runs no cron daemon).
|
||||
|
||||
FORGECTRL=/usr/bin/forgectrl
|
||||
LOGROTATE=/usr/sbin/logrotate
|
||||
CONF=/etc/logrotate.conf
|
||||
PIDFILE=/var/run/forgefirm-logging.pid
|
||||
LEGACY=/data/forgefirm/legacy-logs
|
||||
|
||||
render() {
|
||||
[ -x "$FORGECTRL" ] || return 0
|
||||
# syslog is not up yet at this point: report to the console
|
||||
"$FORGECTRL" --render-syslog || echo "forgefirm-logging: render-syslog failed"
|
||||
}
|
||||
|
||||
# Files written by ForgeFIRM before it logged through syslog. Moved, not
|
||||
# deleted, so nothing on the bench is lost; the factory's own
|
||||
# /data/glowforge.log and /data/log/glowforge* are not ours and stay.
|
||||
sweep_legacy() {
|
||||
moved=0
|
||||
for f in /data/forgectrl.log /data/forgectrl.log.* /data/forgectrl.log-* \
|
||||
/data/gfcloud.log /data/gfcloud.log.* /data/gfhome.log /data/gfhome.log.*; do
|
||||
[ -e "$f" ] || continue
|
||||
mkdir -p "$LEGACY"
|
||||
mv "$f" "$LEGACY/" && moved=1
|
||||
done
|
||||
for d in /data/log/gfcloud /data/log/gfhome; do
|
||||
[ -d "$d" ] || continue
|
||||
mkdir -p "$LEGACY"
|
||||
mv "$d" "$LEGACY/" && moved=1
|
||||
done
|
||||
[ $moved -eq 1 ] && \
|
||||
echo "forgefirm-logging: pre-syslog log files moved to $LEGACY (delete when no longer needed)"
|
||||
return 0
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
render
|
||||
sweep_legacy
|
||||
[ -x "$LOGROTATE" ] || exit 0
|
||||
"$LOGROTATE" "$CONF" 2>/dev/null
|
||||
( while :; do
|
||||
sleep 3600
|
||||
"$LOGROTATE" "$CONF" 2>/dev/null
|
||||
done ) &
|
||||
echo $! > "$PIDFILE"
|
||||
;;
|
||||
stop)
|
||||
[ -r "$PIDFILE" ] && kill "$(cat "$PIDFILE")" 2>/dev/null
|
||||
rm -f "$PIDFILE"
|
||||
;;
|
||||
restart)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
render)
|
||||
render
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|render}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -0,0 +1,17 @@
|
||||
# The ForgeFIRM logging tree: one directory per logger under
|
||||
# /data/log/forgefirm, rsyslog the only writer. Size-capped, so a
|
||||
# chatty debug level cannot fill /data; rotation renames and HUPs
|
||||
# rsyslog (never copytruncate - no lost lines).
|
||||
/data/log/forgefirm/*/*.log {
|
||||
size 2M
|
||||
rotate 3
|
||||
nodateext
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
create 0640 root root
|
||||
sharedscripts
|
||||
postrotate
|
||||
pkill -HUP rsyslogd 2>/dev/null || true
|
||||
endscript
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
SUMMARY = "ForgeFIRM logging tree: rsyslog rules at boot, rotation"
|
||||
DESCRIPTION = "Boot-time glue for the ForgeFIRM logging tree \
|
||||
(/data/log/forgefirm/<logger>/): renders the per-logger rsyslog rules \
|
||||
from the machine settings before rsyslog starts (forgectrl \
|
||||
--render-syslog), moves pre-syslog log files out of the way once, and \
|
||||
drives size-capped logrotate at boot and hourly (a full /data breaks \
|
||||
settings, update staging, and the controllers' own writes)."
|
||||
LICENSE = "MIT"
|
||||
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
|
||||
|
||||
SRC_URI = " \
|
||||
file://forgefirm.logrotate \
|
||||
file://forgefirm-logging.init \
|
||||
"
|
||||
|
||||
S = "${WORKDIR}"
|
||||
|
||||
inherit update-rc.d
|
||||
|
||||
INITSCRIPT_NAME = "forgefirm-logging"
|
||||
# 19: before rsyslog's own script (syslog, S20) so the rendered rules
|
||||
# exist when it reads its config.
|
||||
INITSCRIPT_PARAMS = "start 19 2 3 4 5 ."
|
||||
|
||||
RDEPENDS:${PN} = "logrotate rsyslog forgectrl"
|
||||
|
||||
do_install() {
|
||||
install -Dm 0644 ${WORKDIR}/forgefirm.logrotate ${D}${sysconfdir}/logrotate.d/forgefirm
|
||||
install -Dm 0755 ${WORKDIR}/forgefirm-logging.init ${D}${sysconfdir}/init.d/forgefirm-logging
|
||||
}
|
||||
Reference in New Issue
Block a user