Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket Passing for seemless restarts? #1675

Open
jkrauska opened this issue May 11, 2018 · 1 comment
Open

Socket Passing for seemless restarts? #1675

jkrauska opened this issue May 11, 2018 · 1 comment

Comments

@jkrauska
Copy link

Consider looking at passing file descriptors between old and new gobgp processes?

https://godoc.org/github.com/ftrvxmtrx/fd

This would allow you to upgrade gobgp daemon 'live'.

Presumably we'd need to request a rib refresh right away, but the connection wouldn't go down.
(important for some with BGP)

@ljluestc
Copy link

ljluestc commented Nov 3, 2024


package main

import (
    "fmt"
    "os"
    "os/exec"
    "syscall"

    "github.com/ftrvxmtrx/fd"
)

func main() {
    // Existing GoBGP process logic...

    // When ready to upgrade:
    err := upgradeGoBGP()
    if err != nil {
        fmt.Println("Error upgrading GoBGP:", err)
    }
}

func upgradeGoBGP() error {
    // Create a new process for the upgraded GoBGP
    cmd := exec.Command("./gobgp", "daemon") // Adjust command as necessary
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr

    // Pass existing file descriptors to the new process
    oldFDs := []int{ /* add your file descriptors here */ }
    newFDs, err := fd.New(oldFDs)
    if err != nil {
        return fmt.Errorf("failed to create file descriptor set: %w", err)
    }

    // Start the new GoBGP process
    if err := cmd.Start(); err != nil {
        return fmt.Errorf("failed to start new GoBGP process: %w", err)
    }

    // Pass file descriptors to the new process
    if err := newFDs.PassTo(cmd.Process.Pid); err != nil {
        return fmt.Errorf("failed to pass file descriptors: %w", err)
    }

    // Optionally wait for the new process to finish
    // If you want to wait, use cmd.Wait()
    return nil
}

// Function to request a RIB refresh
func requestRIBRefresh() {
    // Implementation for requesting RIB refresh
    // This may involve calling an appropriate method or sending a signal
    fmt.Println("Requesting RIB refresh...")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants