这个自制的 systemd 服务在 CentOS 8.3 上为什么会失败,提示“Failed with result 'protocol'”?

这个自制的 systemd 服务在 CentOS 8.3 上为什么会失败,提示“Failed with result 'protocol'”?

首先,这个问题只在 CentOS8 上出现,而在 CentOS7 上则运行正常。这是版本:

# cat /etc/redhat-release
CentOS Linux release 8.3.2011

我尝试创建一个服务来执行 bash 命令来更改路由。这是可执行的 bash /root/route_degrade.sh

#!/bin/bash
# ensure router role
echo "1" > /proc/sys/net/ipv4/ip_forward
systemctl start firewalld
firewall-cmd --add-masquerade
#firewall-cmd --add-port=1194/udp
firewall-cmd --add-service=openvpn

# degrade original default router to LAN only router
cloudroute=$(ip route | grep default | cut -d " " -f 3)
if [[ $cloudroute == 10.* ]]; then
  ip route add 10.0.0.0/8 via $cloudroute
  ip route del default
fi
exit 0

这个可执行文件绝对没问题,因为我确实在根目录中单独执行了它./route_degrade.sh

以下autoinit.service/usr/lib/systemd/system

[Unit]
Description=Changes Default route to Route within cloud Permanently
After=firewalld.service
#Before=openvpn@Client_d.service


[Service]
Type=notify
ExecStart=/root/route_degrade.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

但它仍然失败,即使在我重新加载服务文件systemctl daemon-reload并重新启动它之后,状态如下systemd

● autoinit.service - Changes Default route to Route within cloud Permanently
   Loaded: loaded (/usr/lib/systemd/system/autoinit.service; disabled; vendor preset: disabled)
   Active: failed (Result: protocol) since Sat 2022-03-26 17:03:18 CST; 17s ago
  Process: 6924 ExecStart=/root/route_degrade.sh (code=exited, status=0/SUCCESS)
 Main PID: 6924 (code=exited, status=0/SUCCESS)

Mar 26 17:03:17 10-13-107-213 systemd[1]: Starting Changes Default route to Route within cloud Permanently...
Mar 26 17:03:17 10-13-107-213 route_degrade.sh[6924]: Warning: ALREADY_ENABLED: masquerade already enabled in 'public'
Mar 26 17:03:17 10-13-107-213 route_degrade.sh[6924]: success
Mar 26 17:03:18 10-13-107-213 route_degrade.sh[6924]: Warning: ALREADY_ENABLED: 'openvpn' already in 'public'
Mar 26 17:03:18 10-13-107-213 route_degrade.sh[6924]: success
Mar 26 17:03:18 10-13-107-213 systemd[1]: autoinit.service: Failed with result 'protocol'.
Mar 26 17:03:18 10-13-107-213 systemd[1]: Failed to start Changes Default route to Route within cloud Permanently.

我不知道哪里出了问题,显然它确实执行了 bash 脚本,并且命令firewall-cmd被抛出success,并且它捕获了退出代码 0。那么这是什么Failed with result 'protocol'意思呢?

相关内容