首页 > 解决方案 > update-rc.d:错误:防火墙默认启动不包含运行级别,正在中止

问题描述

我正在尝试添加一项服务,以便它在启动时启动但不可能,我收到以下错误

$ sudo systemctl enable firewall.service

Synchronizing state of firewall.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable firewall
update-rc.d: error: firewall Default-Start contains no runlevels, aborting
# /etc/systemd/system/firewall.service
[Unit]
ConditionPathExists=/etc/init.d/firewall
after=network.target

[Service]
ExecStart=/etc/init.d/firewall

[Install]
WantedBy=multi-user.target

标签: linuxsystemctl

解决方案


编辑您的防火墙文件并将其添加到开头

### BEGIN INIT INFO
# Provides:          firewall
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: your description here
### END INIT INFO

将文件移动到正确的目录

mv /etc/init.d/firewall  /etc/systemd/system/firewall

在 /lib/systemd/system/ 中创建 firewall.service 文件

> /lib/systemd/system/firewall.service

您的 firewall.service 文件应该包含这个

 [Unit]
 Description=Firewall

 [Service]
 Type=simple
 RemainAfterExit=yes
 ExecStart=/etc/systemd/system/firewall start
 ExecStop=/etc/systemd/system/firewall stop
 ExecReload=/etc/systemd/system/firewall restart

 [Install]
 WantedBy=multi-user.target

重新加载 systemd 管理器配置并启用防火墙

systemctl daemon-reload
systemctl enable firewall

推荐阅读