diff --git a/trojan/install.go b/trojan/install.go index c6687fe5..55c2ed4c 100644 --- a/trojan/install.go +++ b/trojan/install.go @@ -109,8 +109,15 @@ func InstallTls() { } func InstallMysql() { - var mysql core.Mysql - choice := util.LoopInput("请选择: ", []string{"安装docker版mysql", "输入自定义mysql连接"}, true) + var ( + mysql core.Mysql + choice int + ) + if util.IsExists("/.dockerenv") { + choice = 2 + } else { + choice = util.LoopInput("请选择: ", []string{"安装docker版mysql", "输入自定义mysql连接"}, true) + } if choice < 0 { return } else if choice == 1 { diff --git a/trojan/trojan.go b/trojan/trojan.go index b72b8ddf..2ff73e54 100644 --- a/trojan/trojan.go +++ b/trojan/trojan.go @@ -21,58 +21,29 @@ func ControllMenu() { } func Restart() { - if util.IsExists("/.dockerenv") { - Stop() - Start() - fmt.Println(util.Green("重启trojan成功!")) + if err := util.ExecCommand("systemctl restart trojan"); err != nil { + fmt.Println(util.Red("重启trojan失败!")) } else { - if err := util.ExecCommand("systemctl restart trojan"); err != nil { - fmt.Println(util.Red("重启trojan失败!")) - } else { - fmt.Println(util.Green("重启trojan成功!")) - } + fmt.Println(util.Green("重启trojan成功!")) } } func Start() { - if util.IsExists("/.dockerenv") { - check := util.ExecCommandWithResult(`ps aux|grep "/usr/bin/trojan/trojan"|grep -v grep`) - if check != "" { - Stop() - } - util.ExecCommand(`echo "" > /.run.log`) - util.StartProcess("/usr/bin/trojan/trojan", "-c", "/usr/local/etc/trojan/config.json", "-l", "/.run.log") - fmt.Println(util.Green("启动trojan成功!")) + if err := util.ExecCommand("systemctl start trojan"); err != nil { + fmt.Println(util.Red("启动trojan失败!")) } else { - if err := util.ExecCommand("systemctl start trojan"); err != nil { - fmt.Println(util.Red("启动trojan失败!")) - } else { - fmt.Println(util.Green("启动trojan成功!")) - } + fmt.Println(util.Green("启动trojan成功!")) } } func Stop() { - if util.IsExists("/.dockerenv") { - util.ExecCommandWithResult(`ps aux|grep "/usr/bin/trojan/trojan"|grep -v grep|awk '{print $2}'|xargs -r kill -9`) - fmt.Println(util.Green("停止trojan成功!")) + if err := util.ExecCommand("systemctl stop trojan"); err != nil { + fmt.Println(util.Red("停止trojan失败!")) } else { - if err := util.ExecCommand("systemctl stop trojan"); err != nil { - fmt.Println(util.Red("停止trojan失败!")) - } else { - fmt.Println(util.Green("停止trojan成功!")) - } + fmt.Println(util.Green("停止trojan成功!")) } } func Status() { - if util.IsExists("/.dockerenv") { - if util.ExecCommandWithResult("cat /.run.log|grep FATAL") != "" { - fmt.Println(util.ExecCommandWithResult("cat /.run.log")) - } else { - fmt.Println(util.Green("trojan running...")) - } - } else { - util.ExecCommand("systemctl status trojan") - } + util.ExecCommand("systemctl status trojan") } diff --git a/util/command.go b/util/command.go index ac7211f1..86cf4d33 100644 --- a/util/command.go +++ b/util/command.go @@ -5,7 +5,6 @@ import ( "io" "io/ioutil" "net/http" - "os" "os/exec" "strings" ) @@ -86,19 +85,3 @@ func ExecCommandWithResult(command string) string { } return string(out) } - -func StartProcess(name string, args ...string) { - env := os.Environ() - procAttr := &os.ProcAttr{ - Env: env, - Files: []*os.File{ - os.Stdin, - os.Stdout, - os.Stderr, - }, - } - _, err := os.StartProcess(name, args, procAttr) - if err != nil { - fmt.Println(err) - } -}