在使用ubuntu18.04
系统中发现,原来可以写入/etc/rc.local开机启动
文件现在没有了,现在采用其他方式来做开机自启,方式亲测有效:
步骤一:在/etc文件夹里面创建 rc.local 添加开启启动文件,创建完成后,添加可执行文件
vi rc.local
chmod 777 rc.local
#!/bin/sh -e
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
#touch /var/lock/subsys/local
#以下是开启启动程序 :
/lib/firmware/tast.sh
#sleep(3)
#/lib/firmware/tcp.sh &
步骤二:进入/etc/systemd/system 文件夹创建 rc-local.service 文件(此文件不用加权限) 添加以下内容
vi rc-local.service
# SPDX-License-Identifier: LGPL-2.1+
#
# 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.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
步骤三:使能rc-local
服务
systemctl enable rc-local
步骤四:rc-local.service服务设置开机自启
systemctl enable rc-local.service
查看服务是否启动成功:systemctl is-active rc-local.service ——状态是active即为启动成功的,如果不成功则或者重启一下亦可:systemctl restart rc-local.service(此段重启为开机脚本rc.local文件重启)
最后重启后查看添加的开机启动脚本是否正常运行;