feat: add restart subcommands to witness and refinery (gt-9kc2)
- Add `gt witness restart <rig>` command (stop + start) - Add `gt refinery restart [rig]` command (stop + start) - Add self-cycling documentation to refinery template - Clarify that restarts are daemon-managed, not shell loops 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,21 @@ Examples:
|
||||
RunE: runRefineryAttach,
|
||||
}
|
||||
|
||||
var refineryRestartCmd = &cobra.Command{
|
||||
Use: "restart [rig]",
|
||||
Short: "Restart the refinery",
|
||||
Long: `Restart the Refinery for a rig.
|
||||
|
||||
Stops the current session (if running) and starts a fresh one.
|
||||
If rig is not specified, infers it from the current directory.
|
||||
|
||||
Examples:
|
||||
gt refinery restart gastown
|
||||
gt refinery restart # infer rig from cwd`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: runRefineryRestart,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Start flags
|
||||
refineryStartCmd.Flags().BoolVar(&refineryForeground, "foreground", false, "Run in foreground (default: background)")
|
||||
@@ -111,6 +126,7 @@ func init() {
|
||||
// Add subcommands
|
||||
refineryCmd.AddCommand(refineryStartCmd)
|
||||
refineryCmd.AddCommand(refineryStopCmd)
|
||||
refineryCmd.AddCommand(refineryRestartCmd)
|
||||
refineryCmd.AddCommand(refineryStatusCmd)
|
||||
refineryCmd.AddCommand(refineryQueueCmd)
|
||||
refineryCmd.AddCommand(refineryAttachCmd)
|
||||
@@ -383,3 +399,31 @@ func runRefineryAttach(cmd *cobra.Command, args []string) error {
|
||||
// Attach to session using exec to properly forward TTY
|
||||
return attachToTmuxSession(sessionID)
|
||||
}
|
||||
|
||||
func runRefineryRestart(cmd *cobra.Command, args []string) error {
|
||||
rigName := ""
|
||||
if len(args) > 0 {
|
||||
rigName = args[0]
|
||||
}
|
||||
|
||||
mgr, _, rigName, err := getRefineryManager(rigName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Restarting refinery for %s...\n", rigName)
|
||||
|
||||
// Stop if running (ignore ErrNotRunning)
|
||||
if err := mgr.Stop(); err != nil && err != refinery.ErrNotRunning {
|
||||
return fmt.Errorf("stopping refinery: %w", err)
|
||||
}
|
||||
|
||||
// Start fresh
|
||||
if err := mgr.Start(false); err != nil {
|
||||
return fmt.Errorf("starting refinery: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s Refinery restarted for %s\n", style.Bold.Render("✓"), rigName)
|
||||
fmt.Printf(" %s\n", style.Dim.Render("Use 'gt refinery attach' to connect"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -78,6 +78,19 @@ If the witness is not running, this will start it first.`,
|
||||
RunE: runWitnessAttach,
|
||||
}
|
||||
|
||||
var witnessRestartCmd = &cobra.Command{
|
||||
Use: "restart <rig>",
|
||||
Short: "Restart the witness",
|
||||
Long: `Restart the Witness for a rig.
|
||||
|
||||
Stops the current session (if running) and starts a fresh one.
|
||||
|
||||
Examples:
|
||||
gt witness restart gastown`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runWitnessRestart,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Start flags
|
||||
witnessStartCmd.Flags().BoolVar(&witnessForeground, "foreground", false, "Run in foreground (default: background)")
|
||||
@@ -88,6 +101,7 @@ func init() {
|
||||
// Add subcommands
|
||||
witnessCmd.AddCommand(witnessStartCmd)
|
||||
witnessCmd.AddCommand(witnessStopCmd)
|
||||
witnessCmd.AddCommand(witnessRestartCmd)
|
||||
witnessCmd.AddCommand(witnessStatusCmd)
|
||||
witnessCmd.AddCommand(witnessAttachCmd)
|
||||
|
||||
@@ -341,3 +355,41 @@ func runWitnessAttach(cmd *cobra.Command, args []string) error {
|
||||
attachCmd.Stderr = os.Stderr
|
||||
return attachCmd.Run()
|
||||
}
|
||||
|
||||
func runWitnessRestart(cmd *cobra.Command, args []string) error {
|
||||
rigName := args[0]
|
||||
|
||||
mgr, r, err := getWitnessManager(rigName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Restarting witness for %s...\n", rigName)
|
||||
|
||||
// Kill tmux session if it exists
|
||||
t := tmux.NewTmux()
|
||||
sessionName := witnessSessionName(rigName)
|
||||
running, _ := t.HasSession(sessionName)
|
||||
if running {
|
||||
if err := t.KillSession(sessionName); err != nil {
|
||||
fmt.Printf("%s Warning: failed to kill session: %v\n", style.Dim.Render("⚠"), err)
|
||||
}
|
||||
}
|
||||
|
||||
// Update state file to stopped
|
||||
_ = mgr.Stop()
|
||||
|
||||
// Start fresh
|
||||
created, err := ensureWitnessSession(rigName, r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("starting witness: %w", err)
|
||||
}
|
||||
|
||||
if created {
|
||||
_ = mgr.Start(false) // Mark as running in state file
|
||||
}
|
||||
|
||||
fmt.Printf("%s Witness restarted for %s\n", style.Bold.Render("✓"), rigName)
|
||||
fmt.Printf(" %s\n", style.Dim.Render("Use 'gt witness attach' to connect"))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user