| 1547 | } |
| 1548 | |
| 1549 | func (s *Service) startHomeSubscriber(ctx context.Context) { |
| 1550 | if s == nil { |
| 1551 | return |
| 1552 | } |
| 1553 | s.cfgMu.RLock() |
| 1554 | cfg := s.cfg |
| 1555 | s.cfgMu.RUnlock() |
| 1556 | if cfg == nil || !cfg.Home.Enabled { |
| 1557 | return |
| 1558 | } |
| 1559 | |
| 1560 | if s.homeCancel != nil { |
| 1561 | s.homeCancel() |
| 1562 | s.homeCancel = nil |
| 1563 | } |
| 1564 | if s.homeClient != nil { |
| 1565 | s.homeClient.Close() |
| 1566 | s.homeClient = nil |
| 1567 | } |
| 1568 | if s.homeLogForwarder != nil { |
| 1569 | s.homeLogForwarder.Stop() |
| 1570 | s.homeLogForwarder = nil |
| 1571 | } |
| 1572 | |
| 1573 | homeCtx := ctx |
| 1574 | if homeCtx == nil { |
| 1575 | homeCtx = context.Background() |
| 1576 | } |
| 1577 | homeCtx, cancel := context.WithCancel(homeCtx) |
| 1578 | s.homeCancel = cancel |
| 1579 | |
| 1580 | client := home.New(cfg.Home) |
| 1581 | s.homeClient = client |
| 1582 | home.SetCurrent(client) |
| 1583 | |
| 1584 | go client.StartConfigSubscriber(homeCtx, func(raw []byte) error { |
| 1585 | parsed, err := config.ParseConfigBytes(raw) |
| 1586 | if err != nil { |
| 1587 | log.Warnf("failed to parse home config payload: %v", err) |
| 1588 | return err |
| 1589 | } |
| 1590 | return s.applyHomeOverlayContext(homeCtx, parsed) |
| 1591 | }) |
| 1592 | s.startHomeUsageForwarder(homeCtx, client) |
| 1593 | s.homeLogForwarder = logging.StartHomeAppLogForwarder(0) |
| 1594 | } |
| 1595 | |
| 1596 | // Run starts the service and blocks until the context is cancelled or the server stops. |
| 1597 | // It initializes all components including authentication, file watching, HTTP server, |