操作步骤

  1. 参照/lib/systemd/system/rc-local.service模板,在其后面添加语句

    1
    2
    [Install]
    WantedBy=multi-user.target

    并放在/etc/systemd/system

  2. 创建/etc/rc.local文件,加入自己的脚本命令,并加权限

    1
    2
    #!/bin/bash
    #自己的脚本命令
  3. 加权限

    1
    sudo chmod a+x /etc/rc.local
  4. 使能并启用

    1
    2
    3
    sudo systemctl enable rc-local
    sudo systemctl start rc-local.service
    sudo systemctl status rc-local.service