diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 0698b8e8e..0db1e0bb3 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -880,6 +880,10 @@ func writeContainerLogMessage(w io.Writer, done <-chan struct{}, messages <-chan // The collector closes both channels when it finishes. Drain all buffered // logs before handling its result, or a ready error channel can drop the tail. if err := <-errors; err != nil { + if err == errLogContainerMissing { + _, _ = fmt.Fprint(w, "event: container-missing\ndata: {}\n\n") + return false + } _, _ = fmt.Fprintf(w, "event: error\ndata: %v\n\n", err) } return false @@ -889,6 +893,10 @@ func writeContainerLogMessage(w io.Writer, done <-chan struct{}, messages <-chan func collectLogs(done <-chan struct{}, params dto.StreamLog, messageChan chan<- string, errorChan chan<- error) { defer close(messageChan) defer close(errorChan) + if err := checkLogContainers(params); err != nil { + errorChan <- err + return + } var cmdArgs []string cmdArgs = append(cmdArgs, "logs") if params.Follow { diff --git a/agent/app/service/logs.go b/agent/app/service/logs.go index b2186e59b..a9578d279 100644 --- a/agent/app/service/logs.go +++ b/agent/app/service/logs.go @@ -1,9 +1,11 @@ package service import ( + "bytes" "context" "encoding/base64" "encoding/json" + "errors" "fmt" "os" "os/exec" @@ -16,6 +18,7 @@ import ( "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/global" "github.com/1Panel-dev/1Panel/agent/i18n" + "github.com/1Panel-dev/1Panel/agent/utils/common" "github.com/1Panel-dev/1Panel/agent/utils/re" ) @@ -567,3 +570,47 @@ func (u *LogService) ListSystemLogFile() ([]string, error) { return listFile, nil } + +var errLogContainerMissing = errors.New("log container missing") + +func checkLogContainers(params dto.StreamLog) error { + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + command := "docker" + args := []string{"container", "inspect", "--format", "{{.Id}}", params.Container} + if params.Type == "compose" { + command = common.GetDockerComposeCommand() + args = nil + if command != "docker-compose" { + command = "docker" + args = append(args, "compose") + } + for _, file := range strings.Split(params.Compose, ",") { + if file != "" { + args = append(args, "-f", file) + } + } + args = append(args, "ps", "--all", "--quiet") + } + cmd := exec.CommandContext(ctx, command, args...) + var stderr bytes.Buffer + cmd.Stderr = &stderr + output, err := cmd.Output() + if err != nil { + return logContainerPresenceResult(params.Type, stderr.String(), err) + } + return logContainerPresenceResult(params.Type, string(output), nil) +} + +func logContainerPresenceResult(kind, output string, err error) error { + if err != nil { + if kind != "compose" && (strings.Contains(output, "No such container:") || strings.Contains(output, "No such object:")) { + return errLogContainerMissing + } + return fmt.Errorf("check log containers: %w: %s", err, strings.TrimSpace(output)) + } + if strings.TrimSpace(output) == "" { + return errLogContainerMissing + } + return nil +} diff --git a/frontend/src/components/log/container/index.vue b/frontend/src/components/log/container/index.vue index 695c7b868..ddab0e7ec 100644 --- a/frontend/src/components/log/container/index.vue +++ b/frontend/src/components/log/container/index.vue @@ -258,6 +258,13 @@ const searchLogs = async () => { } const source = new EventSource(url); eventSource = source; + source.addEventListener('container-missing', () => { + if (version !== searchVersion) return; + stopListening(); + const message = i18n.global.t('container.logsUnavailable'); + term?.writeln(message); + MsgError(message); + }); source.onmessage = (event: MessageEvent) => { if (version !== searchVersion) return; term?.write(Base64.toUint8Array(event.data)); diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f2a89330d..20637c6bc 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2566,6 +2566,8 @@ const message = { missing: 'Missing', }, container: { + logsUnavailable: + 'The container does not exist or has been deleted. Container logs are unavailable. Recreate the container and try again.', nvidiaSupport: 'NVIDIA GPU support', nvidiaHelper: 'Register the NVIDIA container runtime. Install NVIDIA Container Toolkit first. Assign GPUs to each container separately.', diff --git a/frontend/src/lang/modules/es-es.ts b/frontend/src/lang/modules/es-es.ts index 8852041ad..a6bee8c02 100644 --- a/frontend/src/lang/modules/es-es.ts +++ b/frontend/src/lang/modules/es-es.ts @@ -2601,6 +2601,8 @@ const message = { missing: 'No existe', }, container: { + logsUnavailable: + 'El contenedor no existe o se ha eliminado. Los registros del contenedor no están disponibles. Vuelva a crear el contenedor e inténtelo de nuevo.', nvidiaSupport: 'Compatibilidad con GPU NVIDIA', nvidiaHelper: 'Registra el entorno de ejecución de NVIDIA. Instala primero NVIDIA Container Toolkit. Asigna las GPU a cada contenedor por separado.', diff --git a/frontend/src/lang/modules/fa.ts b/frontend/src/lang/modules/fa.ts index 8fe3d1045..7217b31f0 100644 --- a/frontend/src/lang/modules/fa.ts +++ b/frontend/src/lang/modules/fa.ts @@ -2543,6 +2543,8 @@ const message = { missing: 'ناموجود', }, container: { + logsUnavailable: + 'کانتینر وجود ندارد یا حذف شده است. لاگ‌های کانتینر در دسترس نیستند. کانتینر را دوباره ایجاد کنید و مجدداً تلاش کنید.', nvidiaSupport: 'پشتیبانی از GPU انویدیا', nvidiaHelper: 'محیط اجرای کانتینر NVIDIA را ثبت می‌کند. ابتدا NVIDIA Container Toolkit را نصب کنید. GPU را جداگانه به هر کانتینر اختصاص دهید.', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 31baa0a0a..25001b020 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -2549,6 +2549,8 @@ const message = { missing: '存在しない', }, container: { + logsUnavailable: + 'コンテナが存在しないか、削除されています。コンテナのログは表示できません。コンテナを再作成してから、もう一度お試しください。', nvidiaSupport: 'NVIDIA GPU サポート', nvidiaHelper: 'NVIDIA コンテナーランタイムを登録します。先に NVIDIA Container Toolkit をインストールしてください。GPU はコンテナーごとに割り当てる必要があります。', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index e853e8a34..ec0f4f1cb 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -2519,6 +2519,8 @@ const message = { missing: '없음', }, container: { + logsUnavailable: + '컨테이너가 존재하지 않거나 삭제되었습니다. 컨테이너 로그를 확인할 수 없습니다. 컨테이너를 다시 생성한 후 재시도하세요.', nvidiaSupport: 'NVIDIA GPU 지원', nvidiaHelper: 'NVIDIA 컨테이너 런타임을 등록합니다. 먼저 NVIDIA Container Toolkit을 설치하세요. GPU는 각 컨테이너에 별도로 할당해야 합니다.', diff --git a/frontend/src/lang/modules/lo.ts b/frontend/src/lang/modules/lo.ts index 00a1d238a..7d80fca97 100644 --- a/frontend/src/lang/modules/lo.ts +++ b/frontend/src/lang/modules/lo.ts @@ -2492,6 +2492,8 @@ const message = { missing: 'ບໍ່ມີ', }, container: { + logsUnavailable: + 'ຄອນເທນເນີບໍ່ມີຢູ່ ຫຼື ຖືກລຶບແລ້ວ. ບໍ່ສາມາດເບິ່ງບັນທຶກຂອງຄອນເທນເນີໄດ້. ກະລຸນາສ້າງຄອນເທນເນີໃໝ່ ແລ້ວລອງອີກຄັ້ງ.', nvidiaSupport: 'ຮອງຮັບ NVIDIA GPU', nvidiaHelper: 'ລົງທະບຽນ NVIDIA runtime ສຳລັບຄອນເທນເນີ. ຕິດຕັ້ງ NVIDIA Container Toolkit ກ່ອນ ແລະ ຈັດສັນ GPU ໃຫ້ແຕ່ລະຄອນເທນເນີແຍກກັນ.', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index d189ca40c..0bf7a03f6 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -2593,6 +2593,8 @@ const message = { missing: 'Tiada', }, container: { + logsUnavailable: + 'Kontena tidak wujud atau telah dipadamkan. Log kontena tidak tersedia. Cipta semula kontena dan cuba lagi.', nvidiaSupport: 'Sokongan GPU NVIDIA', nvidiaHelper: 'Daftarkan runtime kontena NVIDIA. Pasang NVIDIA Container Toolkit dahulu. Peruntukkan GPU kepada setiap kontena secara berasingan.', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index 4154cf1c8..0e87274f1 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -2601,6 +2601,8 @@ const message = { missing: 'Não existe', }, container: { + logsUnavailable: + 'O contêiner não existe ou foi excluído. Os logs do contêiner não estão disponíveis. Recrie o contêiner e tente novamente.', nvidiaSupport: 'Suporte a GPU NVIDIA', nvidiaHelper: 'Registra o runtime de contêiner NVIDIA. Instale primeiro o NVIDIA Container Toolkit. Atribua GPUs a cada contêiner separadamente.', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index 536bdd502..74d732c79 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -2593,6 +2593,8 @@ const message = { missing: 'Отсутствует', }, container: { + logsUnavailable: + 'Контейнер не существует или был удалён. Журналы контейнера недоступны. Создайте контейнер заново и повторите попытку.', nvidiaSupport: 'Поддержка GPU NVIDIA', nvidiaHelper: 'Регистрирует среду выполнения контейнеров NVIDIA. Сначала установите NVIDIA Container Toolkit. Назначайте GPU каждому контейнеру отдельно.', diff --git a/frontend/src/lang/modules/tr.ts b/frontend/src/lang/modules/tr.ts index b897ef03c..e3ce4cd5b 100644 --- a/frontend/src/lang/modules/tr.ts +++ b/frontend/src/lang/modules/tr.ts @@ -2588,6 +2588,8 @@ const message = { missing: 'Mevcut değil', }, container: { + logsUnavailable: + 'Konteyner mevcut değil veya silinmiş. Konteyner günlükleri kullanılamıyor. Konteyneri yeniden oluşturup tekrar deneyin.', nvidiaSupport: 'NVIDIA GPU desteği', nvidiaHelper: 'NVIDIA konteyner çalışma zamanını kaydeder. Önce NVIDIA Container Toolkit kurun. GPU’ları her konteynere ayrı ayrı atayın.', diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index 6d2343847..a90a2b989 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -2396,6 +2396,7 @@ const message = { missing: '不存在', }, container: { + logsUnavailable: '容器不存在或已被刪除,暫無可檢視的容器日誌。請重新建立容器後再試。', nvidiaSupport: 'NVIDIA GPU 支援', nvidiaHelper: '註冊 NVIDIA 容器執行環境,需先安裝 NVIDIA Container Toolkit。各容器仍需個別分配 GPU。', nvidiaLocalOnly: '僅支援本機預設 Docker Socket。', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index f59acf7b8..7d1e53cb0 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2403,6 +2403,7 @@ const message = { missing: '不存在', }, container: { + logsUnavailable: '容器不存在或已被删除,暂无可查看的容器日志。请重新创建容器后再试。', nvidiaSupport: 'NVIDIA GPU 支持', nvidiaHelper: '注册 NVIDIA 容器运行时,需要先安装 NVIDIA Container Toolkit。具体容器仍需单独分配 GPU。', nvidiaLocalOnly: '仅支持本机默认 Docker Socket。', diff --git a/frontend/src/views/ai/mcp/server/index.vue b/frontend/src/views/ai/mcp/server/index.vue index 1cda9a7db..3f2cac7b9 100644 --- a/frontend/src/views/ai/mcp/server/index.vue +++ b/frontend/src/views/ai/mcp/server/index.vue @@ -62,14 +62,7 @@