fix: deploy.sh 容器未运行时自动启动,避免无变更时跳过启动

This commit is contained in:
fawney19
2026-02-07 14:53:46 +08:00
parent 02906dad0e
commit 3b8398b2e5

View File

@@ -256,10 +256,19 @@ else
echo ">>> Code unchanged."
fi
# 只在有变化时重启
# 检查容器是否在运行
CONTAINERS_RUNNING=true
if [ -z "$($DC ps -q 2>/dev/null)" ]; then
CONTAINERS_RUNNING=false
fi
# 有变化时重启,或容器未运行时启动
if [ "$NEED_RESTART" = true ]; then
echo ">>> Restarting services..."
$DC up -d
elif [ "$CONTAINERS_RUNNING" = false ]; then
echo ">>> Containers not running, starting services..."
$DC up -d
else
echo ">>> No changes detected, skipping restart."
fi