发布于2026-07-31 阅读(0)
扫一扫,手机访问

chmod 搞定:chmod +x /path/to/your/python_script.py
nano 或 vim 打开一个新文件,路径为 /etc/systemd/system/my_python_service.service,把下面这些内容贴进去:[Unit]
Description=My Python Service
After=network.target
[Service]
Type=simple
User=
Group=
WorkingDirectory=/path/to/your/script/directory
ExecStart=/usr/bin/python3 /path/to/your/python_script.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
注意把 和 换成实际运行脚本的用户和组,/path/to/your/python_script.py 换成脚本的真实路径。
sudo systemctl daemon-reload
sudo systemctl start my_python_service
sudo systemctl status my_python_service
如果状态显示 active (running),说明脚本已经成功跑起来了。
sudo systemctl enable my_python_service
sudo systemctl stop my_python_service
sudo systemctl restart my_python_service
最后多说一句:以上步骤默认用的是 Python 3(路径 /usr/bin/python3)。如果你还在用 Python 2,记得把路径换成 /usr/bin/python2。
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
7
8