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   css   DNS   电源   多线程   反向代理   重定向   原创   WinSCP   随机   随机数   VSCode   venv   vbs   多进程   远程调试   字典   生活   激活   线程池   日志   数据库   网卡   截取字符   进度条   安装   进程池   领带   uuid   tc   IP   iostat   import   GitHub   dpkg   DHCP   curl   crx   CPU   cloud-init   Chrome   BBR   Apt   iptables   Kitsunebi   subprocess   SSH   SoftEther   Set   samba   pyflakes   pip   Office   Nginx   NextCloud   List   libreoffice   kvm   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!