{"record":{"id":"39f421df9289dbcb","repo":"vitessio/vitess","slug":"make-mycnf-hook-failed-v-v","errorCode":null,"errorMessage":"make_mycnf hook failed(%v): %v","messagePattern":"make_mycnf hook failed\\((.+?)\\): (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/mysqld.go","lineNumber":1463,"sourceCode":"\nfunc (mysqld *Mysqld) initConfig(cnf *Mycnf, outFile string) error {\n\tvar err error\n\tvar configData string\n\n\tenv := make(map[string]string)\n\tenvVars := []string{\"KEYSPACE\", \"SHARD\", \"TABLET_TYPE\", \"TABLET_ID\", \"TABLET_DIR\", \"MYSQL_PORT\"}\n\tfor _, v := range envVars {\n\t\tenv[v] = os.Getenv(v)\n\t}\n\n\tswitch hr := hook.NewHookWithEnv(\"make_mycnf\", nil, env).Execute(); hr.ExitStatus {\n\tcase hook.HOOK_DOES_NOT_EXIST:\n\t\tlog.Info(\"make_mycnf hook doesn't exist, reading template files\")\n\t\tconfigData, err = cnf.makeMycnf(mysqld.getMycnfTemplate())\n\tcase hook.HOOK_SUCCESS:\n\t\tconfigData, err = cnf.fillMycnfTemplate(hr.Stdout)\n\tdefault:\n\t\treturn fmt.Errorf(\"make_mycnf hook failed(%v): %v\", hr.ExitStatus, hr.Stderr)\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn os2.WriteFile(outFile, []byte(configData))\n}\n\nfunc (mysqld *Mysqld) getMycnfTemplate() string {\n\tif mycnfTemplateFile != \"\" {\n\t\tdata, err := os.ReadFile(mycnfTemplateFile)\n\t\tif err != nil {\n\t\t\tlog.Error(fmt.Sprintf(\"template file specified by -mysqlctl-mycnf-template could not be read: %v\", mycnfTemplateFile))\n\t\t\tos.Exit(1)\n\t\t}\n\t\treturn string(data) // use only specified template\n\t}\n\tvar myTemplateSource strings.Builder","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/mysqld.go#L1445-L1481","documentation":"The optional 'make_mycnf' hook script ran but returned an exit status other than success (and not HOOK_DOES_NOT_EXIST), so mysqld cannot generate my.cnf. The hook's exit status and stderr are surfaced in the message. This is the default branch of the hook result switch in initConfig.","triggerScenarios":"Calling Mysqld.InitConfig / Start with a hook named 'make_mycnf' present in vtenv/vthook path, where the hook exits non-zero (neither HOOK_SUCCESS nor HOOK_DOES_NOT_EXIST).","commonSituations":"Custom my.cnf generation hook with a bug or missing dependency; hook script not executable / wrong interpreter; hook emits error because required env vars or template files are absent.","solutions":["Read the stderr portion of the message to see the hook's own error and fix the hook script.","Run the hook manually with the same inputs to reproduce and debug.","Remove or fix the make_mycnf hook if custom config generation is not needed, letting the template path be used.","Verify the hook script is executable and returns hook.HOOK_SUCCESS (exit 0)."],"exampleFix":"// before (hook script)\n#!/bin/sh\ncat ${TEMPLATE} # TEMPLATE unset -> fails\n// after\n#!/bin/sh\n: \"${TEMPLATE:=/vthook/mycnf/template.cnf}\"\ncat \"$TEMPLATE\"","handlingStrategy":"validation","validationCode":"hookPath := filepath.Join(vtenv.VtRoot(), \"vthook\", \"make_mycnf\")\nif _, err := os.Stat(hookPath); err == nil {\n    if info, _ := os.Stat(hookPath); info.Mode()&0o111 == 0 {\n        return fmt.Errorf(\"make_mycnf hook not executable\")\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := mysqld.InitConfig(cnf, outFile); err != nil {\n    if strings.Contains(err.Error(), \"make_mycnf hook failed\") {\n        log.Errorf(\"hook exit/stderr: %v\", err)\n    }\n    return err\n}","preventionTips":["Test custom hooks manually with representative inputs before rollout","Make hook scripts executable and use explicit interpreter shebangs","Make hooks fail loudly but deterministically; log to stderr","Avoid hooks unless custom my.cnf generation is truly required"],"tags":["mysql","config","hook"],"backgroundTag":"hook-exit-failure","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}