mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	试用 executils.LookPath()代替 exec.LookPath()
This commit is contained in:
		@@ -4,6 +4,7 @@ package utils
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
 | 
						"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
 | 
				
			||||||
 | 
						executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
 | 
				
			||||||
	"github.com/iwind/TeaGo/types"
 | 
						"github.com/iwind/TeaGo/types"
 | 
				
			||||||
	"os/exec"
 | 
						"os/exec"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
@@ -14,7 +15,7 @@ func AddPortsToFirewall(ports []int) {
 | 
				
			|||||||
		// Linux
 | 
							// Linux
 | 
				
			||||||
		if runtime.GOOS == "linux" {
 | 
							if runtime.GOOS == "linux" {
 | 
				
			||||||
			// firewalld
 | 
								// firewalld
 | 
				
			||||||
			firewallCmd, _ := exec.LookPath("firewall-cmd")
 | 
								firewallCmd, _ := executils.LookPath("firewall-cmd")
 | 
				
			||||||
			if len(firewallCmd) > 0 {
 | 
								if len(firewallCmd) > 0 {
 | 
				
			||||||
				err := exec.Command(firewallCmd, "--add-port="+types.String(port)+"/tcp").Run()
 | 
									err := exec.Command(firewallCmd, "--add-port="+types.String(port)+"/tcp").Run()
 | 
				
			||||||
				if err == nil {
 | 
									if err == nil {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ package utils
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
 | 
						teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
 | 
				
			||||||
 | 
						executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
 | 
				
			||||||
	"github.com/iwind/TeaGo/Tea"
 | 
						"github.com/iwind/TeaGo/Tea"
 | 
				
			||||||
	"github.com/iwind/TeaGo/files"
 | 
						"github.com/iwind/TeaGo/files"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
@@ -15,13 +16,13 @@ import (
 | 
				
			|||||||
var systemdServiceFile = "/etc/systemd/system/edge-api.service"
 | 
					var systemdServiceFile = "/etc/systemd/system/edge-api.service"
 | 
				
			||||||
var initServiceFile = "/etc/init.d/" + teaconst.SystemdServiceName
 | 
					var initServiceFile = "/etc/init.d/" + teaconst.SystemdServiceName
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 安装服务
 | 
					// Install 安装服务
 | 
				
			||||||
func (this *ServiceManager) Install(exePath string, args []string) error {
 | 
					func (this *ServiceManager) Install(exePath string, args []string) error {
 | 
				
			||||||
	if os.Getgid() != 0 {
 | 
						if os.Getgid() != 0 {
 | 
				
			||||||
		return errors.New("only root users can install the service")
 | 
							return errors.New("only root users can install the service")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	systemd, err := exec.LookPath("systemctl")
 | 
						systemd, err := executils.LookPath("systemctl")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return this.installInitService(exePath, args)
 | 
							return this.installInitService(exePath, args)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -29,14 +30,14 @@ func (this *ServiceManager) Install(exePath string, args []string) error {
 | 
				
			|||||||
	return this.installSystemdService(systemd, exePath, args)
 | 
						return this.installSystemdService(systemd, exePath, args)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 启动服务
 | 
					// Start 启动服务
 | 
				
			||||||
func (this *ServiceManager) Start() error {
 | 
					func (this *ServiceManager) Start() error {
 | 
				
			||||||
	if os.Getgid() != 0 {
 | 
						if os.Getgid() != 0 {
 | 
				
			||||||
		return errors.New("only root users can start the service")
 | 
							return errors.New("only root users can start the service")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if files.NewFile(systemdServiceFile).Exists() {
 | 
						if files.NewFile(systemdServiceFile).Exists() {
 | 
				
			||||||
		systemd, err := exec.LookPath("systemctl")
 | 
							systemd, err := executils.LookPath("systemctl")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -53,7 +54,7 @@ func (this *ServiceManager) Uninstall() error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if files.NewFile(systemdServiceFile).Exists() {
 | 
						if files.NewFile(systemdServiceFile).Exists() {
 | 
				
			||||||
		systemd, err := exec.LookPath("systemctl")
 | 
							systemd, err := executils.LookPath("systemctl")
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -93,7 +94,7 @@ func (this *ServiceManager) installInitService(exePath string, args []string) er
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	chkCmd, err := exec.LookPath("chkconfig")
 | 
						chkCmd, err := executils.LookPath("chkconfig")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user