diff --git a/backend/app/repo/cronjob.go b/backend/app/repo/cronjob.go index 1e7068c51..a668fefe7 100644 --- a/backend/app/repo/cronjob.go +++ b/backend/app/repo/cronjob.go @@ -116,7 +116,7 @@ func (u *CronjobRepo) StartRecords(cronjobID uint, targetPath string) model.JobR var record model.JobRecords record.StartTime = time.Now() record.CronjobID = cronjobID - record.Status = constant.StatusRunning + record.Status = constant.StatusWaiting if err := global.DB.Create(&record).Error; err != nil { global.LOG.Errorf("create record status failed, err: %v", err) } diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go index fc9d2d7ee..046629421 100644 --- a/backend/app/service/cornjob.go +++ b/backend/app/service/cornjob.go @@ -162,7 +162,10 @@ func (u *CronjobService) HandleOnce(id uint) error { if cronjob.ID == 0 { return constant.ErrRecordNotFound } - u.HandleJob(&cronjob) + + record := cronjobRepo.StartRecords(cronjob.ID, "") + record.FromLocal = cronjob.KeepLocal + go u.HandleJob(&cronjob) return nil } diff --git a/backend/app/service/cronjob_helper.go b/backend/app/service/cronjob_helper.go index 38525984e..54a887f29 100644 --- a/backend/app/service/cronjob_helper.go +++ b/backend/app/service/cronjob_helper.go @@ -24,46 +24,48 @@ func (u *CronjobService) HandleJob(cronjob *model.Cronjob) { ) record := cronjobRepo.StartRecords(cronjob.ID, "") record.FromLocal = cronjob.KeepLocal - switch cronjob.Type { - case "shell": - if len(cronjob.Script) == 0 { - return + go func() { + switch cronjob.Type { + case "shell": + if len(cronjob.Script) == 0 { + return + } + stdout, errExec := cmd.Exec(cronjob.Script) + if errExec != nil { + err = errExec + } + message = []byte(stdout) + case "website": + record.File, err = u.HandleBackup(cronjob, record.StartTime) + case "database": + record.File, err = u.HandleBackup(cronjob, record.StartTime) + case "directory": + if len(cronjob.SourceDir) == 0 { + return + } + record.File, err = u.HandleBackup(cronjob, record.StartTime) + case "curl": + if len(cronjob.URL) == 0 { + return + } + stdout, errCurl := cmd.Exec("curl " + cronjob.URL) + if err != nil { + err = errCurl + } + message = []byte(stdout) } - stdout, errExec := cmd.Exec(cronjob.Script) - if errExec != nil { - err = errExec - } - message = []byte(stdout) - case "website": - record.File, err = u.HandleBackup(cronjob, record.StartTime) - case "database": - record.File, err = u.HandleBackup(cronjob, record.StartTime) - case "directory": - if len(cronjob.SourceDir) == 0 { - return - } - record.File, err = u.HandleBackup(cronjob, record.StartTime) - case "curl": - if len(cronjob.URL) == 0 { - return - } - stdout, errCurl := cmd.Exec("curl " + cronjob.URL) if err != nil { - err = errCurl + cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), string(message)) + return } - message = []byte(stdout) - } - if err != nil { - cronjobRepo.EndRecords(record, constant.StatusFailed, err.Error(), string(message)) - return - } - if len(message) != 0 { - record.Records, err = mkdirAndWriteFile(cronjob, record.StartTime, message) - if err != nil { - global.LOG.Errorf("save file %s failed, err: %v", record.Records, err) + if len(message) != 0 { + record.Records, err = mkdirAndWriteFile(cronjob, record.StartTime, message) + if err != nil { + global.LOG.Errorf("save file %s failed, err: %v", record.Records, err) + } } - } - cronjobRepo.EndRecords(record, constant.StatusSuccess, "", record.Records) + cronjobRepo.EndRecords(record, constant.StatusSuccess, "", record.Records) + }() } func (u *CronjobService) HandleBackup(cronjob *model.Cronjob, startTime time.Time) (string, error) { diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index c3bdb9fd1..36f83a448 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -40,10 +40,10 @@ type daemonJsonItem struct { func (u *DockerService) LoadDockerStatus() string { status := constant.StatusRunning - stdout, err := cmd.Exec("systemctl is-active docker") - if string(stdout) != "active\n" || err != nil { - status = constant.Stopped - } + // stdout, err := cmd.Exec("systemctl is-active docker") + // if string(stdout) != "active\n" || err != nil { + // status = constant.Stopped + // } return status } diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index d88ed3fb2..eb2446637 100644 --- a/backend/app/service/image_repo.go +++ b/backend/app/service/image_repo.go @@ -1,14 +1,17 @@ package service import ( + "context" "encoding/json" "io/ioutil" "os" "path" "strings" + "time" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/common" "github.com/jinzhu/copier" @@ -64,10 +67,22 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error { } if req.Protocol == "http" { _ = u.handleRegistries(req.DownloadUrl, "", "create") - stdout, err := cmd.Exec("systemctl restart docker") - if err != nil { - return errors.New(string(stdout)) + ticker := time.NewTicker(3 * time.Second) + ctx, cancle := context.WithTimeout(context.Background(), time.Second*20) + for range ticker.C { + select { + case <-ctx.Done(): + cancle() + return errors.New("the docker service cannot be restarted") + default: + stdout, err := cmd.Exec("systemctl is-active docker") + if string(stdout) == "active\n" && err == nil { + global.LOG.Info("docker restart with new conf successful!") + cancle() + } + } } + cancle() } if err := copier.Copy(&imageRepo, &req); err != nil { diff --git a/backend/router/ro_container.go b/backend/router/ro_container.go index be353aacf..22b936bf8 100644 --- a/backend/router/ro_container.go +++ b/backend/router/ro_container.go @@ -15,7 +15,7 @@ func (s *ContainerRouter) InitContainerRouter(Router *gin.RouterGroup) { Use(middleware.PasswordExpired()) baseApi := v1.ApiGroupApp.BaseApi { - baRouter.GET("/exec", baseApi.ContainerExec) + baRouter.GET("/exec", baseApi.ContainerWsSsh) baRouter.GET("/stats/:id", baseApi.ContainerStats) baRouter.POST("", baseApi.ContainerCreate) diff --git a/frontend/src/styles/common.scss b/frontend/src/styles/common.scss index 23939850a..41f11fc96 100644 --- a/frontend/src/styles/common.scss +++ b/frontend/src/styles/common.scss @@ -269,3 +269,9 @@ } } } + +.xterm-viewport::-webkit-scrollbar { + width: 8px; + height: 8px; + background-color: #000000; +} \ No newline at end of file diff --git a/frontend/src/views/cronjob/operate/index.vue b/frontend/src/views/cronjob/operate/index.vue index 035c6b435..5413037c4 100644 --- a/frontend/src/views/cronjob/operate/index.vue +++ b/frontend/src/views/cronjob/operate/index.vue @@ -7,7 +7,7 @@ - + @@ -184,6 +184,7 @@ const dialogData = ref({ }); const acceptParams = (params: DialogProps): void => { dialogData.value = params; + changeType(); title.value = i18n.global.t('commons.button.' + dialogData.value.title); drawerVisiable.value = true; checkMysqlInstalled(); @@ -310,6 +311,39 @@ const loadDir = async (path: string) => { dialogData.value.rowData!.sourceDir = path; }; +const changeType = () => { + switch (dialogData.value.rowData!.type) { + case 'shell': + dialogData.value.rowData.specType = 'perWeek'; + dialogData.value.rowData.week = 1; + dialogData.value.rowData.hour = 1; + dialogData.value.rowData.minute = 30; + break; + case 'database': + dialogData.value.rowData.specType = 'perDay'; + dialogData.value.rowData.hour = 2; + dialogData.value.rowData.minute = 30; + break; + case 'website': + dialogData.value.rowData.specType = 'perWeek'; + dialogData.value.rowData.week = 1; + dialogData.value.rowData.hour = 1; + dialogData.value.rowData.minute = 30; + break; + case 'directory': + dialogData.value.rowData.specType = 'perDay'; + dialogData.value.rowData.hour = 1; + dialogData.value.rowData.minute = 30; + break; + case 'curl': + dialogData.value.rowData.specType = 'perWeek'; + dialogData.value.rowData.week = 1; + dialogData.value.rowData.hour = 1; + dialogData.value.rowData.minute = 30; + break; + } +}; + const loadBackups = async () => { const res = await getBackupList(); backupOptions.value = []; diff --git a/frontend/src/views/host/monitor/index.vue b/frontend/src/views/host/monitor/index.vue index 324c80cf4..6274c01a4 100644 --- a/frontend/src/views/host/monitor/index.vue +++ b/frontend/src/views/host/monitor/index.vue @@ -21,7 +21,7 @@ :start-placeholder="$t('commons.search.timeStart')" :end-placeholder="$t('commons.search.timeEnd')" :shortcuts="shortcuts" - style="float: right; right: 20px" + style="float: right" >
@@ -41,7 +41,7 @@ :start-placeholder="$t('commons.search.timeStart')" :end-placeholder="$t('commons.search.timeEnd')" :shortcuts="shortcuts" - style="float: right; right: 20px" + style="float: right" >
@@ -59,7 +59,7 @@ :start-placeholder="$t('commons.search.timeStart')" :end-placeholder="$t('commons.search.timeEnd')" :shortcuts="shortcuts" - style="float: right; right: 20px" + style="float: right" >
@@ -79,27 +79,16 @@ :start-placeholder="$t('commons.search.timeStart')" :end-placeholder="$t('commons.search.timeEnd')" :shortcuts="shortcuts" - style="float: right; right: 20px" + style="float: right" > -
+
+ + + +