p4lf.service #2

  • //
  • p4lf/
  • dev/
  • p4lf.service
  • View
  • Commits
  • Open Download .zip Download (1 KB)
[Unit]
Description=P4 Log Feeder - feeds Perforce server log chunks to LogChunksDir
After=network.target
# If p4d is managed by systemd on this host, uncomment to add ordering:
# After=p4d_1.service

[Service]
Type=simple
User=perforce
Group=perforce

# SDP environment: P4LOG and LOGS are set per instance by sourcing
# /p4/common/bin/p4_vars <instance>. That file is a real shell script (uses
# command substitution, conditionals, etc.), NOT a simple KEY=VALUE file, so
# it cannot be loaded via systemd's EnvironmentFile= directive (systemd will
# silently ignore every non-trivial line, leaving P4LOG/LOGS unset). Instead,
# source it in a shell wrapper before exec'ing the binary.
# Adjust the instance number below as needed:
Environment=INSTANCE=1

ExecStart=/bin/bash -c 'source /p4/common/bin/p4_vars ${INSTANCE} && exec /p4/common/site/log_feeder/p4lf -config /p4/common/site/log_feeder/p4lf.cfg'

# On SIGHUP: reload config and rotate p4lf's own log.
ExecReload=/bin/kill -HUP $MAINPID

Restart=on-failure
RestartSec=10s

# Ensure clean shutdown: SIGTERM first, then SIGKILL after 30s.
TimeoutStopSec=30
KillMode=mixed
KillSignal=SIGTERM

# Limit resource usage.
LimitNOFILE=65536

StandardOutput=null
StandardError=journal

[Install]
WantedBy=multi-user.target
# Change User Description Committed
#2 33270 C. Thomas Tyler Fix p4lf.service: EnvironmentFile= cannot source p4_vars (a real shell script),
causing P4LOG/LOGS to never be set and the service to fail on fresh install (P4LF-3).

Replaced EnvironmentFile=-/p4/common/bin/p4_vars with an ExecStart bash -c wrapper
that actually sources p4_vars <instance> and execs the p4lf binary. This also fixes
an unrelated latent risk noted during review: the old '-' prefix on EnvironmentFile
silently ignored a missing/unreadable p4_vars file; the new wrapper aborts immediately
(non-zero exit, clear stderr message) if p4_vars is missing, instead of silently
proceeding without P4LOG/LOGS set.
#1 32818 C. Thomas Tyler Initial implementation of p4lf in Go.

Adds:
- Go module (github.com/rcowham/p4lf) with fsnotify dependency
- internal/config: KEY=VALUE config parser with all settings
- internal/tailer: file reader with inode-based rotation detection and
  state file checkpoint/resume (inode + byte offset, JSON, atomic write)
- internal/chunker: gzip chunk writer with MaxLogChunks/MinLogSpace guards
- internal/logger: rotating log writer with gzip of rotated files
- cmd/p4lf/main.go: service main loop, SIGHUP/SIGTERM/SIGINT handling,
  config hot-reload on modtime change
- Makefile: build/test/install/release targets for Linux amd64/arm64,
  macOS arm64/amd64; version injected via ldflags
- p4lf.cfg.example: fully documented example config
- p4lf.service: systemd unit file (User=perforce, Restart=on-failure)
- ai/session_log_2026-06-25.md: design session log
- ai/session_log_2026-06-25-2.md: implementation session log
- .p4ignore: added bin/ and dist/