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