Uninstall 删除服务
()
| 52 | |
| 53 | // Uninstall 删除服务 |
| 54 | func (this *ServiceManager) Uninstall() error { |
| 55 | if os.Getgid() != 0 { |
| 56 | return errors.New("only root users can uninstall the service") |
| 57 | } |
| 58 | |
| 59 | if files.NewFile(systemdServiceFile).Exists() { |
| 60 | systemd, err := executils.LookPath("systemctl") |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | // disable service |
| 66 | _ = executils.NewTimeoutCmd(10*time.Second, systemd, "disable", teaconst.SystemdServiceName+".service").Start() |
| 67 | |
| 68 | // reload |
| 69 | _ = executils.NewTimeoutCmd(10*time.Second, systemd, "daemon-reload").Start() |
| 70 | |
| 71 | return files.NewFile(systemdServiceFile).Delete() |
| 72 | } |
| 73 | |
| 74 | f := files.NewFile(initServiceFile) |
| 75 | if f.Exists() { |
| 76 | return f.Delete() |
| 77 | } |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | // install init service |
| 82 | func (this *ServiceManager) installInitService(exePath string, args []string) error { |
no test coverage detected