diff --git a/internal/radio/liquidsoap/liquidsoap.go b/internal/radio/liquidsoap/liquidsoap.go index 76c7a3a..1f0de69 100644 --- a/internal/radio/liquidsoap/liquidsoap.go +++ b/internal/radio/liquidsoap/liquidsoap.go @@ -1,10 +1,8 @@ package liquidsoap import ( - "os" "os/exec" "syscall" - "time" "github.com/pkg/errors" ) @@ -20,23 +18,21 @@ func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { return nil, err } + out, err := exec.Command(liquidsoapPath, "--verbose", "-c", scriptPath).CombinedOutput() + if err != nil { + return nil, errors.Wrap(err, "cannot check script") + } + + if len(out) > 0 { + return nil, errors.Errorf("script validation failed: %s", string(out)) + } + cmd := exec.Command(liquidsoapPath, scriptPath) if err := cmd.Start(); err != nil { return nil, err } - // If there are errors in a script this time will be sufficient to wait - // for them to occure. - time.Sleep(4 * time.Second) - - if _, err := os.FindProcess(cmd.Process.Pid); err != nil { - if err_wait := cmd.Wait(); err != nil { - return nil, errors.Wrap(err, err_wait.Error()) - } - return nil, err - } - return &Liquidsoap{ command: cmd}, nil }