feat 内建重启
This commit is contained in:
parent
259e8fc2e1
commit
576ac08a05
@ -82,5 +82,5 @@ RUN apt-get update \
|
|||||||
/var/lib/apt/lists/* \
|
/var/lib/apt/lists/* \
|
||||||
/var/tmp/*
|
/var/tmp/*
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
VOLUME ["/config"]
|
VOLUME ["/config", "/var/run/docker.sock"]
|
||||||
ENTRYPOINT [ "/entrypoint" ]
|
ENTRYPOINT [ "/entrypoint" ]
|
||||||
|
@ -226,6 +226,7 @@ docker pull jxxghp/moviepilot:latest
|
|||||||
- 通过微信/Telegram/Slack远程管理,其中微信/Telegram将会自动添加操作菜单(微信菜单条数有限制,部分菜单不显示),微信需要在官方页面设置回调地址,地址相对路径为:`/api/v1/message/`。
|
- 通过微信/Telegram/Slack远程管理,其中微信/Telegram将会自动添加操作菜单(微信菜单条数有限制,部分菜单不显示),微信需要在官方页面设置回调地址,地址相对路径为:`/api/v1/message/`。
|
||||||
- 设置媒体服务器Webhook,通过MoviePilot发送播放通知等。Webhook回调相对路径为`/api/v1/webhook?token=moviepilot`(`3001`端口),其中`moviepilot`为设置的`API_TOKEN`。
|
- 设置媒体服务器Webhook,通过MoviePilot发送播放通知等。Webhook回调相对路径为`/api/v1/webhook?token=moviepilot`(`3001`端口),其中`moviepilot`为设置的`API_TOKEN`。
|
||||||
- 将MoviePilot做为Radarr或Sonarr服务器添加到Overseerr或Jellyseerr(`3001`端口),可使用Overseerr/Jellyseerr浏览订阅。
|
- 将MoviePilot做为Radarr或Sonarr服务器添加到Overseerr或Jellyseerr(`3001`端口),可使用Overseerr/Jellyseerr浏览订阅。
|
||||||
|
- 映射宿主机docker.sock文件到容器`/var/run/docker.sock`,以支持内建重启操作。
|
||||||
|
|
||||||
**注意**
|
**注意**
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ from app.helper.message import MessageHelper
|
|||||||
from app.helper.progress import ProgressHelper
|
from app.helper.progress import ProgressHelper
|
||||||
from app.schemas.types import SystemConfigKey
|
from app.schemas.types import SystemConfigKey
|
||||||
from app.utils.http import RequestUtils
|
from app.utils.http import RequestUtils
|
||||||
|
from app.utils.system import SystemUtils
|
||||||
from version import APP_VERSION
|
from version import APP_VERSION
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -198,3 +199,14 @@ def ruletest(title: str,
|
|||||||
return schemas.Response(success=True, data={
|
return schemas.Response(success=True, data={
|
||||||
"priority": 100 - result[0].pri_order + 1
|
"priority": 100 - result[0].pri_order + 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/restart", summary="重启系统", response_model=schemas.Response)
|
||||||
|
def restart_system(_: schemas.TokenPayload = Depends(verify_token)):
|
||||||
|
"""
|
||||||
|
重启系统
|
||||||
|
"""
|
||||||
|
if not SystemUtils.can_restart():
|
||||||
|
return schemas.Response(success=False, message="当前运行环境不支持重启操作!")
|
||||||
|
SystemUtils.restart_docker()
|
||||||
|
return schemas.Response(success=True)
|
||||||
|
@ -5,6 +5,8 @@ import re
|
|||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union, Tuple
|
from typing import List, Union, Tuple
|
||||||
|
|
||||||
|
import docker
|
||||||
import psutil
|
import psutil
|
||||||
from app import schemas
|
from app import schemas
|
||||||
|
|
||||||
@ -292,3 +294,26 @@ class SystemUtils:
|
|||||||
获取内存使用量和使用率
|
获取内存使用量和使用率
|
||||||
"""
|
"""
|
||||||
return [psutil.virtual_memory().used, int(psutil.virtual_memory().percent)]
|
return [psutil.virtual_memory().used, int(psutil.virtual_memory().percent)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def can_restart() -> bool:
|
||||||
|
"""
|
||||||
|
判断是否可以内部重启
|
||||||
|
"""
|
||||||
|
if not SystemUtils.is_docker():
|
||||||
|
return False
|
||||||
|
return Path("/var/run/docker.sock").exists()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def restart_docker():
|
||||||
|
"""
|
||||||
|
执行Docker重启操作
|
||||||
|
"""
|
||||||
|
# 创建 Docker 客户端
|
||||||
|
client = docker.from_env()
|
||||||
|
# 获取当前容器的 ID
|
||||||
|
container_id = open("/proc/self/cgroup", "r").read().split("/")[-1]
|
||||||
|
if not container_id:
|
||||||
|
return
|
||||||
|
# 重启当前容器
|
||||||
|
client.containers.get(container_id.strip()).restart()
|
||||||
|
@ -49,4 +49,5 @@ openai~=0.27.2
|
|||||||
cacheout~=0.14.1
|
cacheout~=0.14.1
|
||||||
click~=8.1.6
|
click~=8.1.6
|
||||||
requests_cache~=0.5.2
|
requests_cache~=0.5.2
|
||||||
parse==1.19.0
|
parse~=1.19.0
|
||||||
|
docker~=6.1.3
|
Loading…
x
Reference in New Issue
Block a user