linux 開機自動啓動python程序

可以使用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

  

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章