以 jupyter 服务为例
1、检测脚本
vim /home/ailab/bin/check_ailab.sh
#!/bin/bashPID=$(ps -ef|grep -v grep|grep "jupyter" |awk '{print $2}')# 检查进程是否存在
if [ -z "$PID" ]; then# 进程不存在,启动进程echo "Jupyter Notebook is not running. Starting it..."# 这里替换为你启动进程的命令/data1/ailab/run/start.sh &
else# 进程存在,输出进程ID# echo -e "Jupyter Notebook is running with PID: \n${PID}"echo "Jupyter Notebook is running with PID: ${PID}"
fi
2、定时任务 Crontab
每分钟检测一次,也可以设置每秒检测一次
[ailab@localhost ~]$ crontab -l
* * * * * /home/ailab/bin/check_ailab.sh
[ailab@localhost ~]$
我们下期见,拜拜!