-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (53 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* @Author: 杨小灿[email protected]
* @Date: 2023-04-01 13:12:07
* @LastEditors: 杨小灿[email protected]
* @LastEditTime: 2023-04-03 22:45:00
*/
package main
import (
"os"
"os/signal"
"syscall"
"github.com/jian308/canclone/clone"
"github.com/jian308/canclone/webapi"
"github.com/jian308/go/conf"
"github.com/jian308/go/log"
"go.uber.org/zap/zapcore"
)
func main() {
conf.Auto() //加载配置文件
if conf.Get("clone.debug") != nil && conf.Get("clone.debug").(bool) {
log.SetLevel(zapcore.DebugLevel)
} else {
log.SetLevel(zapcore.InfoLevel)
}
//启动接口服务
go webapi.WebNew()
//开启文件同步系统
go clone.New()
log.Info("服务启动成功!")
//优雅关闭开启的服务
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
siger := <-c
if siger == syscall.SIGINT {
//方便调试的时候直接关闭
log.Infof("ctrl+c直接关闭:%d", syscall.Getpid())
if err := clone.Close(); err != nil {
log.Error(err)
}
os.Exit(0)
}
if siger == syscall.SIGTERM {
log.Infof("开启无忧关闭...等待处理完请求将关闭进程id:%d", syscall.Getpid())
//app.Shutdown()会等待一个新请求处理完后关闭
if err := webapi.WebStop(); err != nil {
log.Error(err)
}
if err := clone.Close(); err != nil {
log.Error(err)
}
log.Info("成功关闭!")
}
}