unix - 如果 Unix 进程关闭,它会自行启动
问题描述
设想:
我有 UNIX 进程 myshellscript.sh ,如果 sh 脚本没有运行或停止,我希望重新启动该进程。
注意:不想使用 crontab
解决方案
如果进程因任何原因关闭,shell 脚本将在 5 秒内重新启动。
01.在/etc/systemd/system/中添加服务
例子:
vi /etc/systemd/system/myshellscript.service
[Unit]
Description = SH Script
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5s
ExecStart = sh /resource_path/myshellscript.sh
[Install]
WantedBy=multi-user.target
02.创建命令后执行以下命令
systemctl daemon-reload
systemctl enable myshellscript.service
systemctl restart myshellscript.service
推荐阅读
- security - 保存 RSA 私钥
- python - Otreeを使用してエラーをカウントする
- java - 为什么 return 语句不退出 while 循环,而是返回到 while 循环的第一行?
- java - 将多个数组写入 Arraylist
- c++ - 从 C++ 更新 QML 对象的正确方法?
- python - 如何在seaborn的散点图中设置顶部(重叠)的色调
- python - 分配前引用的变量,但已正确分配
- python - 熊猫数据帧之间的 if 和语句
- python - 为什么函数调用在字典中的python中不起作用
- javascript - 无法删除/更新 ajax laravel 中的新项目