场景:
华为悦盒ec6108v9刷机成ubuntu20.04之后,想要配置autossh开机自启动,却发现没有rc.local文件。
解决方案:
1. 打开/usr/lib/systemd/system/rc-local.service文件,添加下面内容:
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
2. 重新加载文件
systemctl daemon-reload
3. 在/etc/路径下创建rc.local文件,并加入下面内容:
#!/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.
exit 0
如果用户默认运行环境在 /bin/bash 下,则应修改#!bin/sh -e为 #!bin/bash -e 。自行添加的命令要在exit 0前面。
查看用户运行环境:/etc/passwd
4. 修改权限
chmod 755 /etc/rc.local
3. 重启rc服务
systemctl restart rc-local.service
4. 设置开机自启动
root@hi3798mv100:~# systemctl enable rc-local
root@hi3798mv100:~# Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.