Arch Linux

1.创建一个启动service脚本

vim /usr/lib/systemd/system/rc-local.service

  1. [Unit]
  2. Description="/etc/rc.local Compatibility"
  3. [Service]
  4. Type=forking
  5. ExecStart=/etc/rc.local start
  6. TimeoutSec=0
  7. StandardInput=tty
  8. RemainAfterExit=yes
  9. SysVStartPriority=99
  10. [Install]
  11. WantedBy=multi-user.target

2.创建 /etc/rc.local 文件

  1. vim /etc/rc.local
  2. #!/bin/sh
  3. # /etc/rc.local
  4. if test -d /etc/rc.local.d; then
  5. for rcscript in /etc/rc.local.d/*.sh; do
  6. test -r "${rcscript}" && sh ${rcscript}
  7. done
  8. unset rcscript
  9. fi

3.添加执行权限

  1. chmod a+x /etc/rc.local

4.添加/etc/rc.local.d文件夹

  1. mkdir /etc/rc.local.d

5.设置开机自启

  1. systemctl enable rc-local

结尾:

把sh脚本放在/etc/rc.local.d/文件夹中就行