可以使用systemd服務來開機自動啓用程序。
假設要開機自動啓動的python程序是:/opt/app.py
可以創建一個systemd服務
cd /etc/systemd/system vim start-python.service
內容如下:
[Unit] Description=Python Startup Service After=network.target [Service] ExecStart=/usr/bin/python3 /opt/app.py [Install] WantedBy=default.target
啓用服務
systemctl enable start-python.service
啓動服務
systemctl start start-python.service
停止服務
systemctl stop start-python.service
查看服務狀態
systemctl status start-python.service