Error one:
: Failed to start /etc/rc.local Compatibility.7月 07 09:40:03Ubuntusystemd[1]: rc-local.service: Unit entered failed state.7月 07 09:40:03Ubuntu systemd[1]: rc-local.service: Failed with result 'exit-code'
According to the general investigation, check whether the contents of the rc-local.service file and the rc.local file are written incorrectly, add exit 0, change #!/bin/bash, etc. in the script, it will not work after the replacement, and see that there is no such in the error The prompt of file may be related to the unsuccessful identification and loading of the file. The format under ubuntu is changed to unix format. In general, you can download dos2unix with sudo apt install dos2unix
Then run dos2unix xx.sh (or rc.local and other files) for the sh file you want to run, which is to convert the file format to unix
Re-execute the steps of error 2
Mistake 2: (In fact, the wrong file in step 1 was not completely deleted, just change the format and do it once)
sudo systemctl disable rc-local
Failed to disable unit: Refusing to operate on alias name or linked unit
delete /usr/lib/systemd/system/rc-local.servive /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
Use dos2unix again to convert the rc-local.service file to the format dos2unix and press Enter to add the file name
Copy the new rc-local.service file to /lib/systemd/system/ above
relink
sudo ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/
If you are not at ease, re-authorize the /etc/rc.local file chmod +x /etc/rc.local
Rejoin the system service
sudo systemctl enable rc-local #This statement is to create a hyperlink in the system startup service program.
sudo systemctl daemon-reload #
sudo systemctl stop rc-local.service
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
Successfully run the following two pictures, with systemctl explanation
systemctl [command] [unit] :控制systemd系统和服务(单一服务的启动/关闭/观察)
command 主要有:
start :立刻启动后面接的 unit
stop :立刻关闭后面接的 unit
restart :立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思
reload :不关闭后面接的 unit 的情况下,重载配置文件,让设定生效
enable :设定下次开机时,后面接的 unit 会被启动
disable :设定下次开机时,后面接的 unit 不会被启动
status :目前后面接的这个 unit 的状态,会列出有没有正在执行、开机预设执行否、登录等信息等!
is-active :目前有没有正在运作中
is-enable :开机时有没有预设要启用这个 unit
systemctl [command] [--type=TYPE] [--all] :观察系统上所有的服务
command 主要有:
list-units :依据 unit 列出目前有启动的 unit。若加上 --all 才会列出没启动的。
list-unit-files :依据 /usr/lib/systemd/system/ 内的文件,将所有文件列表说明。
--type=TYPE:就是之前提到的 unit type,主要有 service, socket, target 等
systemctl [command] [unit.target] :管理不同的操作环境
command:
get-default :取得目前的 target
set-default :设定后面接的 target 成为默认的操作模式
isolate :切换到后面接的模式
systemctl list-dependencies [unit] [--reverse] :分析各服务之间的相依性
--reverse :反向追踪谁使用这个 unit 的意思!
systemctl daemon-reload :重载 systemd 的脚本配置文件内容
systemctl poweroff 系统关机
systemctl reboot 重新启动
systemctl suspend 进入暂停模式
systemctl hibernate 进入休眠模式
systemctl rescue 强制进入救援模式
systemctl emergency 强制进入紧急救援模式