tools/etcd-agent: write etcd log into log file

This commit is contained in:
Yicheng Qin 2015-03-04 16:45:23 -08:00
parent 008bbd2b84
commit 061baad611

View File

@ -23,6 +23,7 @@ import (
type Agent struct { type Agent struct {
cmd *exec.Cmd cmd *exec.Cmd
logfile *os.File
l net.Listener l net.Listener
} }
@ -34,12 +35,20 @@ func newAgent(etcd string) (*Agent, error) {
} }
c := exec.Command(etcd) c := exec.Command(etcd)
return &Agent{cmd: c}, nil
f, err := os.Create("etcd.log")
if err != nil {
return nil, err
}
return &Agent{cmd: c, logfile: f}, nil
} }
// start starts a new etcd process with the given args. // start starts a new etcd process with the given args.
func (a *Agent) start(args ...string) error { func (a *Agent) start(args ...string) error {
a.cmd = exec.Command(a.cmd.Path, args...) a.cmd = exec.Command(a.cmd.Path, args...)
a.cmd.Stdout = a.logfile
a.cmd.Stderr = a.logfile
return a.cmd.Start() return a.cmd.Start()
} }
@ -56,6 +65,8 @@ func (a *Agent) stop() error {
// restart restarts the stopped etcd process. // restart restarts the stopped etcd process.
func (a *Agent) restart() error { func (a *Agent) restart() error {
a.cmd = exec.Command(a.cmd.Path, a.cmd.Args[1:]...) a.cmd = exec.Command(a.cmd.Path, a.cmd.Args[1:]...)
a.cmd.Stdout = a.logfile
a.cmd.Stderr = a.logfile
return a.cmd.Start() return a.cmd.Start()
} }