49 lines
1.7 KiB
Bash
Executable File
49 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Usage: $0 [start|stop|logs|restart|status|reload|connections]"
|
|
exit 1
|
|
fi
|
|
|
|
source docker.conf
|
|
export WORKERMAN_CONTAINER_NAME=$container_name
|
|
export WORKERMAN_IMAGE_VERSION=$image_version
|
|
|
|
if [ "$1" = "stop" ]; then
|
|
if [ "$(docker inspect -f {{.State.Running}} $WORKERMAN_CONTAINER_NAME 2>/dev/null)" = "true" ]; then
|
|
docker stop $WORKERMAN_CONTAINER_NAME
|
|
else
|
|
echo "Container $WORKERMAN_CONTAINER_NAME is not running."
|
|
fi
|
|
else
|
|
# 判断容器是否存在
|
|
if [ ! "$(docker ps -a -q -f name=$WORKERMAN_CONTAINER_NAME)" ]; then
|
|
# 调用init脚本
|
|
./init
|
|
fi
|
|
# 判断容器是否在运行
|
|
if [ ! "$(docker inspect -f {{.State.Running}} $WORKERMAN_CONTAINER_NAME 2>/dev/null)" = "true" ]; then
|
|
# 启动容器
|
|
docker start $WORKERMAN_CONTAINER_NAME
|
|
fi
|
|
if [ "$1" = "logs" ]; then
|
|
docker logs -f $WORKERMAN_CONTAINER_NAME
|
|
elif [ "$1" = "start" ]; then
|
|
docker exec -itd $WORKERMAN_CONTAINER_NAME bash -c "php start.php start"
|
|
elif [ "$1" = "restart" ]; then
|
|
docker exec -itd $WORKERMAN_CONTAINER_NAME bash -c "php start.php restart"
|
|
elif [ "$1" = "status" ]; then
|
|
docker exec -it $WORKERMAN_CONTAINER_NAME bash -c "php start.php status"
|
|
elif [ "$1" = "reload" ]; then
|
|
docker exec -it $WORKERMAN_CONTAINER_NAME bash -c "php start.php reload"
|
|
elif [ "$1" = "connections" ]; then
|
|
docker exec -it $WORKERMAN_CONTAINER_NAME bash -c "php start.php connections"
|
|
else
|
|
echo "Invalid command"
|
|
echo "Usage: $0 [start|stop|logs|restart|status|reload|connections]"
|
|
exit 1
|
|
fi
|
|
fi
|