修复系统服务相关代码可能不执行的问题

This commit is contained in:
GoEdgeLab
2023-08-01 16:19:05 +08:00
parent f3fd2b2f64
commit afd454fb55

View File

@@ -1,3 +1,4 @@
//go:build linux
// +build linux // +build linux
package utils package utils
@@ -47,7 +48,7 @@ func (this *ServiceManager) Start() error {
return exec.Command("service", teaconst.ProcessName, "start").Start() return exec.Command("service", teaconst.ProcessName, "start").Start()
} }
// 删除服务 // Uninstall 删除服务
func (this *ServiceManager) Uninstall() error { func (this *ServiceManager) Uninstall() error {
if os.Getgid() != 0 { if os.Getgid() != 0 {
return errors.New("only root users can uninstall the service") return errors.New("only root users can uninstall the service")
@@ -60,10 +61,10 @@ func (this *ServiceManager) Uninstall() error {
} }
// disable service // disable service
exec.Command(systemd, "disable", teaconst.SystemdServiceName+".service").Start() _ = exec.Command(systemd, "disable", teaconst.SystemdServiceName+".service").Start()
// reload // reload
exec.Command(systemd, "daemon-reload") _ = exec.Command(systemd, "daemon-reload").Start()
return files.NewFile(systemdServiceFile).Delete() return files.NewFile(systemdServiceFile).Delete()
} }
@@ -144,10 +145,10 @@ WantedBy=multi-user.target`
} }
// stop current systemd service if running // stop current systemd service if running
exec.Command(systemd, "stop", shortName+".service") _ = exec.Command(systemd, "stop", shortName+".service").Start()
// reload // reload
exec.Command(systemd, "daemon-reload") _ = exec.Command(systemd, "daemon-reload").Start()
// enable // enable
cmd := exec.Command(systemd, "enable", shortName+".service") cmd := exec.Command(systemd, "enable", shortName+".service")