linux 开机自启

160 阅读1分钟
  • 使用systemctl来管理

    cd /etc/systemd/system
    sudo vim auto_start_broadcast.service  
    
  • 编辑auto_start_broadcast.service文件

    [Unit]
    Description=
    Documentation=
    After=network.target
    Wants=
    Requires=
    
    [Service]
    ExecStart=/usr/local/bin/python3 /home/zhouqinan/projects/broadcast.py
    ExecStop=
    ExecReload=/usr/local/bin/python3 /home/zhouqinan/projects/broadcast.py
    Type=simple
    
    [Install]
    WantedBy=multi-user.target
    
  • 先试下能否加载

    sudo systemctl start auto_start_broadcast.service
    
  • 设置开机自启

    sudo systemctl enable auto_start_broadcast.service
    
  • 关闭开机自启

    sudo systemctl disable auto_start_broadcast.service