shell 指令碼批量啟動docker內部應用
阿新 • • 發佈:2018-11-01
起因;
內網機房斷電,執行在虛擬機器之上的docker 應用還得手動觸發重啟,實在太費勁,針對此應用場景進行shell 指令碼編寫;
#/bin/bash #author lijx #用於docker 斷電啟動,Docker 內程式應用指令碼 function Start_chehejia_app(){ docker_name=$1 app_name=$2 app_ops_operaiton=$3 abc=$(docker exec -it $docker_name su - work -c "/chj/app/$app_name/bin/console $app_ops_operaiton") } function Get_docker_app_name(){ ops_oper=$1 for i in ` docker ps -a |awk '{if ($8=="Up") print $NF}'|grep -v "CONTAINER"|grep -v "^$"` do relult=$(docker exec -it $i ls -lrt /chj/app/ |tail -1|awk '{print $9}'|tr -d "\r") Start_chehejia_app $i $relult $ops_oper done } case "$1" in start) echo -e "\033[32m 應用啟動 \033[0m" ops_operation="start" Get_docker_app_name $ops_operation $1 ;; stop) echo -e "\033[32m 應用停止 \033[0m" ops_operation="stop" Get_docker_app_name $ops_operation $1 ;; restart) echo -e "\033[32m 應用重啟 \033[0m" ops_operation="stop" Get_docker_app_name $ops_operation $1 ;; status) ops_operation="status" echo -e "\033[32m 檢查程式 \033[0m" Get_docker_app_name $ops_operation ;; *) echo -e '\033[31m Docker內部應用管理,請輸入 "$"Usage: $0 {status|start|stop|restart}" \033[0m' exit 2 esac 使用方法; [[email protected] devops]# sh chj_power_repaoir.sh 以下提示引數如 (status) Docker內部應用管理,請輸入 "$"Usage: $0 {status|start|stop|restart}"