()
| 262 | } |
| 263 | |
| 264 | func getService() service.Service { |
| 265 | options := make(service.KeyValue) |
| 266 | var depends []string |
| 267 | |
| 268 | // 确保服务等待网络就绪后再启动 |
| 269 | switch service.ChosenSystem().String() { |
| 270 | case "unix-systemv": |
| 271 | options["SysvScript"] = sysvScript |
| 272 | case "windows-service": |
| 273 | // 将 Windows 服务的启动类型设为自动(延迟启动) |
| 274 | options["DelayedAutoStart"] = true |
| 275 | default: |
| 276 | // 向 Systemd 添加网络依赖 |
| 277 | depends = append(depends, "Requires=network.target", |
| 278 | "After=network-online.target") |
| 279 | } |
| 280 | |
| 281 | svcConfig := &service.Config{ |
| 282 | Name: "ddns-go", |
| 283 | DisplayName: "ddns-go", |
| 284 | Description: "Simple and easy to use DDNS. Automatically update domain name resolution to public IP (Support Aliyun, Tencent Cloud, Dnspod, Cloudflare, Callback, Huawei Cloud, Baidu Cloud, Porkbun, GoDaddy...)", |
| 285 | Arguments: []string{"-l", *listen, "-f", strconv.Itoa(*every), "-cacheTimes", strconv.Itoa(*ipCacheTimes), "-c", *configFilePath}, |
| 286 | Dependencies: depends, |
| 287 | Option: options, |
| 288 | } |
| 289 | |
| 290 | if *noWebService { |
| 291 | svcConfig.Arguments = append(svcConfig.Arguments, "-noweb") |
| 292 | } |
| 293 | |
| 294 | if *skipVerify { |
| 295 | svcConfig.Arguments = append(svcConfig.Arguments, "-skipVerify") |
| 296 | } |
| 297 | |
| 298 | if *customDNS != "" { |
| 299 | svcConfig.Arguments = append(svcConfig.Arguments, "-dns", *customDNS) |
| 300 | } |
| 301 | |
| 302 | prg := &program{} |
| 303 | s, err := service.New(prg, svcConfig) |
| 304 | if err != nil { |
| 305 | log.Fatalln(err) |
| 306 | } |
| 307 | return s |
| 308 | } |
| 309 | |
| 310 | // 卸载服务 |
| 311 | func uninstallService() { |
no test coverage detected