Files
bookhoard/cmd
john-okeefe 0c24deb60b feat(app): implement application lifecycle management with graceful shutdown
Phase 5: Application Lifecycle Management

Creates internal/app package for proper lifecycle management, signal
handling, and graceful shutdown of all services.

Changes:
- Create internal/app/app.go with App lifecycle manager
  - Handles SIGINT, SIGTERM, SIGQUIT signals
  - Graceful shutdown with 30-second timeout
  - Manages HTTP server shutdown
  - Manages scheduler start/stop
- Update cmd/server/main.go to use app lifecycle manager
  - Replace defer-based cleanup with proper signal handling
  - Server starts in background goroutine
  - Blocks on app.Start() until shutdown signal
  - Clean shutdown of all services

Benefits:
- Proper signal handling (Ctrl+C, kill, docker stop)
- Graceful shutdown prevents data corruption
- No more os.Exit(1) bypassing defer cleanup
- All services stopped in correct order
- Server stops accepting new connections first
- Then scheduler and background services stopped

Technical details:
- Uses sync.Mutex for shutdown safety
- Context with timeout for shutdown operations
- Channel-based coordination for shutdown completion
- Logs all lifecycle events for debugging

Fixes issue where e.Logger.Fatal() would call os.Exit(1)
immediately, skipping defer cleanup and causing unclean shutdown.
2026-02-07 17:31:53 -05:00
..