refactor: use nginx -s reload instead of systemd

- doc: add comment
This commit is contained in:
2026-08-17 10:10:14 +08:00
parent 79f18fcdea
commit f536987a7e
62 changed files with 2216 additions and 598 deletions
+16 -2
View File
@@ -13,8 +13,13 @@ import (
"yms-daemon/internal/updatepackage"
)
// Restart performs a zero-downtime rotation with the exact release currently
// exposed by the compatibility JAR path.
// Restart 使用兼容性 JAR 链接当前指向的精确发行版执行一次零停机轮换:它把
// 当前运行中的发行版部署到非活动槽位,然后切换流量并停止前一单元,从而在
// 不更换版本的前提下完成一次重启。
//
// 参数 ctx 用于控制整个更新过程的取消;report 用于回传实时进度,可为 nil。
// 返回值为本次重启对应的事务记录以及错误。若后端类型为容器,则直接返回错误;
// 若已存在相关活动事务,则尝试复用并续跑。
func (u *Updater) Restart(ctx context.Context, report ProgressReporter) (transaction.Transaction, error) {
if u.config.Backend.Type == deploymentconfig.BackendTypeContainer {
return transaction.Transaction{}, errors.New("restart is not implemented for container backend")
@@ -67,6 +72,8 @@ func (u *Updater) Restart(ctx context.Context, report ProgressReporter) (transac
}, report)
}
// currentReleaseSource 解析兼容性 JAR 链接实际指向的源文件路径。若链接为
// 直接普通文件则原样返回;若为符号链接则要求其为绝对目标并解析到最终文件。
func currentReleaseSource(activeJAR string) (string, error) {
info, err := os.Lstat(activeJAR)
if err != nil {
@@ -92,6 +99,8 @@ func currentReleaseSource(activeJAR string) (string, error) {
return resolved, nil
}
// restartReleasePath 计算当前 JAR 在 release 目录下的相对安装路径。若当前 JAR
// 位于 release 目录内,则返回其相对路径;否则落到 direct 目录下的规范路径。
func (u *Updater) restartReleasePath(jar updatepackage.DirectNativeJAR) (string, error) {
resolvedReleaseDir, err := filepath.EvalSymlinks(u.config.Backend.ReleaseDir)
if err != nil {
@@ -107,6 +116,8 @@ func (u *Updater) restartReleasePath(jar updatepackage.DirectNativeJAR) (string,
return filepath.Join("direct", jar.SHA256[:directReleaseDigestLength], jar.FileName), nil
}
// persistedRestartInput 由已持久化的重启请求重建 updateInput,供续跑已存在的
// 重启事务使用。其中物化函数从 restartMaterializer 得到。
func (u *Updater) persistedRestartInput(request persistedRequest, idempotencyKey string) (updateInput, error) {
materialize, err := u.restartMaterializer(request)
if err != nil {
@@ -124,6 +135,9 @@ func (u *Updater) persistedRestartInput(request persistedRequest, idempotencyKey
}, nil
}
// restartMaterializer 为续跑的重启事务重建构件物化函数。若已物化的构件仍存在
// 且为直接普通文件,则返回一个表示“恢复期间构件消失”的失败函数;否则尝试从
// 源路径或 release 目录重新定位与身份匹配的 JAR 并提供其复制函数。
func (u *Updater) restartMaterializer(request persistedRequest) (func(string) error, error) {
if info, err := os.Lstat(request.ArtifactPath); err == nil {
if !info.Mode().IsRegular() || info.Mode()&os.ModeSymlink != 0 {