feat: initial commit of mini-paas engine and documentation

This commit is contained in:
2026-10-23 13:57:39 -03:00
commit e0e2201230
17 changed files with 2263 additions and 0 deletions

77
cmd/paas/main.go Normal file
View File

@@ -0,0 +1,77 @@
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"mini-paas/internal/config"
"mini-paas/internal/proxy"
"mini-paas/internal/supervisor"
"mini-paas/internal/watcher"
)
func main() {
log.Println("==================================================")
log.Println(" MINI PAAS - ENGINE GO ")
log.Println("==================================================")
cfg := config.Load()
log.Printf("[Config] Porta do PaaS: %s", cfg.Port)
log.Printf("[Config] Diretório de Apps: %s", cfg.AppsDir)
log.Printf("[Config] Pool de Portas: %d - %d", cfg.PortRangeStart, cfg.PortRangeEnd)
log.Printf("[Config] Intervalo de Scan: %v", cfg.ScanInterval)
log.Printf("[Config] Domínio Base: %s", cfg.Domain)
// Inicializa o supervisor de processos
mgr := supervisor.NewManager(cfg.PortRangeStart, cfg.PortRangeEnd, cfg.AppsDir)
// Inicializa o observador da pasta de apps
wt := watcher.NewWatcher(cfg.AppsDir, cfg.ScanInterval, mgr)
wt.Start()
log.Println("[Watcher] Monitoramento de diretório ativo.")
// Inicializa o servidor HTTP e Proxy Reverso
srv := proxy.NewServer(cfg, mgr)
httpServer := &http.Server{
Addr: ":" + cfg.Port,
Handler: srv,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 120 * time.Second,
}
// Canal para shutdown gracioso
shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, os.Interrupt, syscall.SIGTERM)
go func() {
log.Printf("[HTTP] Servidor rodando em http://0.0.0.0:%s", cfg.Port)
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("[HTTP] Falha fatal no servidor: %v", err)
}
}()
<-shutdownChan
log.Println("\n[Shutdown] Sinal recebido. Encerrando Mini PaaS...")
// Para o watcher
wt.Stop()
// Encerra todos os apps filhos
for _, app := range mgr.ListApps() {
log.Printf("[Shutdown] Parando app '%s'...", app.Name)
mgr.Stop(app.Name)
}
// Encerra o servidor HTTP
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = httpServer.Shutdown(ctx)
log.Println("[Shutdown] Mini PaaS finalizado com sucesso.")
}