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

  

 

 

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