#for private
# bash docker_restart.sh /data/mdx
set -x
DOCKER_IMAGE_NAME=keyfunc.tencentcloudcr.com/prod/mdx
version=`cat VERSION`
DOCKER_IMAGE_VERSION=${version:1:7}
MDX_DATA=$1

docker ps | grep mdx_only
if [[ $? == 0 ]];then
  echo 'del docker'
  docker ps -a | tail -n+2 | grep mdx_only | awk '{print $1}' | xargs docker stop
  docker ps -a | tail -n+2 | grep mdx_only | awk '{print $1}' | xargs docker rm
fi

cp server_${DOCKER_IMAGE_VERSION} VERSION ${MDX_DATA}
# dockerid=`docker ps -a | tail -n+2 | grep mdx_only | awk '{print $1}'`
# echo "docker to rm $dockerid"
# if [ $dockerid ];then 
#    docker stop $dockerid
#    docker rm $dockerid
#    #ensure we use latest image
#    #docker rmi ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}
#    echo "docker del done"
# fi
#docker run -d --name mdx_only1 --restart=always --ulimit stack=102400:102400 -v /data_disk/pg_data/mdx/config.json:/home/mdx/config.json -p 9010:9019 keyfunc.tencentcloudcr.com/test/mdx:667b1ed
docker run -d --name mdx_only --restart=always --ulimit stack=-1 -v ${MDX_DATA}/server_${DOCKER_IMAGE_VERSION}:/home/mdx/build/server/server -v ${MDX_DATA}/VERSION:/home/mdx/VERSION -v ${MDX_DATA}:/tmp -v ${MDX_DATA}/config.json:/home/mdx/config.json -p 9010:9019 ${DOCKER_IMAGE_NAME}:418c1a5