| T507 Ubuntu系统开机自启脚本是rc.local ,客户如果直接修改rc.local 文件,启机后存在修改的内容不生效的问题。具体原因和修改方法如下: 18.04及以上系统取消了rc.local自启动功能,因此不能像ubuntu16一样通过编辑rc.local来设置开机启动脚本。所以我们需要先打开rc.local自启动功能。 1、建立rc-local.service文件 sudo vim /etc/systemd/system/rc-local.service输入如下内容
 [Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local
 
 [Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99
 
 [Install]
 WantedBy=multi-user.target
 2、创建rc.localsudo vim /etc/rc.local
 
 输入如下内容,注意加入sshd服务启动
 #!/bin/sh -e
 #
 # rc.local
 #
 # This script is executed at the end of each multiuser runlevel.
 # Make sure that the script will "exit 0" on success or any other
 # value on error.
 #
 # In order to enable or disable this script just change the execution
 # bits.
 #
 # By default this script does nothing.
 echo "rc.local start" > /usr/local/test.log
 /etc/init.d/ssh start
 source ~/.bashrc
 exit 0
 3、给rc.local加上权限sudo chmod +x /etc/rc.local
 4、启用服务sudo systemctl enable rc-local
 待您成功开启rc.local 自启功能之后,您再对rc.local开机自启脚本进行修改,保存后重启,测试修改是否生效。 |