ubuntu18.04启用rc.local


ubuntu18.04不再使用initd管理系统,改用systemd。
然而systemd很难用,改变太大,跟之前的完全不同。

查看是否存在这个文件:

cat /lib/systemd/system/rc.local.service

查看服务状态:

sudo systemctl status rc-local

创建/etc/rc.local文件:

sudo cat <<EOF > /etc/rc.local
#!/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

设置可执行权限:

sudo chmod +x /etc/rc.local

启动服务

systemctl start rc-local

查看服务状态

systemctl status rc-local

Archives