Skip to content

Commit 6a0b6d6

Browse files
comchangsclaude
andcommitted
feat: #48 post_install hook + server dependency check in doctor
post_install hook: Runs after extract + symlink, before start. Enables module-specific setup (venv, pip install, db migration). Example: noriter-superset creates venv and installs packages. tow doctor server dependencies: Checks bash, tar (required) + lsof, curl, nc (recommended). Shows install guidance for missing tools. Only fails on REQUIRED tools missing. Tested on prod: 10/10 checks passed, nc shown as recommended. noriter tow.yaml: - superset: post_install hook with venv + pip install - logstash: post_install hook with plugin install - Removed duplicate logstash definition Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0b7bf98 commit 6a0b6d6

3 files changed

Lines changed: 65 additions & 10 deletions

File tree

‎cmd/tow/cmd_monitor.go‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,61 @@ func newDoctorCmd() *cobra.Command {
634634
})
635635
}
636636

637-
// 7. Branch check
637+
// 7. Server dependencies
638+
if len(env.Servers) > 0 {
639+
srv := env.Servers[0]
640+
depCheck := `
641+
MISSING=""
642+
for cmd in bash tar; do
643+
command -v $cmd >/dev/null 2>&1 || MISSING="$MISSING $cmd(REQUIRED)"
644+
done
645+
for cmd in lsof curl nc; do
646+
command -v $cmd >/dev/null 2>&1 || MISSING="$MISSING $cmd(recommended)"
647+
done
648+
if [ -z "$MISSING" ]; then
649+
echo "ALL_OK"
650+
else
651+
echo "MISSING:$MISSING"
652+
fi
653+
`
654+
check(fmt.Sprintf("Server dependencies on %s", srv.Host), func() error {
655+
result, err := sshMgr.Exec(env, srv.Host, depCheck)
656+
if err != nil {
657+
return err
658+
}
659+
out := strings.TrimSpace(result.Stdout)
660+
if strings.Contains(out, "ALL_OK") {
661+
return nil
662+
}
663+
if strings.Contains(out, "MISSING:") {
664+
missing := strings.TrimPrefix(out, "MISSING:")
665+
parts := strings.Fields(missing)
666+
for _, p := range parts {
667+
if strings.Contains(p, "REQUIRED") {
668+
fmt.Printf(" %s%s — install required%s\n", logger.ColorRed, p, logger.ColorReset)
669+
} else {
670+
fmt.Printf(" %s%s — recommended%s\n", logger.ColorYellow, p, logger.ColorReset)
671+
}
672+
}
673+
// Only fail if REQUIRED tools are missing
674+
for _, p := range parts {
675+
if strings.Contains(p, "REQUIRED") {
676+
return fmt.Errorf("required tools missing: %s", missing)
677+
}
678+
}
679+
}
680+
return nil
681+
})
682+
}
683+
684+
// 8. Branch check
638685
if modName != "" {
639686
check("Branch policy", func() error {
640687
return deploy.CheckBranch(cfg, envName, "deploy")
641688
})
642689
}
643690

644-
// 8. No active lock
691+
// 9. No active lock
645692
if modName != "" && len(env.Servers) > 0 {
646693
servers, _, _ := cfg.GetServersForModule(envName, modName, 0)
647694
if len(servers) > 0 {

‎internal/config/config.go‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,15 @@ type HealthCheckConfig struct {
121121

122122
// HooksConfig defines lifecycle hooks
123123
type HooksConfig struct {
124-
PreBuild string `yaml:"pre_build"`
125-
PostBuild string `yaml:"post_build"`
126-
PreDeploy string `yaml:"pre_deploy"`
127-
PostDeploy string `yaml:"post_deploy"`
128-
PreStart string `yaml:"pre_start"`
129-
PostStart string `yaml:"post_start"`
130-
PreStop string `yaml:"pre_stop"`
131-
PostStop string `yaml:"post_stop"`
124+
PreBuild string `yaml:"pre_build"`
125+
PostBuild string `yaml:"post_build"`
126+
PreDeploy string `yaml:"pre_deploy"`
127+
PostDeploy string `yaml:"post_deploy"`
128+
PostInstall string `yaml:"post_install"` // runs after extract + symlink, before start (venv setup, pip install, etc.)
129+
PreStart string `yaml:"pre_start"`
130+
PostStart string `yaml:"post_start"`
131+
PreStop string `yaml:"pre_stop"`
132+
PostStop string `yaml:"post_stop"`
132133
}
133134

134135
// Defaults provides default values for environments and modules

‎internal/deploy/deploy.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ TOWEOF
222222

223223
logger.Success("[%s] Installed → deploy/%s (symlinked to current)", srv.Host, ts)
224224

225+
// post_install hook — runs after extract + symlink (venv setup, pip install, db migration, etc.)
226+
if mod.Hooks.PostInstall != "" {
227+
logger.ServerAction(srv.Host, "Running post_install hook")
228+
hookCmd := fmt.Sprintf("cd %s/current && %s", baseDir, mod.Hooks.PostInstall)
229+
d.execHook(env, srv.Host, "post_install", hookCmd)
230+
}
231+
225232
if mod.Hooks.PostDeploy != "" {
226233
d.execHook(env, srv.Host, "post_deploy", mod.Hooks.PostDeploy)
227234
}

0 commit comments

Comments
 (0)