-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
159 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/console" | ||
"github.com/goravel/framework/contracts/console/command" | ||
"github.com/goravel/framework/facades" | ||
"github.com/goravel/framework/support/carbon" | ||
|
||
"panel/internal" | ||
"panel/pkg/tools" | ||
) | ||
|
||
// PanelTask 面板每日任务 | ||
type PanelTask struct { | ||
} | ||
|
||
// Signature The name and signature of the console command. | ||
func (receiver *PanelTask) Signature() string { | ||
return "panel:task" | ||
} | ||
|
||
// Description The console command description. | ||
func (receiver *PanelTask) Description() string { | ||
return "[面板] 每日任务" | ||
} | ||
|
||
// Extend The console command extend. | ||
func (receiver *PanelTask) Extend() command.Extend { | ||
return command.Extend{ | ||
Category: "panel", | ||
} | ||
} | ||
|
||
// Handle Execute the console command. | ||
func (receiver *PanelTask) Handle(ctx console.Context) error { | ||
internal.Status = internal.StatusMaintain | ||
|
||
// 优化数据库 | ||
if _, err := facades.Orm().Query().Exec("VACUUM"); err != nil { | ||
facades.Log().Tags("面板", "每日任务"). | ||
With(map[string]any{ | ||
"error": err.Error(), | ||
}).Error("优化面板数据库失败") | ||
return err | ||
} | ||
|
||
// 备份面板 | ||
if err := tools.Archive([]string{"/www/panel"}, "/www/backup/panel/panel-"+carbon.Now().ToShortDateTimeString()+".zip"); err != nil { | ||
facades.Log().Tags("面板", "每日任务"). | ||
With(map[string]any{ | ||
"error": err.Error(), | ||
}).Error("备份面板失败") | ||
return err | ||
} | ||
|
||
// 清理 7 天前的备份 | ||
if _, err := tools.Exec(`find /www/backup/panel -mtime +7 -name "*.zip" -exec rm -rf {} \;`); err != nil { | ||
facades.Log().Tags("面板", "每日任务"). | ||
With(map[string]any{ | ||
"error": err.Error(), | ||
}).Error("清理面板备份失败") | ||
return err | ||
} | ||
|
||
internal.Status = internal.StatusNormal | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
|
||
"panel/internal" | ||
) | ||
|
||
// Status 检查程序状态 | ||
func Status() http.Middleware { | ||
return func(ctx http.Context) { | ||
switch internal.Status { | ||
case internal.StatusUpgrade: | ||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ | ||
"code": 503, | ||
"message": "面板升级中,请稍后", | ||
}) | ||
return | ||
case internal.StatusMaintain: | ||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ | ||
"code": 503, | ||
"message": "面板正在运行维护,请稍后", | ||
}) | ||
return | ||
case internal.StatusClosed: | ||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ | ||
"code": 403, | ||
"message": "面板已关闭", | ||
}) | ||
return | ||
case internal.StatusFailed: | ||
ctx.Request().AbortWithStatusJson(http.StatusOK, http.Json{ | ||
"code": 500, | ||
"message": "面板运行出错,请检查排除或联系支持", | ||
}) | ||
return | ||
default: | ||
ctx.Request().Next() | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package internal | ||
|
||
// 定义面板状态常量 | ||
const ( | ||
StatusNormal = iota | ||
StatusMaintain | ||
StatusClosed | ||
StatusUpgrade | ||
StatusFailed | ||
) | ||
|
||
var Status = StatusNormal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters