looper: rc.local adding path, main.go letting finish the play to find stderr before fatal

This commit is contained in:
Ella Pietraroia 2020-03-02 18:32:28 +10:30
parent 4690209fd5
commit 6968b973bd
2 changed files with 13 additions and 5 deletions

View File

@ -69,6 +69,7 @@ func main() {
// Infinite loop that outputs audio and gathers debug information. // Infinite loop that outputs audio and gathers debug information.
var numPlays int var numPlays int
var fatal bool
for { for {
numPlays++ numPlays++
log.Log(logger.Debug, "playing audio", "play number", numPlays) log.Log(logger.Debug, "playing audio", "play number", numPlays)
@ -91,7 +92,8 @@ func main() {
err = cmd.Start() err = cmd.Start()
if err != nil { if err != nil {
log.Log(logger.Fatal, "cmd.Start() for 'play' failed", "error", err.Error()) log.Log(logger.Error, "cmd.Start() failed", "error", err.Error())
fatal = true
} }
var wg sync.WaitGroup var wg sync.WaitGroup
@ -107,13 +109,19 @@ func main() {
err = cmd.Wait() err = cmd.Wait()
if err != nil { if err != nil {
log.Log(logger.Fatal, "cmd.Run() for 'play' failed", "error", err.Error()) log.Log(logger.Error, "cmd.Run() failed", "error", err.Error())
fatal = true
} }
if errStdout != nil || errStderr != nil { if errStdout != nil || errStderr != nil {
log.Log(logger.Fatal, "failed to capture stdout or stderr") log.Log(logger.Error, "failed to capture stdout or stderr")
fatal = true
} }
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes()) outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
log.Log(logger.Debug, "stdout received", "stdout", outStr) log.Log(logger.Debug, "stdout received", "stdout", outStr)
log.Log(logger.Debug, "stderr received", "stderr", errStr) log.Log(logger.Debug, "stderr received", "stderr", errStr)
if fatal == true {
log.Log(logger.Fatal, "a fatal error has occured while trying to play (see above)")
}
} }
} }

View File

@ -10,6 +10,6 @@ set -x # tell sh to display commands before execution
PLAYERPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper PLAYERPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper
cd $PLAYERPATH cd $PLAYERPATH
./looper & sudo ./looper -path=/home/pi/example.mp3 &
exit 0 exit 0