logpolicy: put Synology logs buffer in /tmp

Ongoing log writing keeps the spinning disks from hibernating.
Fixes https://github.com/tailscale/tailscale/issues/3551

Tested on DSM6 and DSM7.

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry 2022-06-04 15:51:50 -07:00 committed by Denton Gentry
parent fbc079d82d
commit 0687195bee
1 changed files with 19 additions and 2 deletions

View File

@ -49,6 +49,7 @@ import (
"tailscale.com/util/racebuild"
"tailscale.com/util/winutil"
"tailscale.com/version"
"tailscale.com/version/distro"
)
var getLogTargetOnce struct {
@ -530,9 +531,25 @@ func New(collection string) *Policy {
c.HTTPC = &http.Client{Transport: NewLogtailTransport(u.Host)}
}
filchBuf, filchErr := filch.New(filepath.Join(dir, cmdName), filch.Options{
filchOptions := filch.Options{
ReplaceStderr: redirectStderrToLogPanics(),
})
}
filchPrefix := filepath.Join(dir, cmdName)
// Synology disks cannot hibernate if we're writing logs to them all the time.
// https://github.com/tailscale/tailscale/issues/3551
if runtime.GOOS == "linux" && distro.Get() == distro.Synology {
synologyTmpfsLogs := "/tmp/tailscale-logs"
if err := os.MkdirAll(synologyTmpfsLogs, 0755); err == nil {
filchPrefix = filepath.Join(synologyTmpfsLogs, cmdName)
filchOptions.MaxFileSize = 1 << 20
} else {
// not a fatal error, we can leave the log files on the spinning disk
log.Printf("Unable to create /tmp directory for log storage: %v\n", err)
}
}
filchBuf, filchErr := filch.New(filchPrefix, filchOptions)
if filchBuf != nil {
c.Buffer = filchBuf
if filchBuf.OrigStderr != nil {