rc.local 仅在连接到以太网后执行?

rc.local 仅在连接到以太网后执行?

我是 ubuntu 新手,但我决定向 rc.local 添加一条指令,以便它改变我的亮度设置,因为它始终以最大亮度启动。

注意:只有当我通过以太网连接到互联网时,它才会工作。如果我打开笔记本电脑时没有以太网电缆,它将保持最大亮度,只有在我连接以太网电缆后它才会执行 rc.local,或者如果在打开电脑之前连接了以太网电缆,rc.local 将正常执行并将我的亮度级别更改为所需值。

这是我的 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.

 echo 1466 > /sys/class/backlight/intel_backlight/brightness

 exit 0

答案1

默认情况下,/etc/rc.local在建立网络连接后运行。这在插入文件中指定/lib/systemd/system/rc-local.service.d/debian.conf

$ sudo systemctl status rc.local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (exited) since Sat 2017-02-11 00:31:50 EET; 2h 33min ago
    Tasks: 0
   Memory: 0B
      CPU: 0

Feb 11 00:31:50 libellio systemd[1]: Starting /etc/rc.local Compatibility...
Feb 11 00:31:50 libellio systemd[1]: Started /etc/rc.local Compatibility.

$ cat /lib/systemd/system/rc-local.service.d/debian.conf
[Unit]
# not specified by LSB, but has been behaving that way in Debian under SysV
# init and upstart
After=network-online.target

# Often contains status messages which users expect to see on the console
# during boot
[Service]
StandardOutput=journal+console
StandardError=journal+console

虽然这种默认设置对于通常从启动的服务类型来说很好rc.local,但对于您的特定用例,您可能需要更改该设置。

将服务文件复制/lib/systemd/system/rc-local.service/etc/systemd/system。然后将嵌入式配置文件复制到/etc/systemd/system/rc-local.service.d/(如果需要,创建目录),然后编辑副本并注释掉 行After=network-online.target

相关内容