发现 debian 或者 ubuntu 这些最新的发行版没有像红帽系那种启动脚本
发现可以用 systemd 自动把这个文件注册成服务
于是开始了尝试
贴一下脚本
touch /etc/rc.local
cat > /etc/rc.local <<-EOF
#!/bin/bash
<your_program>.sh
exit 0
EOF
chmod +x /etc/rc.local
cat > /etc/systemd/system/rc-local.service <<-EOF
# SPDX-License-Identifier: LGPL-2.1+
#
# 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.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
EOF
systemctl enable --now rc-local.service
注意把 rc.local 里的脚本自行替换一下
最后使用 systemctl status rc-local.service 验证
正文完