func (e SysAddons)Start(c *gin.Context){
cmd :=exec.Command("/bin/bash","-c","/home/addons/yzsoft")
stdout0 , err := cmd.StdoutPipe() // 获取命令输出内容
if err != nil {
fmt.Println(err)
return
}else{
fmt.Println(stdout0)
}
if err := cmd.Start(); err != nil { //开始执行命令
fmt.Println(err)
return
}
}
func (e SysAddons)Restart(c *gin.Context){
e.Stop(c)
e.Start(c)
}
func (e SysAddons)Stop(c *gin.Context){
// 获取8299端口对应进程号并kill
processInfo := exec.Command("/bin/sh", "-c",`lsof -i:8081 | awk '{print $2}' | awk 'NR==2{print}'`)
if pid, err := processInfo.Output(); err != nil {
fmt.Println(err.Error())
}else{
fmt.Println(string(pid))
processExit := exec.Command("/bin/sh", "-c",`kill `+string(pid))
if _, err := processExit.Output(); err != nil {
fmt.Println(err.Error())
}
}
}