gdjlc

培养良好的习惯,每天一点一滴的进步,终将会有收获。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

  

 

 

posted on 2023-12-10 23:22  gdjlc  阅读(434)  评论(0编辑  收藏  举报