monitoring shell script, will be achieved through while true, did not use crontab
#!/bin/bash source /etc/profile appname = aurora-gateway-provider-1.3.1_build2.jar # [] displayed process name jps [App_script with the parent directory, and start-up mode, such as aurora-gateway startup mode is sh sbin / app.sh start] app_path = / opt / workspace / aurora-gateway / # app_script = app.sh # [startup script] # No need to modify the following function monitor() { monitorOutputLog=/data/aurora-gateway/logs/monitor/$(date '+%Y%m%d').log if [ ! -f "$monitorOutputLog" ];then touch "$monitorOutputLog" be pid = $ (jps | awk -v var = $ appname '{if ($ 2 ~ var) print $ 1}') #awk -v shows a shell variables introduced appname awk expression; {if ($ 2 ~ var) print $ 1} judgment is not similar, like printing pid if (kill -0 $ pid 2> / dev / null); then # kill -0 $ pid:? pid process to check whether there is, echo $ exists 0 is returned; there is no return 1; 2> / dev / null: representation does not output an error message echo "$(date '+%Y-%m-%d %H:%M:%S') $appname is running" >> $monitorOutputLog sleep 15 #sleep 15秒 else cd $app_path && sh sbin/$app_script start pid = $ (jps | awk -v var = $ appname '{if ($ 2 ~ var) print $ 1}') if (kill -0 $pid 2>/dev/null);then echo "$ (date '+% Y-% m-% d% H:% M:% S') $ appname started successfully" >> $ monitorOutputLog sleep 15 else echo "$ (date '+% Y-% m-% d% H:% M:% S') $ appname failed to start" >> $ monitorOutputLog sleep 15 be be } while true do monitor done # Steps for usage: # [root] mkdir -p /data/aurora-gateway/logs/monitor/ # [root] chown deploy:deploy /data/aurora-gateway/logs/monitor/ # Copy aurora_gateway_monitor.sh to the / opt / workspace / aurora-gateway / directory # [root] chown deploy:deploy /opt/workspace/aurora-gateway/aurora_gateway_monitor.sh # chmod +x /opt/workspace/aurora-gateway/aurora_gateway_monitor.sh # [Root] su - deploy # cd /opt/workspace/aurora-gateway/ # ./aurora_gateway_monitor.sh& # Check whether the log normal output