增加stop命令

This commit is contained in:
duanhf2012
2020-04-01 16:35:13 +08:00
parent 27ff65726a
commit 9c7a7644ee
8 changed files with 56 additions and 29 deletions

View File

@@ -12,7 +12,6 @@ import (
"os/signal"
"strconv"
"syscall"
"time"
)
var closeSig chan bool
@@ -97,27 +96,34 @@ func Start() {
}
func stopNode(processid interface{}){
func stopNode(arg interface{}) error {
processid,err := getRunProcessPid()
if err != nil {
return err
}
KillProcess(processid)
return nil
}
func startNode(paramNodeId interface{}) {
func startNode(paramNodeId interface{}) error {
initNode(paramNodeId.(int))
cluster.GetCluster().Start()
service.Start()
writeProcessPid()
for {
bRun := true
for bRun {
select {
case <-sigs:
fmt.Printf("Recv stop sig")
break
default:
time.Sleep(time.Second)
log.Debug("receipt stop signal.")
bRun = false
}
}
close(closeSig)
service.WaitStop()
return nil
}

17
node/node_linux.go Normal file
View File

@@ -0,0 +1,17 @@
// +build linux
package node
import (
"fmt"
"syscall"
)
func KillProcess(processId int){
err := syscall.Kill(processId,syscall.Signal(10))
if err != nil {
fmt.Printf("kill processid %d is fail:%+v.\n",processId,err)
}else{
fmt.Printf("kill processid %d is successful.\n",processId)
}
}

1
node/node_other.go Normal file
View File

@@ -0,0 +1 @@
package node