Skip to content

Commit

Permalink
feat: supports restart ddns-go in service (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessy2 authored Oct 27, 2023
1 parent 4c8cf07 commit b0c050c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var every = flag.Int("f", 300, "同步间隔时间(秒)")
var ipCacheTimes = flag.Int("cacheTimes", 5, "间隔N次与服务商比对")

// 服务管理
var serviceType = flag.String("s", "", "服务管理, 支持install, uninstall")
var serviceType = flag.String("s", "", "服务管理, 支持install, uninstall, restart")

// 配置文件路径
var configFilePath = flag.String("c", util.GetConfigFilePathDefault(), "自定义配置文件路径")
Expand Down Expand Up @@ -91,6 +91,8 @@ func main() {
installService()
case "uninstall":
uninstallService()
case "restart":
restartService()
default:
if util.IsRunInDocker() {
run()
Expand Down Expand Up @@ -275,6 +277,25 @@ func installService() {
}
}

// 重启服务
func restartService() {
s := getService()
status, err := s.Status()
if err == nil {
if status == service.StatusRunning {
if err = s.Restart(); err == nil {
log.Println("重启 ddns-go 服务成功!")
}
} else if status == service.StatusStopped {
if err = s.Start(); err == nil {
log.Println("启动 ddns-go 服务成功!")
}
}
} else {
log.Println("ddns-go 服务未安装, 请先安装服务")
}
}

// 打开浏览器
func autoOpenExplorer() {
_, err := config.GetConfigCached()
Expand Down

0 comments on commit b0c050c

Please sign in to comment.