mirror of
http://junepve.top:3000/chicrobot/README.git
synced 2026-10-30 03:11:29 +08:00
更新 e1_linux添加systemd服务.md
This commit is contained in:
1 parent
6beba4c147
commit
acdf8fbcea
1 file changed
+20
-15
+20
-15
@@ -3,24 +3,24 @@
|
||||
|
||||
编辑
|
||||
```
|
||||
sudo nano /etc/systemd/system/myblog.service
|
||||
sudo nano /etc/systemd/system/pykins.service
|
||||
```
|
||||
文件内容
|
||||
```
|
||||
[Unit]
|
||||
Description=My Blog Application
|
||||
Description=python CICD service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=your_username # ← 替换为你的用户名(如 ubuntu、root 等)
|
||||
WorkingDirectory=/path/to/your/project # ← 项目根目录(包含 .venv 和 main.py)
|
||||
ExecStart=/path/to/your/project/.venv/bin/python main.py
|
||||
User=root # 替换为实际用户名(如 ubuntu、root 等)
|
||||
WorkingDirectory=/pathToProject # 项目根目录(包含 .venv 和 main.py)
|
||||
ExecStart=/pathToProject/.venv/bin/python main.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
# 可选:设置环境变量
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
# 不使用 journal管理日志,直接重定向到文件
|
||||
# StandardOutput=append:/pathToProject/main.log # 日志文件
|
||||
# StandardError=append:/pathToProject/main.log # 错误日志与正常日志写在同一个文件,便于还原上下文
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -42,16 +42,21 @@ sudo systemctl start myblog.service
|
||||
```
|
||||
# 启动
|
||||
sudo systemctl start myblog
|
||||
|
||||
# 停止
|
||||
sudo systemctl stop myblog
|
||||
|
||||
# 重启
|
||||
sudo systemctl restart myblog
|
||||
|
||||
# 查看状态
|
||||
sudo systemctl status myblog
|
||||
|
||||
# 查看日志(实时)
|
||||
sudo journalctl -u myblog -f
|
||||
```
|
||||
```
|
||||
查看日志
|
||||
```
|
||||
# 实时跟踪日志(类似 tail -f)
|
||||
sudo journalctl -u myapp.service -f
|
||||
# 查看该服务的所有日志
|
||||
sudo journalctl -u myapp.service
|
||||
# 查看今天的日志
|
||||
sudo journalctl -u myapp.service --since today
|
||||
# 按 SyslogIdentifier 过滤(需配置该项)
|
||||
sudo journalctl -t myapp
|
||||
```
|
||||
Reference in new issue
Block a user