引言
千万不要把死循环放进去啊!!!使用 systemd 方式
新建脚本
在此文件中写入您的脚本
vi /etc/rc.d/rc.local
赋予执行权限
chmod +x /etc/rc.d/rc.local
编辑启动状态
编辑文件
vi /usr/lib/systemd/system/rc-local.service
在最后一行加入 [Install]
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
然后使用 systemd 开机自启动
systemctl enable rc-local.service
查看启动状态
使用以下命令
systemctl status rc-local.service