etcd-agent: SIGQUIT when cleanup

This commit is contained in:
Gyu-Ho Lee 2016-06-15 15:56:14 -07:00
parent b607b36a6c
commit bd604a029e
2 changed files with 9 additions and 7 deletions

View File

@ -73,12 +73,12 @@ func (a *Agent) start(args ...string) error {
} }
// stop stops the existing etcd process the agent started. // stop stops the existing etcd process the agent started.
func (a *Agent) stop() error { func (a *Agent) stopWithSig(sig os.Signal) error {
if a.state != stateStarted { if a.state != stateStarted {
return nil return nil
} }
err := sigtermAndWait(a.cmd) err := stopWithSig(a.cmd, sig)
if err != nil { if err != nil {
return err return err
} }
@ -87,8 +87,8 @@ func (a *Agent) stop() error {
return nil return nil
} }
func sigtermAndWait(cmd *exec.Cmd) error { func stopWithSig(cmd *exec.Cmd, sig os.Signal) error {
err := cmd.Process.Signal(syscall.SIGTERM) err := cmd.Process.Signal(sig)
if err != nil { if err != nil {
return err return err
} }
@ -125,7 +125,8 @@ func (a *Agent) restart() error {
} }
func (a *Agent) cleanup() error { func (a *Agent) cleanup() error {
if err := a.stop(); err != nil { // exit with stackstrace
if err := a.stopWithSig(syscall.SIGQUIT); err != nil {
return err return err
} }
a.state = stateUninitialized a.state = stateUninitialized
@ -152,7 +153,7 @@ func (a *Agent) cleanup() error {
// terminate stops the exiting etcd process the agent started // terminate stops the exiting etcd process the agent started
// and removes the data dir. // and removes the data dir.
func (a *Agent) terminate() error { func (a *Agent) terminate() error {
err := a.stop() err := a.stopWithSig(syscall.SIGTERM)
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,6 +19,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/rpc" "net/rpc"
"syscall"
"github.com/coreos/etcd/tools/functional-tester/etcd-agent/client" "github.com/coreos/etcd/tools/functional-tester/etcd-agent/client"
) )
@ -47,7 +48,7 @@ func (a *Agent) RPCStart(args []string, pid *int) error {
func (a *Agent) RPCStop(args struct{}, reply *struct{}) error { func (a *Agent) RPCStop(args struct{}, reply *struct{}) error {
plog.Printf("stop etcd") plog.Printf("stop etcd")
err := a.stop() err := a.stopWithSig(syscall.SIGTERM)
if err != nil { if err != nil {
plog.Println("error stopping etcd", err) plog.Println("error stopping etcd", err)
return err return err