0%

Ubuntu自启动

Ubuntu 通过Service自启动

  1. /lib/systemd/system/文件夹下创建Service,本次使用Service创建NPC自启。故将本次服务名称命名为npc.service
  2. 编写npc.service内容
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    [Unit]
    Description=nps_client_service
    After=network.target #网络启动后
    Wants=
    Requires=

    [Service]
    Type=forking
    ExecStart=/bin/bash /opt/NPClient/start_npc.sh #执行的内容是脚本test.sh中的内容,其中包括它的绝对地址

    [Install]
    WantedBy=multi-user.target
  3. 将该服务设置为开机启动
    1
    systemctl enable npc.service
  4. 查看服务状态
    1
    systemctl status npc.service

    确保此时无报错

  5. 重启电脑