Skip to content

Commit

Permalink
Add option to exit when disconnected from remote
Browse files Browse the repository at this point in the history
close #7
  • Loading branch information
zyxkad committed Feb 5, 2024
1 parent b391239 commit 6ddcc87
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ debug: false
record_serve_info: false
# 跳过第一次同步, 直接启动节点 (debug用)
skip-first-sync: false
# 是否在连接断开后直接退出
exit-when-disconnected: false
# 日志最长保存时间 (天). 设置为 0 禁用清理过期日志
log-slots: 7
# 是否禁用 bmclapi 分发的证书, 同 CLUSTER_BYOC
Expand Down
5 changes: 4 additions & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ func (cr *Cluster) Connect(ctx context.Context) bool {
os.Exit(1)
}
engio.OnDisconnect(func(_ *engine.Socket, err error) {
if config.ExitWhenDisconnected {
logErrorf("Cluster disconnected from remote; exit.")
os.Exit(0x08)
}
go cr.disconnected()
logErrorf("Disconnected: %v", err)
})
engio.OnRecv(func(_ *engine.Socket, data []byte) {
logDebugf("Engine.IO recv: %q", (string)(data))
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Config struct {
Debug bool `yaml:"debug"`
RecordServeInfo bool `yaml:"record_serve_info"`
SkipFirstSync bool `yaml:"skip-first-sync"`
ExitWhenDisconnected bool `yaml:"exit-when-disconnected"`
LogSlots int `yaml:"log-slots"`
Byoc bool `yaml:"byoc"`
NoOpen bool `yaml:"noopen"`
Expand Down Expand Up @@ -100,6 +101,7 @@ var defaultConfig = Config{
Debug: false,
RecordServeInfo: false,
SkipFirstSync: false,
ExitWhenDisconnected: false,
LogSlots: 7,
Byoc: false,
NoOpen: false,
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
debug: false
record_serve_info: false
skip-first-sync: false
exit-when-disconnected: false
log-slots: 7
byoc: false
noopen: false
Expand Down

0 comments on commit 6ddcc87

Please sign in to comment.