Ubuntu好像从16.04的下一个版本开始取消了rc.local 这种服务,开启全面systemd 时代?

假如一些用户使用不习惯的话,这里提供一种启用rc.local定制开机自启服务方法。

1、创建rc-local.service服务

sudo vim /etc/systemd/system/rc-local.service

在vim中,添加如下内容:

[Unit]
Description=/etc/rc.local Compatibility
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

2、创建/etc/rc.local文件并赋予可执行权限

sudo vim /etc/rc.local

在vim中粘贴以下文本:

#!/bin/sh -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.

exit 0

给/etc/rc.local添加可执行权限:

sudo chmod +x /etc/rc.local

启用开机自启服务:

sudo systemctl enable rc-local

启动服务:

sudo systemctl start rc-local.service

检查服务状态:

sudo systemctl status rc-local.service



end.