{"record":{"id":"611312a88239b473","repo":"Billionmail/BillionMail","slug":"failed-to-restart-rspamd-container-v","errorCode":null,"errorMessage":"Failed to restart rspamd container: %v","messagePattern":"Failed to restart rspamd container: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/domains/domains.go","lineNumber":635,"sourceCode":"\n\t\t\t// Remove old config block if it exists\n\t\t\tpattern := fmt.Sprintf(`(?s)#%s_DKIM_BEGIN.*?#%s_DKIM_END\\s*`, domain, domain)\n\t\t\tsignContent, err = gregex.ReplaceString(pattern, \"\", signContent)\n\t\t\tif err != nil {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tsignContent = strings.Replace(signContent, \"#BT_DOMAIN_DKIM_END\", signConf+\"\\n#BT_DOMAIN_DKIM_END\", 1)\n\t\t\t_, err = public.WriteFile(signConfPath, signContent)\n\t\t\tif err != nil {\n\t\t\t\terr = fmt.Errorf(\"Failed to write DKIM sign config: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Restart rspamd service\n\t\t\terr = dk.RestartContainerByName(context.Background(), consts.SERVICES.Rspamd)\n\t\t\tif err != nil {\n\t\t\t\terr = fmt.Errorf(\"Failed to restart rspamd container: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\t// DKIM public key is typically stored in a specific location in the container or host\n\t// Assuming we use docker exec to read the DKIM public key from the rspamd container\n\tdkimPub, err := public.ReadFile(dkimPubPath)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"Cannot read DKIM public key: %v\", err)\n\t\treturn\n\t}\n\n\t// Format DKIM record\n\t// Expected format is a pre-formatted TXT record value like \"v=DKIM1; k=rsa; p=MIIBIjANBg...\"\n\tdkimRecord := strings.TrimSpace(dkimPub)\n\n\t// If the raw public key is read, format it into DNS TXT record format","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/domains.go#L617-L653","documentation":"Thrown when restarting the rspamd container via dk.RestartContainerByName fails after the DKIM signing config was written. Without the restart rspamd would not pick up the new DKIM key/signing block, so the function treats a failed restart as fatal.","triggerScenarios":"Docker API returns an error from container restart — container not found, docker daemon unreachable/unix socket permission denied, container in a restart loop or unhealthy state, or timeout during stop/start.","commonSituations":"rspamd container crashed or was renamed, Docker socket not mounted/permission denied for the BillionMail container, daemon restart in progress, or resource exhaustion preventing the container from starting.","solutions":["Check `docker ps -a` for the rspamd container and start it manually if stopped (docker start rspamd)","Verify the Docker socket is accessible from the process (mount /var/run/docker.sock, correct group membership)","Check `docker logs rspamd` for config errors introduced by the new DKIM block — a malformed config can make the container die on restart","Re-run RepairDKIMSigningConfig once the daemon/container is healthy"],"exampleFix":"// before: restart fails, no diagnosis\ndk.RestartContainerByName(context.Background(), consts.SERVICES.Rspamd)\n// after: inspect container state on failure\ndocker ps -a --filter name=rspamd\ndocker logs rspamd --tail 50\n# then retry the restart","handlingStrategy":"retry","validationCode":"docker ps --format '{{.Names}} {{.Status}}' | grep -q rspamd || echo 'rspamd container not running'\ntest -S /var/run/docker.sock && echo 'docker socket present'","typeGuard":"func dockerReachable() bool {\n    c, err := net.Dial(\"unix\", \"/var/run/docker.sock\")\n    if err != nil { return false }\n    c.Close()\n    return true\n}","tryCatchPattern":"err := dk.RestartContainerByName(ctx, consts.SERVICES.Rspamd)\nif err != nil {\n    log.Printf(\"rspamd restart failed: %v — checking container state before retry\", err)\n    time.Sleep(5 * time.Second)\n    return dk.RestartContainerByName(ctx, consts.SERVICES.Rspamd)\n}","preventionTips":["Add Docker socket mount and group permissions to deployment manifests","Add restart policies (unless-stopped) to the rspamd container","Validate rspamd config syntax before restart to avoid crash-loops"],"tags":["docker","rspamd","container","service-restart"],"backgroundTag":"docker-container-restart-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}