Skip to content

Commit bb2a642

Browse files
xjxiaiSecloud
authored andcommitted
feat(backend): optimize dbha crontab and Makefile close #11320
1 parent d7bdabe commit bb2a642

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

dbm-services/common/dbha/ha-module/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ SHELL := /bin/bash
22
BASE_DIR = $(shell pwd)
33
VERSION = $(shell git describe --tags --always --dirty)
44
GITHASH = $(shell git rev-parse --short HEAD)
5+
BUILDTIME = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
56
APPNAME = dbha
67
GOOS ?= linux
7-
BUILD_FLAG = " -X main.version=${VERSION} -X main.githash=${GITHASH} "
8-
BUILD_MINI_FLAG = " -s -w -X main.version=${VERSION} -X main.githash=${GITHASH} "
8+
BUILD_FLAG = " -X main.version=${VERSION} -X main.githash=${GITHASH} -X main.buildTime=${BUILDTIME}"
9+
BUILD_MINI_FLAG = " -s -w -X main.version=${VERSION} -X main.githash=${GITHASH} -X main.buildTime=${BUILDTIME}"
910

1011
.PHONY: build mini clean gotool image
1112

dbm-services/common/dbha/ha-module/dbha.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"time"
78

89
"dbm-services/common/dbha/ha-module/agent"
910
"dbm-services/common/dbha/ha-module/config"
@@ -20,6 +21,7 @@ var configFile string
2021
var showVersion bool
2122
var version = "1.0.0"
2223
var githash = "unknown"
24+
var buildStamp = time.Now().Format("2006-01-02 15:04:05")
2325

2426
// Init TODO
2527
func Init() {
@@ -35,6 +37,7 @@ func main() {
3537
if showVersion {
3638
fmt.Println("Version:", version)
3739
fmt.Println("Git hash info:", githash)
40+
fmt.Println("BuildTime:", buildStamp)
3841
os.Exit(0)
3942
}
4043

dbm-ui/backend/flow/utils/cloud/script_template/dbha_template.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
ha_gm_conf_template = """
1414
log_conf:
15-
log_path: "./log"
15+
log_path: "./log/log"
1616
log_level: "LOG_DEBUG"
1717
log_maxsize: 512
1818
log_maxbackups: 1000
@@ -154,7 +154,7 @@
154154

155155
ha_agent_conf_template = """
156156
log_conf:
157-
log_path: "./log"
157+
log_path: "./log/log"
158158
log_level: "LOG_DEBUG"
159159
log_maxsize: 512
160160
log_maxbackups: 1000
@@ -303,6 +303,7 @@
303303
304304
# 准备相关文件
305305
mkdir -p $path/dbha/{{dbha_type}};
306+
mkdir -p $path/dbha/{{dbha_type}}/log;
306307
cp /data/install/{{dbha_conf}} $path/dbha/{{dbha_type}};
307308
cp /data/install/dbha $path/dbha/{{dbha_type}};
308309
chmod -R 777 $path/dbha;
@@ -317,23 +318,28 @@
317318
echo "----------------------------------------------------------------";
318319
319320
# 增加定期拉起任务
320-
dbha_cron="$path/dbha/{{dbha_type}}/cron.sh";
321+
dbha_cron="$path/dbha/{{dbha_type}}/check_agent_alive.sh";
321322
echo -e "
322-
# 检查进程是否存在
323-
is_process_running() {
324-
ps aux | grep {{dbha_conf}} | grep -v grep | awk '{print \$2}' > /dev/null
323+
#!/bin/sh
324+
LOG="/var/log/dbha_watchdog.log"
325+
326+
cd $path/dbha/{{dbha_type}} || {
327+
echo "$(date) [ERROR] dbha work directory not exist" >> $LOG
328+
exit 1
325329
}
326-
if ! is_process_running; then
327-
echo "Process {{dbha_type}} is not running. Restarting..."
328-
cd /usr/local/bkdb/dbha/{{dbha_type}}
329-
# 启动进程的命令
330-
nohup ./dbha -config_file=ha-{{dbha_type}}.conf -type={{dbha_type}} -> dbha-apply.log 2>&1 &
331-
echo "Process {{dbha_type}} restarted successfully."
330+
331+
if ! ps -ef|grep "dbha -config_file={{dbha_conf}}"|grep -v grep; then
332+
echo "$(date) [ERROR] dbha process not found" >> $LOG
333+
if nohup ./dbha -config_file={{dbha_conf}} -type={{dbha_type}} - >> runtime.log 2>&1 & then
334+
echo "$(date) [OK] restart ok PID:$!" >> $LOG
335+
else
336+
echo "$(date) [FAIL] restart failed" >> $LOG
337+
fi
332338
fi
333339
" > $dbha_cron
334340
335341
chmod +x $dbha_cron;
336-
(crontab -l ; echo "* * * * * $dbha_cron") 2>&1 | grep -v "no crontab" | sort | uniq | crontab -
342+
(crontab -l ; echo "*/3 * * * * $dbha_cron > /dev/null 2>&1") 2>&1 | grep -v "no crontab" | sort | uniq | crontab -
337343
"""
338344

339345
dbha_stop_script_template = """

0 commit comments

Comments
 (0)