net-im/tencent-qq: bump version to 3.2.15_p241224
[gentoo-zh.git] / net-dns / ddns-go / files / ddns-go-6.6.2-remove-service-management-support.patch
bloba9fd632465489a8b3524b396427f867a8fbdde3f
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
6 ---
7 main.go | 224 --------------------------------------------------------
8 1 file changed, 224 deletions(-)
10 diff --git a/main.go b/main.go
11 index 30cebf2..2226a95 100644
12 --- a/main.go
13 +++ b/main.go
14 @@ -9,7 +9,6 @@ import (
15 "net"
16 "net/http"
17 "os"
18 - "os/exec"
19 "path/filepath"
20 "strconv"
21 "time"
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"
29 // ddns-go 版本
30 @@ -34,9 +32,6 @@ var every = flag.Int("f", 300, "Update frequency(seconds)")
31 // 缓存次数
32 var ipCacheTimes = flag.Int("cacheTimes", 5, "Cache times")
34 -// 服务管理
35 -var serviceType = flag.String("s", "", "Service management (install|uninstall|restart)")
37 // 配置文件路径
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 {
45 - case "install":
46 - installService()
47 - case "uninstall":
48 - uninstallService()
49 - case "restart":
50 - restartService()
51 - default:
52 - if util.IsRunInDocker() {
53 - run()
54 - } else {
55 - s := getService()
56 - status, _ := s.Status()
57 - if status != service.StatusUnknown {
58 - // 以服务方式运行
59 - s.Run()
60 - } else {
61 - // 非服务方式运行
62 - switch s.Platform() {
63 - case "windows-service":
64 - util.Log("可使用 .\\ddns-go.exe -s install 安装服务运行")
65 - default:
66 - util.Log("可使用 sudo ./ddns-go -s install 安装服务运行")
67 - }
68 - run()
69 - }
70 - }
71 - }
74 -func run() {
75 // 兼容之前的配置文件
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.
86 - go p.run()
87 - return nil
89 -func (p *program) run() {
90 - run()
92 -func (p *program) Stop(s service.Service) error {
93 - // Stop should not block. Return with a few seconds.
94 - return nil
97 -func getService() service.Service {
98 - options := make(service.KeyValue)
99 - var depends []string
101 - // 确保服务等待网络就绪后再启动
102 - switch service.ChosenSystem().String() {
103 - case "unix-systemv":
104 - options["SysvScript"] = sysvScript
105 - case "windows-service":
106 - // 将 Windows 服务的启动类型设为自动(延迟启动)
107 - options["DelayedAutoStart"] = true
108 - default:
109 - // 向 Systemd 添加网络依赖
110 - depends = append(depends, "Requires=network.target",
111 - "After=network-online.target")
114 - svcConfig := &service.Config{
115 - Name: "ddns-go",
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,
120 - Option: options,
123 - if *noWebService {
124 - svcConfig.Arguments = append(svcConfig.Arguments, "-noweb")
127 - if *skipVerify {
128 - svcConfig.Arguments = append(svcConfig.Arguments, "-skipVerify")
131 - if *customDNS != "" {
132 - svcConfig.Arguments = append(svcConfig.Arguments, "-dns", *customDNS)
135 - prg := &program{}
136 - s, err := service.New(prg, svcConfig)
137 - if err != nil {
138 - log.Fatalln(err)
140 - return s
143 -// 卸载服务
144 -func uninstallService() {
145 - s := getService()
146 - s.Stop()
147 - if service.ChosenSystem().String() == "unix-systemv" {
148 - if _, err := exec.Command("/etc/init.d/ddns-go", "stop").Output(); err != nil {
149 - log.Println(err)
152 - if err := s.Uninstall(); err == nil {
153 - util.Log("ddns-go 服务卸载成功")
154 - } else {
155 - util.Log("ddns-go 服务卸载失败, 异常信息: %s", err)
159 -// 安装服务
160 -func installService() {
161 - s := getService()
163 - status, err := s.Status()
164 - if err != nil && status == service.StatusUnknown {
165 - // 服务未知,创建服务
166 - if err = s.Install(); err == nil {
167 - s.Start()
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 {
171 - log.Println(err)
173 - if _, err := exec.Command("/etc/init.d/ddns-go", "start").Output(); err != nil {
174 - log.Println(err)
177 - return
179 - util.Log("安装 ddns-go 服务失败, 异常信息: %s", err)
182 - if status != service.StatusUnknown {
183 - util.Log("ddns-go 服务已安装, 无需再次安装")
187 -// 重启服务
188 -func restartService() {
189 - s := getService()
190 - status, err := s.Status()
191 - if err == nil {
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 服务成功")
201 - } else {
202 - util.Log("ddns-go 服务未安装, 请先安装服务")
206 // 打开浏览器
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}}"
217 -name="ddns-go"
218 -pid_file="/var/run/$name.pid"
219 -stdout_log="/var/log/$name.log"
220 -stderr_log="/var/log/$name.err"
221 -START=99
222 -get_pid() {
223 - cat "$pid_file"
225 -is_running() {
226 - [ -f "$pid_file" ] && cat /proc/$(get_pid)/stat > /dev/null 2>&1
228 -start() {
229 - if is_running; then
230 - echo "Already started"
231 - else
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"
238 - exit 1
239 - fi
240 - fi
242 -stop() {
243 - if is_running; then
244 - echo -n "Stopping $name.."
245 - kill $(get_pid)
246 - for i in $(seq 1 10)
247 - do
248 - if ! is_running; then
249 - break
250 - fi
251 - echo -n "."
252 - sleep 1
253 - done
254 - echo
255 - if is_running; then
256 - echo "Not stopped; may still be shutting down or shutdown may have failed"
257 - exit 1
258 - else
259 - echo "Stopped"
260 - if [ -f "$pid_file" ]; then
261 - rm "$pid_file"
262 - fi
263 - fi
264 - else
265 - echo "Not running"
266 - fi
268 -restart() {
269 - stop
270 - if is_running; then
271 - echo "Unable to stop, will not attempt to start"
272 - exit 1
273 - fi
274 - start
278 2.45.2