cmdlogger: initial commit

This commit is contained in:
Mikaël Cluseau
2024-01-20 13:24:14 +01:00
parent 354bdce5ab
commit 1a84bb4286
5 changed files with 76 additions and 31 deletions

View File

@ -3,12 +3,13 @@ package initservices
import (
"log"
"os"
"os/exec"
"path/filepath"
"time"
"github.com/spf13/cobra"
plog "novit.nc/direktil/pkg/log"
cmdlogger "novit.nc/direktil/inits/pkg/cmd/logger"
)
var (
@ -58,18 +59,13 @@ func run(c *cobra.Command, args []string) {
func runService(svcPath string) {
svc := filepath.Base(svcPath)
logger := plog.Get(svc)
plog.EnableFiles()
n := 0
for {
lastStart := time.Now()
cmd := exec.Command(svcPath)
cmd.Stdout = logger
cmd.Stderr = logger
err := cmd.Run()
err := cmdlogger.Run("", svcPath)
if time.Since(lastStart) > crashForgiveDelay {
n = 0