From b0856090d98676d04602905137f115eda35b64f9 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Tue, 21 May 2024 21:27:18 +0200 Subject: [PATCH] fix log file on k8s issue (cherry picked from commit 6f2800f49402cd5fe354fd77340666b424b7bf17) --- daemon/openrc_linux.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/daemon/openrc_linux.go b/daemon/openrc_linux.go index b8d0fedd..76e5f286 100644 --- a/daemon/openrc_linux.go +++ b/daemon/openrc_linux.go @@ -9,6 +9,10 @@ import ( "golang.org/x/exp/slog" ) +var ( + LogFile = "/var/log/netclient.log" +) + // setupOpenRC - sets up openrc daemon func setupOpenRC() error { service := `#!/sbin/openrc-run @@ -25,7 +29,6 @@ respawn_period=10 output_log="/var/log/netclient.log" error_log="/var/log/netclient.log" depend() { - need net after firewall } @@ -34,6 +37,13 @@ depend() { if err := os.WriteFile("/etc/init.d/netclient", bytes, 0755); err != nil { return err } + if _, err := os.Stat(LogFile); err != nil { + if os.IsNotExist(err) { + if err := os.WriteFile(LogFile, []byte("--------------------"), 0644); err != nil { + return err + } + } + } if _, err := ncutils.RunCmd("/sbin/rc-update add netclient default", false); err != nil { return err }