67 lines
1.8 KiB
Bash
67 lines
1.8 KiB
Bash
#!/bin/sh
|
|
|
|
# Restart the shipping service
|
|
|
|
# 获取命令行参数
|
|
if [ $# -ne 1 ]; then
|
|
echo "Usage: $0 [start|stop|status|restart]"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" = "start" ]; then
|
|
echo "Starting shipping_service..."
|
|
mkdir -p log
|
|
: > log/shipping_service.log
|
|
nohup ./shipping_service >> log/shipping_service.log 2>&1 &
|
|
echo "shipping_service started."
|
|
elif [ "$1" = "stop" ]; then
|
|
echo "Stopping shipping_service..."
|
|
# ...existing code...
|
|
PID=$(ps -ef | grep '[s]hipping_service' | awk '{print $2}')
|
|
if [ -z "$PID" ]; then
|
|
echo "shipping_service is not running."
|
|
exit 1
|
|
fi
|
|
kill "$PID"
|
|
# 等待优雅退出,最多 5 秒,超时则强制杀死
|
|
COUNT=0
|
|
while [ $COUNT -lt 5 ]; do
|
|
sleep 1
|
|
if ! ps -p "$PID" > /dev/null 2>&1; then
|
|
break
|
|
fi
|
|
COUNT=$((COUNT+1))
|
|
done
|
|
if ps -p "$PID" > /dev/null 2>&1; then
|
|
kill -9 "$PID"
|
|
fi
|
|
echo "shipping_service stopped."
|
|
elif [ "$1" = "status" ]; then
|
|
echo "shipping_service status:"
|
|
PID=$(ps -ef | grep '[s]hipping_service' | awk '{print $2}')
|
|
if [ -z "$PID" ]; then
|
|
echo "shipping_service is not running."
|
|
else
|
|
echo "shipping_service is running."
|
|
fi
|
|
elif [ "$1" = "restart" ]; then
|
|
echo "Restarting login..."
|
|
PID=$(ps -ef | grep '[s]hipping_service' | awk '{print $2}')
|
|
if [ -n "$PID" ]; then
|
|
echo "shipping_service stopping."
|
|
kill "$PID"
|
|
fi
|
|
while :; do
|
|
PID=$(ps -ef | grep '[s]hipping_service' | awk '{print $2}')
|
|
[ -z "$PID" ] && break
|
|
sleep 1
|
|
done
|
|
echo "shipping_service stopped."
|
|
mkdir -p log
|
|
: > log/shipping_service.log
|
|
nohup ./shipping_service >> log/shipping_service.log 2>&1 &
|
|
echo "shipping_service restarted."
|
|
else
|
|
echo "Usage: $0 [start|stop|status|restart]"
|
|
exit 1
|
|
fi |