systemd 使用rc.local 说明

Posted rongfengliang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了systemd 使用rc.local 说明相关的知识,希望对你有一定的参考价值。

rc.local 是一个早期的产物用来进行启动配置的管理(还可以进行开机自启动服务的管理)实际上systemd 也是可以直接使用
rc.local ,使用上很简单,就是添加执行权限,同时添加自己的shell 代码就可以了

一些说明

实际上 rc.local 添加了执行权限之后,使用的就是rc-local 的一个systemd 的服务

 
#  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.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
?
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes

自定义配置

基于systemd启动的配置

# /etc/systemd/system/my-startup.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/libexec/my-startup-script
?
[Install]
WantedBy=multi-user.target

参考资料

https://unix.stackexchange.com/questions/471824/what-is-the-correct-substitute-for-rc-local-in-systemd-instead-of-re-creating-rc
https://www.redhat.com/sysadmin/replacing-rclocal-systemd

以上是关于systemd 使用rc.local 说明的主要内容,如果未能解决你的问题,请参考以下文章

Linux systemd rc-local.service 实现执行开机脚本

ubuntu18创建rc.local

ubuntu18创建rc.local

Ubuntu20.04设置开机自启脚本开机自启命令(ubuntu自启,ubuntu开机自启)rc(run command)(systemd)(/etc/rc.local)(开机启动原理)

Ubuntu20.04设置开机自启脚本开机自启命令(ubuntu自启,ubuntu开机自启)rc(run command)(systemd)(/etc/rc.local)(开机启动原理)开机自启动

Ubuntu 18.04 rc-local设置开机自启动