linux下/etc/rc.local文件配置流程

linux下/etc/rc.local文件配置流程


写在前面

换了个新的开发板,想要对boa服务器执行开机自启动的操作,于是开始找/etc/rc.local,但是没有这个文件,需要进行软链加入服务,便有此篇


rc.local 是启动加载文件

systemd 默认会读取 /etc/systemd/system 下的配置文件,该目录下的文件会链接 /lib/systemd/system/ 下的文件。

一般系统安装完 /lib/systemd/system/ 下会有 rc-local.service 文件,即我们需要的配置文件

  1. 首先将 /lib/systemd/system/rc-local.service 链接到 /etc/systemd/system/ 目录下
复制代码
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service
  1. 修改文件内容
复制代码
sudo vim /etc/systemd/system/rc-local.service
  1. 在文件末尾添加如下代码
复制代码
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
  1. 创建/etc/rc.local文件
复制代码
sudo vim /etc/rc.local
  1. 打开rc.local文件,写入执行代码
bash 复制代码
#!/bin/bash -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.

#在下面添加你要开机启动的命令
#例如我需要开机启动boa服务器,则写入:
#/etc/boa/boa &
  1. 将 /etc/rc.local变成可执行文件
复制代码
  sudo chmod +x /etc/rc.local
  1. 激活rc-local.service
复制代码
 sudo systemctl enable rc-local.service
  1. 启动服务并检查状态
复制代码
sudo systemctl daemon-reload
sudo systemctl stop   rc-local.service
sudo systemctl start  rc-local.service
sudo systemctl status rc-local.service
相关推荐
不仙5201 小时前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
AI视觉网奇2 小时前
linux 检索库 判断库是否支持
java·linux·服务器
dapeng-大鹏2 小时前
KVM+LVM 零停机在线扩容 Ubuntu 根分区:从磁盘添加到逻辑卷扩展完整
linux·运维·ubuntu·磁盘空间扩展
乐维_lwops2 小时前
案例解读|运维监控助力某大型卷烟厂构建高效运维监控体系
运维·运维案例
JiaWen技术圈2 小时前
网站用户注册行为验证码方案
运维·安全
仙柒4153 小时前
Docker存储原理
运维·docker·容器
DolphinDB3 小时前
漫长人工,耗费存储?用 BackupRestore 模块一站式解决跨环境数据同步难题
运维·后端·架构
闫记康3 小时前
Linux学习day5
linux·chrome·学习
TechPioneer_lp3 小时前
30 岁硕士 Linux C 开发背景,未来想去澳洲就业,研究方向该选 AI、SDN 漏洞还是 Linux 内核?
linux·人工智能·职业规划·澳洲求职
_kerneler4 小时前
[qemu+kvm]: trap 寄存器脱敏优化方法
linux