Ubuntu18.04以上镜像版本配置rc.local

操作系统
问题描述

火山引擎Ubuntu18.04以上镜像版本,默认rc-local.service为关闭,默认/etc/rc.local未创建,如下所示:

root@rclocal:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: inactive (dead)
       Docs: man:systemd-rc-local-generator(8)
root@rclocal:~# cat /etc/rc.local
cat: /etc/rc.local: No such file or directory
问题分析

ubuntu-16以上不能通过直接编辑rc.local来设置开机启动脚本,需要配置rc-local.service文件,然后,编辑rc.local文件,启动rc-local.service服务即可。

解决方案

火山引擎针对此类问题进行了相关优化,客户不需要进行相关配置,具使用方法如下。

  1. 使用命令sudo vi /etc/rc.local创建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.
echo "看到这行字,说明添加自启动脚本成功。" > /usr/local/test.log
exit 
  1. rc.local文件添加可执行权限,命令如下:
sudo chmod +x /etc/rc.local
  1. 重启使用命令cat /usr/local/test.log,如出现下列结果,则配置成功。
root@rclocal:~# cat /usr/local/test.log
看到这行字,说明添加自启动脚本成功。

如果您有其他问题,欢迎您联系火山引擎技术支持服务

445
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论