mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-20 00:01:06 +00:00
fix: fix docker log
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -2543,6 +2543,8 @@ const message = {
|
||||
missing: 'ناموجود',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable:
|
||||
'کانتینر وجود ندارد یا حذف شده است. لاگهای کانتینر در دسترس نیستند. کانتینر را دوباره ایجاد کنید و مجدداً تلاش کنید.',
|
||||
nvidiaSupport: 'پشتیبانی از GPU انویدیا',
|
||||
nvidiaHelper:
|
||||
'محیط اجرای کانتینر NVIDIA را ثبت میکند. ابتدا NVIDIA Container Toolkit را نصب کنید. GPU را جداگانه به هر کانتینر اختصاص دهید.',
|
||||
|
||||
@@ -2549,6 +2549,8 @@ const message = {
|
||||
missing: '存在しない',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable:
|
||||
'コンテナが存在しないか、削除されています。コンテナのログは表示できません。コンテナを再作成してから、もう一度お試しください。',
|
||||
nvidiaSupport: 'NVIDIA GPU サポート',
|
||||
nvidiaHelper:
|
||||
'NVIDIA コンテナーランタイムを登録します。先に NVIDIA Container Toolkit をインストールしてください。GPU はコンテナーごとに割り当てる必要があります。',
|
||||
|
||||
@@ -2519,6 +2519,8 @@ const message = {
|
||||
missing: '없음',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable:
|
||||
'컨테이너가 존재하지 않거나 삭제되었습니다. 컨테이너 로그를 확인할 수 없습니다. 컨테이너를 다시 생성한 후 재시도하세요.',
|
||||
nvidiaSupport: 'NVIDIA GPU 지원',
|
||||
nvidiaHelper:
|
||||
'NVIDIA 컨테이너 런타임을 등록합니다. 먼저 NVIDIA Container Toolkit을 설치하세요. GPU는 각 컨테이너에 별도로 할당해야 합니다.',
|
||||
|
||||
@@ -2492,6 +2492,8 @@ const message = {
|
||||
missing: 'ບໍ່ມີ',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable:
|
||||
'ຄອນເທນເນີບໍ່ມີຢູ່ ຫຼື ຖືກລຶບແລ້ວ. ບໍ່ສາມາດເບິ່ງບັນທຶກຂອງຄອນເທນເນີໄດ້. ກະລຸນາສ້າງຄອນເທນເນີໃໝ່ ແລ້ວລອງອີກຄັ້ງ.',
|
||||
nvidiaSupport: 'ຮອງຮັບ NVIDIA GPU',
|
||||
nvidiaHelper:
|
||||
'ລົງທະບຽນ NVIDIA runtime ສຳລັບຄອນເທນເນີ. ຕິດຕັ້ງ NVIDIA Container Toolkit ກ່ອນ ແລະ ຈັດສັນ GPU ໃຫ້ແຕ່ລະຄອນເທນເນີແຍກກັນ.',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -2593,6 +2593,8 @@ const message = {
|
||||
missing: 'Отсутствует',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable:
|
||||
'Контейнер не существует или был удалён. Журналы контейнера недоступны. Создайте контейнер заново и повторите попытку.',
|
||||
nvidiaSupport: 'Поддержка GPU NVIDIA',
|
||||
nvidiaHelper:
|
||||
'Регистрирует среду выполнения контейнеров NVIDIA. Сначала установите NVIDIA Container Toolkit. Назначайте GPU каждому контейнеру отдельно.',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -2396,6 +2396,7 @@ const message = {
|
||||
missing: '不存在',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable: '容器不存在或已被刪除,暫無可檢視的容器日誌。請重新建立容器後再試。',
|
||||
nvidiaSupport: 'NVIDIA GPU 支援',
|
||||
nvidiaHelper: '註冊 NVIDIA 容器執行環境,需先安裝 NVIDIA Container Toolkit。各容器仍需個別分配 GPU。',
|
||||
nvidiaLocalOnly: '僅支援本機預設 Docker Socket。',
|
||||
|
||||
@@ -2403,6 +2403,7 @@ const message = {
|
||||
missing: '不存在',
|
||||
},
|
||||
container: {
|
||||
logsUnavailable: '容器不存在或已被删除,暂无可查看的容器日志。请重新创建容器后再试。',
|
||||
nvidiaSupport: 'NVIDIA GPU 支持',
|
||||
nvidiaHelper: '注册 NVIDIA 容器运行时,需要先安装 NVIDIA Container Toolkit。具体容器仍需单独分配 GPU。',
|
||||
nvidiaLocalOnly: '仅支持本机默认 Docker Socket。',
|
||||
|
||||
@@ -62,14 +62,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.button.log')" prop="path" width="120px">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
@click="openLog(row)"
|
||||
link
|
||||
type="primary"
|
||||
:disabled="
|
||||
row.status !== 'Running' && row.status !== 'Rrror' && row.status !== 'Restarting'
|
||||
"
|
||||
>
|
||||
<el-button @click="openLog(row)" link type="primary">
|
||||
{{ $t('website.check') }}
|
||||
</el-button>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user