从systemd处理(重新)启动Docker容器意外退出

我有一个docker集装箱。在linux服务器docker容器的重新启动过程中,因此在systemd中停止了脚本文件,为容器重新启动添加脚本文件。此脚本也停止了chef-client。 但是脚本只执行了一半的命令。我不知道为什么在主客户端停止之后它会停止。之后它不会继续。

重新启动脚本:

[root@server01 user1]# more /apps/service-scripts/docker-container-restart.sh #!/bin/bash echo "Starting to stop the chef-client automatic running.." service chef-client stop echo "Completed the stopping the chef-client automatic running" echo "Restart check... the Applicaiton Container $(date)" IsAppRunning=$(docker inspect -f '{{.State.Running}}' app-prod) echo "IsAppRunning state $IsAppRunning" if [ "$IsAppRunning" != "true" ]; then IsAppRunning=$(docker inspect -f '{{.State.Running}}' app-prod) echo "Restarting.... the Applicaiton Container $(date)" docker restart app-prod IsAppRunning=$(docker inspect -f '{{.State.Running}}' app-prod) echo "Restart completed($IsAppRunning) the Applicaiton Container $(date)" else echo "Restart is not required, app is already up and running" fi 

Systemctl日志:

 [root@server01 user1] systemctl status app-docker-container.service ● app-docker-container.service - Application start Loaded: loaded (/etc/systemd/system/app-docker-container.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2017-09-24 16:00:40 CDT; 18h ago Main PID: 1187 (docker-container-restart) Memory: 16.4M CGroup: /system.slice/app-docker-container.service ├─1187 /bin/bash /apps/service-scripts/docker-container-restart.sh └─1220 docker inspect -f {{.State.Running}} app-prod Sep 24 16:00:40 server01 systemd[1]: Started Application start. Sep 24 16:00:40 server01 systemd[1]: Starting Application start... Sep 24 16:00:40 server01 docker-container-restart.sh[1187]: Starting to stop the chef-client automatic running.. Sep 24 16:00:41 server01 docker-container-restart.sh[1187]: Redirecting to /bin/systemctl stop chef-client.service Sep 24 16:00:41 server01 docker-container-restart.sh[1187]: Completed the stopping the chef-client automatic running Sep 24 16:00:41 server01 docker-container-restart.sh[1187]: Restart check... the Applicaiton Container Sun Sep 24 16:00:41 CDT 2017 

SystemD:

 [root@server01 user1]# more /etc/systemd/system/app-docker-container.service [Unit] Description=Application start After=docker.service,chef-client.service [Service] Type=simple ExecStart=/apps/service-scripts/docker-container-restart.sh [Install] WantedBy=multi-user.target