Use trap in shell scripts
· One min read
docker run -d --name gs2 -p 9000-9009:9000-9009/tcp -v /root/real-gameserver/config:/opt/q1game/config 172.16.127.171:10001/gserver-allinone:0.0.1 /bin/bash -c 'cd control;./startAll.sh;trap "echo [`date --iso-8601=seconds`] WARNING Game Server will be stopped after 5 seconds;trap - SIGTERM;sleep 5;echo [`date --iso-8601=seconds`] WARNING Stopping the Game Server...;./stop.sh;exit 0" SIGTERM;while true;do echo "[`date --iso-8601=seconds`] Game Server(Game Id: ${GAMD_ID}, Region Id: ${REGION_ID}, Area Id: ${AREA_ID}, World Id: ${WORLD_ID}) running...";sleep 5;done'
docker stop gs2 -t 120
