增加SSH登录建议端口接口

This commit is contained in:
GoEdgeLab
2021-08-14 18:07:20 +08:00
parent 09b1c65463
commit af90487eaa
8 changed files with 131 additions and 14 deletions

View File

@@ -3,8 +3,9 @@ package main
import (
"flag"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"net"
"github.com/iwind/gosock/pkg/gosock"
"os"
"os/exec"
)
func main() {
@@ -24,11 +25,21 @@ func main() {
stderr("need '-cmd=COMMAND' argument")
} else if cmd == "test" {
// 检查是否正在运行
path := os.TempDir() + "/edge-node.sock"
conn, err := net.Dial("unix", path)
if err == nil {
_ = conn.Close()
stderr("test node status: edge node is running now, can not install again")
var sock = gosock.NewTmpSock("edge-node")
if sock.IsListening() {
// 从systemd中停止
systemctl, _ := exec.LookPath("systemctl")
if len(systemctl) > 0 {
systemctlCmd := exec.Command(systemctl, "stop", "edge-node")
_ = systemctlCmd.Run()
}
// 从进程中停止
if sock.IsListening() {
_, _ = sock.Send(&gosock.Command{
Code: "stop",
})
}
}
} else if cmd == "unzip" { // 解压
if len(zipPath) == 0 {