pond: push logs to separate logfiles

This commit is contained in:
Łukasz Magiera 2019-07-26 02:40:06 +02:00
parent 88ef6565b7
commit 11fe67f66f

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -21,6 +22,8 @@ const listenAddr = "127.0.0.1:2222"
type runningNode struct { type runningNode struct {
cmd *exec.Cmd cmd *exec.Cmd
meta nodeInfo meta nodeInfo
stop func()
} }
type api struct { type api struct {
@ -60,9 +63,18 @@ func (api *api) Spawn() (nodeInfo, error) {
} }
errlogfile, err := os.OpenFile(dir + ".err.log", os.O_CREATE | os.O_WRONLY, 0644)
if err != nil {
return nodeInfo{}, err
}
logfile, err := os.OpenFile(dir + ".out.log", os.O_CREATE | os.O_WRONLY, 0644)
if err != nil {
return nodeInfo{}, err
}
cmd := exec.Command("./lotus", "daemon", genParam, "--api", fmt.Sprintf("%d", 2500+id)) cmd := exec.Command("./lotus", "daemon", genParam, "--api", fmt.Sprintf("%d", 2500+id))
cmd.Stderr = os.Stderr cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile)
cmd.Stdout = os.Stdout cmd.Stdout = io.MultiWriter(os.Stdout, logfile)
cmd.Env = []string{"LOTUS_PATH=" + dir} cmd.Env = []string{"LOTUS_PATH=" + dir}
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nodeInfo{}, err return nodeInfo{}, err
@ -78,6 +90,11 @@ func (api *api) Spawn() (nodeInfo, error) {
api.running[id] = runningNode{ api.running[id] = runningNode{
cmd: cmd, cmd: cmd,
meta: info, meta: info,
stop: func() {
defer errlogfile.Close()
defer logfile.Close()
},
} }
api.runningLk.Unlock() api.runningLk.Unlock()