mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tools/etcd-agent: write etcd log into log file
This commit is contained in:
parent
008bbd2b84
commit
061baad611
@ -22,8 +22,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Agent struct {
|
type Agent struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
l net.Listener
|
logfile *os.File
|
||||||
|
l net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAgent(etcd string) (*Agent, error) {
|
func newAgent(etcd string) (*Agent, error) {
|
||||||
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user