start.sh 1.07 KB
#!/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