Skip to content

开机自启配置

使用 rc.local 服务配置

rc.local 是一个系统服务,用于在系统启动时自动执行一些脚本或命令。这个服务在系统启动时会被自动调用,并在系统启动完成后执行一些用户指定的脚本或命令,以便在系统启动时进行自定义配置或操作。

通过 sudo vim /etc/rc.local 文件末尾添加启动命令的方式实现,例如:

shell
#!/bin/bash
# by tinch for startup
/bin/mount -n -o remount,suid /
chmod 777 /tmp
nohup sh -c 'sleep 10 &&
if grep -q "Generated by resolvconf" "/etc/resolv.conf"; then
    echo "nameserver 223.6.6.6
nameserver 8.8.8.8
nameserver 223.5.5.5
nameserver 114.114.114.114" > /etc/resolv.conf
fi' > /dev/null 2>&1 &
if [ -d /etc/aidlux ]; then
    if [ -f /etc/aidlux/oom ]; then
        rm /etc/aidlux/oom
    fi
    for e in $(ls /etc/aidlux); do
      chmod 775 "/etc/aidlux/$e"
      nohup "/etc/aidlux/$e" >/var/log/startlog 2>&1 &
    done
fi

echo "test_autostart" > /home/aidlux/test.log

在末尾加入需要执行的脚本或命令即可。