feat: complete daemon operations and recovery tooling
This commit is contained in:
@@ -101,6 +101,9 @@ type Backend struct {
|
||||
ActiveJAR string `toml:"active_jar"`
|
||||
// SystemctlPath systemctl 可执行文件的绝对路径。
|
||||
SystemctlPath string `toml:"systemctl_path"`
|
||||
// StopGraceSeconds 容器后端停止旧容器时,发送停止信号后到强制终止前的等待秒数。
|
||||
// 可省略;省略时执行器使用默认值 30。原生后端不使用该字段。
|
||||
StopGraceSeconds *int `toml:"stop_grace_seconds"`
|
||||
// Slot 包含 8080、8081 两个受支持槽位的精确取值。
|
||||
Slot BackendSlots `toml:"slot"`
|
||||
}
|
||||
@@ -187,7 +190,7 @@ func validateExactDocumentKeys(document []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := rejectUnknownKeys(backend, "backend", "type", "release_dir", "active_jar", "systemctl_path", "slot"); err != nil {
|
||||
if err := rejectUnknownKeys(backend, "backend", "type", "release_dir", "active_jar", "systemctl_path", "stop_grace_seconds", "slot"); err != nil {
|
||||
return err
|
||||
}
|
||||
slots, err := exactTable(backend, "backend", "slot")
|
||||
@@ -264,6 +267,9 @@ func (c Config) Validate() error {
|
||||
if err := validateAbsolutePath("backend.systemctl_path", c.Backend.SystemctlPath); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.Backend.StopGraceSeconds != nil && *c.Backend.StopGraceSeconds <= 0 {
|
||||
return errors.New("backend.stop_grace_seconds must be a positive integer")
|
||||
}
|
||||
switch c.Backend.Type {
|
||||
case BackendTypeNative:
|
||||
if c.Backend.Slot.Port8080.ContainerName != "" || c.Backend.Slot.Port8081.ContainerName != "" {
|
||||
|
||||
@@ -91,6 +91,28 @@ func TestLoadValidContainerConfiguration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadAcceptsStopGraceSeconds 验证 backend.stop_grace_seconds 配置为合法正整数时
|
||||
// 能被接受,并解析到 Backend.StopGraceSeconds。
|
||||
func TestLoadAcceptsStopGraceSeconds(t *testing.T) {
|
||||
content := strings.Replace(validContainerConfig, "systemctl_path = \"/bin/systemctl\"", "systemctl_path = \"/bin/systemctl\"\nstop_grace_seconds = 45", 1)
|
||||
config, err := Load(writeConfig(t, content))
|
||||
if err != nil {
|
||||
t.Fatalf("load configuration with stop_grace_seconds: %v", err)
|
||||
}
|
||||
if config.Backend.StopGraceSeconds == nil || *config.Backend.StopGraceSeconds != 45 {
|
||||
t.Fatalf("unexpected stop_grace_seconds: %+v", config.Backend.StopGraceSeconds)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadRejectsNonPositiveStopGraceSeconds 验证 backend.stop_grace_seconds 配置为非正整数时被拒绝。
|
||||
func TestLoadRejectsNonPositiveStopGraceSeconds(t *testing.T) {
|
||||
content := strings.Replace(validContainerConfig, "systemctl_path = \"/bin/systemctl\"", "systemctl_path = \"/bin/systemctl\"\nstop_grace_seconds = 0", 1)
|
||||
_, err := Load(writeConfig(t, content))
|
||||
if err == nil || !strings.Contains(err.Error(), "backend.stop_grace_seconds") {
|
||||
t.Fatalf("expected stop_grace_seconds rejection, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLoadRejectsChangedContainerName 验证容器槽位的 container_name 被篡改时会被拒绝,
|
||||
// 且错误信息精确指向 backend.slot.8081.container_name 字段。
|
||||
func TestLoadRejectsChangedContainerName(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user