feat: add logrotate support with SIGHUP signal handling
Some checks failed
Build RPM Package / Build RPM Packages (CentOS 7, Rocky 8/9/10) (push) Has been cancelled
Some checks failed
Build RPM Package / Build RPM Packages (CentOS 7, Rocky 8/9/10) (push) Has been cancelled
- Add Reopenable interface in api/types.go for log rotation support - Add FileWriter.Reopen() method to reopen log files after rotation - Add MultiWriter.Reopen() method to propagate rotation to all writers - Update main.go to handle SIGHUP signal for systemctl reload - Add logrotate configuration file (packaging/logrotate/ja4sentinel) - Update systemd service with ExecReload for graceful rotation - Update architecture.yml with logrotate documentation - Update RPM spec and Dockerfile.package to include logrotate files - Bump version to 1.1.0 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@ -182,6 +182,28 @@ func (w *FileWriter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reopen reopens the log file (for logrotate support)
|
||||
func (w *FileWriter) Reopen() error {
|
||||
w.mutex.Lock()
|
||||
defer w.mutex.Unlock()
|
||||
|
||||
if err := w.file.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close file during reopen: %w", err)
|
||||
}
|
||||
|
||||
// Open new file
|
||||
newFile, err := os.OpenFile(w.path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to reopen file %s: %w", w.path, err)
|
||||
}
|
||||
|
||||
w.file = newFile
|
||||
w.encoder = json.NewEncoder(newFile)
|
||||
w.currentSize = 0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnixSocketWriter writes log records to a UNIX socket with reconnection logic
|
||||
type UnixSocketWriter struct {
|
||||
socketPath string
|
||||
@ -495,6 +517,23 @@ func (mw *MultiWriter) CloseAll() error {
|
||||
return lastErr
|
||||
}
|
||||
|
||||
// Reopen reopens all writers that support log rotation
|
||||
func (mw *MultiWriter) Reopen() error {
|
||||
mw.mutex.Lock()
|
||||
defer mw.mutex.Unlock()
|
||||
|
||||
var lastErr error
|
||||
for _, w := range mw.writers {
|
||||
if reopenable, ok := w.(api.Reopenable); ok {
|
||||
if err := reopenable.Reopen(); err != nil {
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastErr
|
||||
}
|
||||
|
||||
// BuilderImpl implements the api.Builder interface
|
||||
type BuilderImpl struct{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user