Unix进程在关闭时自行启动

Unix进程在关闭时自行启动,unix,Unix,情景: 我有UNIX进程myshellscript.sh,无论出于何种原因,如果sh脚本没有运行或停止,我希望该进程重新启动 注意:不想使用crontab如果进程因任何原因关闭,shell脚本将在5秒内重新启动。 01。在/etc/systemd/system中添加服务/ 例如: 02。创建命令后,执行以下命令 vi /etc/systemd/system/myshellscript.service [Unit] Description = SH Script After=network-on

情景:

我有UNIX进程myshellscript.sh,无论出于何种原因,如果sh脚本没有运行或停止,我希望该进程重新启动

注意:不想使用crontab

如果进程因任何原因关闭,shell脚本将在5秒内重新启动。 01。在/etc/systemd/system中添加服务/

例如:

02。创建命令后,执行以下命令

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
systemctl daemon-reload
systemctl enable myshellscript.service
systemctl restart myshellscript.service