Skip to content

Commit 31a0772

Browse files
committed
restarts myc on user namespaces to catch myc bin update (#50)
Signed-off-by: Ashraf Fouda <ashraf.m.fouda@gmail.com>
1 parent 1d8f2ec commit 31a0772

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

pkg/upgrade/upgrade.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,51 @@ func (u *Upgrader) install(repo, name string) error {
508508
return errors.Wrap(err, "failed to list services from flist")
509509
}
510510

511-
return u.ensureRestarted(services...)
511+
if err := u.ensureRestarted(services...); err != nil {
512+
return err
513+
}
514+
515+
// restarting mycelium instances on user's namespaces
516+
return u.restartMyceliumInstances()
517+
}
518+
519+
// this method restarts all mycelium-<usernetwork> instances on user's namespaces to catch mycelium version updates
520+
func (u *Upgrader) restartMyceliumInstances() error {
521+
const zinitPath = "/etc/zinit"
522+
523+
// Get all services from host
524+
entries, err := os.ReadDir(zinitPath)
525+
if err != nil {
526+
return fmt.Errorf("failed to read host zinit directory: %w", err)
527+
}
528+
529+
var myceliumServices []string
530+
for _, entry := range entries {
531+
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".yaml") || !strings.HasPrefix(entry.Name(), "mycelium-") {
532+
continue
533+
}
534+
535+
serviceName := strings.TrimSuffix(entry.Name(), ".yaml")
536+
myceliumServices = append(myceliumServices, serviceName)
537+
}
538+
539+
if len(myceliumServices) == 0 {
540+
return nil
541+
}
542+
543+
log.Info().Strs("services", myceliumServices).Msg("restarting mycelium instances")
544+
if err := u.zinit.StopMultiple(20*time.Second, myceliumServices...); err != nil {
545+
log.Error().Err(err).Msg("failed to stop all mycelium services")
546+
}
547+
548+
for _, name := range myceliumServices {
549+
log.Info().Str("service", name).Msg("starting mycelium service")
550+
if err := u.zinit.Start(name); err != nil {
551+
log.Error().Err(err).Str("service", name).Msg("could not start mycelium service")
552+
}
553+
}
554+
555+
return nil
512556
}
513557

514558
func (u *Upgrader) servicesFromStore(store meta.Walker) ([]string, error) {

0 commit comments

Comments
 (0)