1 From f44343ec2ea7f7cfe9e26b082714837e6f88a247 Mon Sep 17 00:00:00 2001
2 From: Puqns67 <me@puqns67.icu>
3 Date: Sun, 16 Jun 2024 01:15:02 +0800
4 Subject: [PATCH 2/3] build: remove service management support for this build
7 main.go | 224 --------------------------------------------------------
8 1 file changed, 224 deletions(-)
10 diff --git a/main.go b/main.go
11 index 30cebf2..2226a95 100644
14 @@ -9,7 +9,6 @@ import (
22 @@ -18,7 +17,6 @@ import (
23 "github.com/jeessy2/ddns-go/v6/dns"
24 "github.com/jeessy2/ddns-go/v6/util"
25 "github.com/jeessy2/ddns-go/v6/web"
26 - "github.com/kardianos/service"
30 @@ -34,9 +32,6 @@ var every = flag.Int("f", 300, "Update frequency(seconds)")
32 var ipCacheTimes = flag.Int("cacheTimes", 5, "Cache times")
35 -var serviceType = flag.String("s", "", "Service management (install|uninstall|restart)")
38 var configFilePath = flag.String("c", util.GetConfigFilePathDefault(), "Custom configuration file path")
40 @@ -93,37 +88,6 @@ func main() {
41 util.SetDNS(*customDNS)
43 os.Setenv(util.IPCacheTimesENV, strconv.Itoa(*ipCacheTimes))
44 - switch *serviceType {
52 - if util.IsRunInDocker() {
56 - status, _ := s.Status()
57 - if status != service.StatusUnknown {
62 - switch s.Platform() {
63 - case "windows-service":
64 - util.Log("可使用 .\\ddns-go.exe -s install 安装服务运行")
66 - util.Log("可使用 sudo ./ddns-go -s install 安装服务运行")
76 conf, _ := config.GetConfigCached()
77 conf.CompatibleConfig()
78 @@ -186,130 +150,6 @@ func runWebServer() error {
79 return http.Serve(l, nil)
82 -type program struct{}
84 -func (p *program) Start(s service.Service) error {
85 - // Start should not block. Do the actual work async.
89 -func (p *program) run() {
92 -func (p *program) Stop(s service.Service) error {
93 - // Stop should not block. Return with a few seconds.
97 -func getService() service.Service {
98 - options := make(service.KeyValue)
99 - var depends []string
102 - switch service.ChosenSystem().String() {
103 - case "unix-systemv":
104 - options["SysvScript"] = sysvScript
105 - case "windows-service":
106 - // 将 Windows 服务的启动类型设为自动(延迟启动)
107 - options["DelayedAutoStart"] = true
109 - // 向 Systemd 添加网络依赖
110 - depends = append(depends, "Requires=network.target",
111 - "After=network-online.target")
114 - svcConfig := &service.Config{
116 - DisplayName: "ddns-go",
117 - 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...)",
118 - Arguments: []string{"-l", *listen, "-f", strconv.Itoa(*every), "-cacheTimes", strconv.Itoa(*ipCacheTimes), "-c", *configFilePath},
119 - Dependencies: depends,
124 - svcConfig.Arguments = append(svcConfig.Arguments, "-noweb")
128 - svcConfig.Arguments = append(svcConfig.Arguments, "-skipVerify")
131 - if *customDNS != "" {
132 - svcConfig.Arguments = append(svcConfig.Arguments, "-dns", *customDNS)
136 - s, err := service.New(prg, svcConfig)
144 -func uninstallService() {
147 - if service.ChosenSystem().String() == "unix-systemv" {
148 - if _, err := exec.Command("/etc/init.d/ddns-go", "stop").Output(); err != nil {
152 - if err := s.Uninstall(); err == nil {
153 - util.Log("ddns-go 服务卸载成功")
155 - util.Log("ddns-go 服务卸载失败, 异常信息: %s", err)
160 -func installService() {
163 - status, err := s.Status()
164 - if err != nil && status == service.StatusUnknown {
166 - if err = s.Install(); err == nil {
168 - util.Log("安装 ddns-go 服务成功! 请打开浏览器并进行配置")
169 - if service.ChosenSystem().String() == "unix-systemv" {
170 - if _, err := exec.Command("/etc/init.d/ddns-go", "enable").Output(); err != nil {
173 - if _, err := exec.Command("/etc/init.d/ddns-go", "start").Output(); err != nil {
179 - util.Log("安装 ddns-go 服务失败, 异常信息: %s", err)
182 - if status != service.StatusUnknown {
183 - util.Log("ddns-go 服务已安装, 无需再次安装")
188 -func restartService() {
190 - status, err := s.Status()
192 - if status == service.StatusRunning {
193 - if err = s.Restart(); err == nil {
194 - util.Log("重启 ddns-go 服务成功")
196 - } else if status == service.StatusStopped {
197 - if err = s.Start(); err == nil {
198 - util.Log("启动 ddns-go 服务成功")
202 - util.Log("ddns-go 服务未安装, 请先安装服务")
207 func autoOpenExplorer() {
208 _, err := config.GetConfigCached()
209 @@ -332,67 +172,3 @@ func autoOpenExplorer() {
214 -const sysvScript = `#!/bin/sh /etc/rc.common
215 -DESCRIPTION="{{.Description}}"
216 -cmd="{{.Path}}{{range .Arguments}} {{.|cmd}}{{end}}"
218 -pid_file="/var/run/$name.pid"
219 -stdout_log="/var/log/$name.log"
220 -stderr_log="/var/log/$name.err"
226 - [ -f "$pid_file" ] && cat /proc/$(get_pid)/stat > /dev/null 2>&1
229 - if is_running; then
230 - echo "Already started"
232 - echo "Starting $name"
233 - {{if .WorkingDirectory}}cd '{{.WorkingDirectory}}'{{end}}
234 - $cmd >> "$stdout_log" 2>> "$stderr_log" &
235 - echo $! > "$pid_file"
236 - if ! is_running; then
237 - echo "Unable to start, see $stdout_log and $stderr_log"
243 - if is_running; then
244 - echo -n "Stopping $name.."
246 - for i in $(seq 1 10)
248 - if ! is_running; then
255 - if is_running; then
256 - echo "Not stopped; may still be shutting down or shutdown may have failed"
260 - if [ -f "$pid_file" ]; then
270 - if is_running; then
271 - echo "Unable to stop, will not attempt to start"