start.sh
1.07 KB
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
#!/bin/bash
# 服务启动脚本
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR" || exit
source "${SCRIPT_DIR}/config.sh"
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
}
log "Starting $SERVICE_NAME service..."
# 检查是否已经运行
if systemctl is-active --quiet "$SERVICE_NAME"; then
log "Service $SERVICE_NAME is already running"
exit 0
fi
# 启动主服务
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
# 启动健康检查服务
sudo systemctl enable "health-check-${SERVICE_NAME}"
sudo systemctl start "health-check-${SERVICE_NAME}"
# 检查服务启动状态
if systemctl is-active --quiet "$SERVICE_NAME"; then
log "Service $SERVICE_NAME started successfully"
else
log "Failed to start service $SERVICE_NAME"
exit 1
fi
# 检查健康检查服务启动状态
if systemctl is-active --quiet "health-check-${SERVICE_NAME}"; then
log "Health check service started successfully"
else
log "Warning: Failed to start health check service"
fi
log "Service startup process completed"
exit 0