Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supports restart ddns-go in service #896

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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