fix(task/cron): use the correct pointer to build structure

feat(init): included enviroment variable and working directory
test(cron): wip
This commit is contained in:
2024-03-29 11:30:36 +00:00
parent f2bfd6e60b
commit 3bdca8c540
8 changed files with 85 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ package init
import (
"io"
"os"
"os/exec"
"sync"
"time"
@@ -34,6 +35,15 @@ cron:
goto fail
}
cmd = exec.Command(cron.Command(), cron.Arguments()...)
cmd.Env = os.Environ()
if cron.EnvLen() > 0 {
cmd.Env = append(cmd.Env, cron.Environ()...)
}
if len(cron.WorkingDir()) > 0 {
cmd.Dir = cron.WorkingDir()
}
iwg = &sync.WaitGroup{}
if stdout, err = cmd.StdoutPipe(); err != nil {

View File

@@ -25,6 +25,7 @@ type Task interface {
Name() string
Command() string
Arguments() []string
EnvLen() int
Environ() []string
Setsid() bool
UserGroup() UserGroup

View File

@@ -3,6 +3,7 @@ package init
import (
"bufio"
"io"
"os"
"os/exec"
"sync"
"time"
@@ -39,6 +40,15 @@ service:
goto fail
}
cmd = exec.Command(task.Command(), task.Arguments()...)
cmd.Env = os.Environ()
if task.EnvLen() > 0 {
cmd.Env = append(cmd.Env, task.Environ()...)
}
if len(task.WorkingDir()) > 0 {
cmd.Dir = task.WorkingDir()
}
iwg = &sync.WaitGroup{}
if stdout, err = cmd.StdoutPipe(); err != nil {