有个机器上的服务可能会炸掉,在修复之前直接重启。懂不懂let it crash.哲学
bash
#!/bin/bash
PORT=端口
SERVICE_NAME=服务名称
if ! nc -z localhost $PORT; then
echo "Port $PORT is not active. Attempting to start $SERVICE_NAME..."
systemctl start $SERVICE_NAME
if systemctl is-active --quiet $SERVICE_NAME; then
echo "$SERVICE_NAME has been started successfully."
else
echo "Failed to start $SERVICE_NAME."
fi
else
echo "Port $PORT is active."
fi