sudo vim /etc/systemd/system/upload_image.service
编辑一下内容
----------------------------------------------
[Unit]
Description=上传群图片服务
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/home/xxx/qun_code
ExecStart=/home/xxx/venv/bin/python3 /home/xxx/qun_code/upload_qun.py
Restart=always
RestartSec=10
StandardOutput=append:/var/log/xxx.log
StandardError=append:/var/log/xxx.log
[Install]
WantedBy=multi-user.target
----------------------------------------------
systemctl --version 那个版本就可以使用file append了
219 老版本只能用
StandardOutput=journal
StandardError=journal
236可以用
StandardOutput=file:/var/log/xxx.log
StandardError=file:/var/log/xxx.log
240可以用
StandardOutput=append:/var/log/xxx.log
StandardError=append:/var/log/xxx.log
----------------------------------------------
重启服务
systemctl daemon-reload
systemctl enable upload_image
systemctl restart upload_image
systemctl status upload_image
----------------------------------------------
旧版本查看日志
journalctl -u upload_image.service -f
journalctl -u upload_image.service -n 100
journalctl -u upload_image.service --since today
--------------------------------------------
查看所有的服务
systemctl list-unit-files --type=service
#更加详细的信息
systemctl list-units --type=service --all
查看正在运行的
systemctl list-units --type=service --state=active
-------------------------------
修改服务的名字 将 my_fast_api2 改为 my_fast_api
sudo systemctl stop my_fast_api2.service
sudo systemctl disable my_fast_api2.service
sudo mv /etc/systemd/system/my_fast_api2.service /etc/systemd/system/my_fast_api.service
sudo systemctl daemon-reload
sudo systemctl enable my_fast_api.service
sudo systemctl start my_fast_api.service