Ubuntu 18.04 启用 rc.local

Tag: Ubuntu 
Posted on 2020-07-22

ubuntu18.04 改用 systemd 管理启动系统,虽说对于系统来说更加规范,但是丢失了 rc.local 的便捷。

所以,虽然默认没有 rc.local 了,但是系统仍然保留了启动 rc.local 的服务,只要启用就可以重回 rc.local 了。


首先创建软链接

ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service


然后编辑该文件,添加最后的 [Install] 块

vi /etc/systemd/system/rc-local.service


如下:

#  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
Alias=rc-local.service


创建 rc.local 文件

echo -e '#!/bin/bash' > /etc/rc.local


授可执行权

chmod 755 /etc/rc.local


设置服务

systemctl enable rc-local
systemctl start rc-local
systemctl status rc-local

然后就可以在 rc.local 里随便写点东西了,连之前的 exit 0 都不需要了。

 评论
张三
orz
李四
orz orz
李小四
orz orz orz
张小三
orz orz orz orz
  搜索
  Tags
全部   Ubuntu   Linux   Python   Windows   Shell   转发   字体   循环   js   KMS   MySQL   html   DNS   css   多线程   VSCode   Office   安装   WinSCP   字典   原创   多进程   反向代理   领带   截取字符   随机数   随机   重定向   远程调试   进程池   进度条   网卡   线程池   电源   生活   激活   浏览器   日志   数据库   venv   vbs   uuid   IP   iostat   import   GitHub   dpkg   DHCP   curl   crx   CPU   cloud-init   BBR   Apt   iptables   Kitsunebi   kvm   tc   subprocess   SSH   SoftEther   Set   samba   pyflakes   pip   Nginx   NextCloud   List   libreoffice   Adobe  
  功能
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!