Skip to content

Commit 4185485

Browse files
committed
refactor(main): extract signal helper func
1 parent cffdb4a commit 4185485

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/main.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,9 @@ import (
88
"mjpclab.dev/ghfs/src/serverLog"
99
"mjpclab.dev/ghfs/src/setting"
1010
"mjpclab.dev/ghfs/src/version"
11-
"os"
12-
"os/signal"
1311
"strconv"
14-
"syscall"
1512
)
1613

17-
func cleanupOnEnd(appInst *app.App) {
18-
chSignal := make(chan os.Signal)
19-
signal.Notify(chSignal, syscall.SIGINT, syscall.SIGTERM)
20-
21-
go func() {
22-
<-chSignal
23-
appInst.Shutdown()
24-
}()
25-
}
26-
27-
func reInitOnHup(appInst *app.App) {
28-
chSignal := make(chan os.Signal)
29-
signal.Notify(chSignal, syscall.SIGHUP)
30-
31-
go func() {
32-
for range chSignal {
33-
errs := appInst.ReOpenLog()
34-
if serverError.CheckError(errs...) {
35-
appInst.Shutdown()
36-
break
37-
}
38-
errs = appInst.ReLoadCertificates()
39-
if serverError.CheckError(errs...) {
40-
appInst.Shutdown()
41-
break
42-
}
43-
}
44-
}()
45-
}
46-
4714
func Main() (ok bool) {
4815
// params
4916
params, printVersion, printHelp, errs := param.ParseFromCli()

src/signal.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package src
2+
3+
import (
4+
"mjpclab.dev/ghfs/src/app"
5+
"mjpclab.dev/ghfs/src/serverError"
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
)
10+
11+
func cleanupOnEnd(appInst *app.App) {
12+
chSignal := make(chan os.Signal)
13+
signal.Notify(chSignal, syscall.SIGINT, syscall.SIGTERM)
14+
15+
go func() {
16+
<-chSignal
17+
appInst.Shutdown()
18+
}()
19+
}
20+
21+
func reInitOnHup(appInst *app.App) {
22+
chSignal := make(chan os.Signal)
23+
signal.Notify(chSignal, syscall.SIGHUP)
24+
25+
go func() {
26+
for range chSignal {
27+
errs := appInst.ReOpenLog()
28+
if serverError.CheckError(errs...) {
29+
appInst.Shutdown()
30+
break
31+
}
32+
errs = appInst.ReLoadCertificates()
33+
if serverError.CheckError(errs...) {
34+
appInst.Shutdown()
35+
break
36+
}
37+
}
38+
}()
39+
}

0 commit comments

Comments
 (0)