ScenarioThe company project is deployed in Docker. Due to unknown reasons, the container occasionally stops. It is necessary to write a script to monitor the running status of the container. If the container stops, start the container again. Shell Script#!/bin/bash # Pass in the container name containerName=$1 currTime=`date +"%Y-%m-%d %H:%M:%S"` # Check if the process exists=`docker inspect --format '{{.State.Running}}' ${containerName}` if [ "${exist}" != "true" ]; then docker start ${containerName} # Record echo "${currTime} restart docker container, container name: ${containerName}" >> /mnt/xvde1/ms_ctynyd/scripts/wbwf_monitor.log fi Scheduled tasks crontabcrontab -e to edit Linux scheduled tasks # Monitor docker 8081 container*/1 * * * * sh /mnt/xvde1/ms_ctynyd/scripts/wbwf_monitor.sh server_wbwf_wbwf-app_1 # Monitor docker 7081 container*/1 * * * * sh /mnt/xvde1/ms_ctynyd/scripts/wbwf_monitor.sh server_hb_hb-test-app_1 Supplement: Shell script determines whether a service is running Shell script to determine whether a service is enabled The script is as follows:#!/bin/bash #Check the service status to see if it is installed read -p "Please enter the service to be tested:" SERVICE netstat -anp | grep $SERVICE &> /dev/null if [ $? -eq 0 ] then echo "$SERVICE service has been started!" else rpm -q $SERVICE &> /dev/null if [ $? -eq 0 ] then echo "$SERVICE service has been installed and is starting...." service $SERVICE start else echo "The service is not installed!" fi fi The results are as follows:The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
<<: Web development tutorial cross-domain solution detailed explanation
>>: The difference between html block-level tags and inline tags
Vue stores storage with Boolean values I encounte...
Table of contents Linux 1. Basic use of crontab 2...
Preface This article mainly introduces the soluti...
1. Upload rz to the server and decompress it rz [...
The steps are as follows 1. Create a docker group...
Preface As we all know, the browser's homolog...
https://docs.microsoft.com/en-us/windows/wsl/wsl-...
Add the following code to the CSS style of the el...
Use JS to implement a random roll call system for...
This article shares the specific code of Navicat ...
The progress bar is not smooth I believe that mos...
The web pinball game implemented using javeScript...
1. Operating Environment vmware14pro Ubuntu 16.04...
background I am learning nodejs recently, and I r...
Pessimistic Lock Pessimistic lock, considers the ...