GYURYONG的记录与分享 - Linux
type: channel
link: https://gyuryong.com/index.php/tag/Linux/
items: Debian 9+/Ubuntu 17+添加rc.local开机自启

Debian 9+/Ubuntu 17+添加rc.local开机自启
type: item
date: 2019-10-06T13:23:00+08:00
description: 有些时候我们需要用/etc/rc.local管理开机启动，Debian 9+/Ubuntu 17+以后系统都没有rc.local文件了，想要像以前一样，在/etc/rc.local中设置开机启动程序，按下面教程设置即可。1.添加rc-local.service服务文件：cat > /etc/systemd/system/rc-local.service <<EOF [Unit] Description=/etc/rc.local ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target EOF 2.新建rc-local文件：cat > /etc/rc.local <<EOF #!/bin/sh # # 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. exit 0 EOF 3.添加权限 /设置开机自启 /启动脚本：chmod +x /etc/rc.local systemctl enable rc-local systemctl start rc-local.service 4.检查状态：systemctl status rc-local.service 5.完成之后就可以在/etc/rc.local中的exit前增加你想启动的脚本了。