/usr/lib/systemd/system文件夹下新建indexsite.service
[Unit]
Description=Index Site
[Service]
User=nobody
WorkingDirectory=/var/www/index
ExecStart=/usr/bin/env python3 server.py
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start indexsite
sudo systemctl enable indexsite
Python文件作为服务运行(Running as a service)
原文:https://www.cnblogs.com/jsben/p/15005527.html