原由;docker
內網機房斷電,運行在虛擬機之上的docker 應用還得手動觸發重啓,實在太費勁,針對此應用場景進行shell 腳本編寫;
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 使用方法; [root@docker-agent-dev-20180712-02 devops]# sh chj_power_repaoir.sh 如下提示參數如 (status) Docker內部應用管理,請輸入 "$"Usage: $0 {status|start|stop|restart}"