Repository navigation
feat(p2p): add --foreground flag to listen and forward commands - #11099
Conversation
adds `-f/--foreground` option that keeps the command running until interrupted (SIGTERM/Ctrl+C) or closed via `ipfs p2p close`. the listener/forwarder is automatically removed when the command exits. useful for systemd services and scripts that need cleanup on exit.
34a8acc to
e7bb812
Compare
|
Thanks! This works great for me I have two ipfs services, one to launch ipfs as a daemon and one to start forwarding ssh in the background. ipfs.service ipfs-ssh-forward.service This seems to work really nicely with systemd, the port listening will automatically restart with if for some reason that systemd service stops running and will relaunch with the ipfs service when it starts. Only quirk is I'm depending on delays to wait for ipfs daemon to fully startup before launching p2p listen. If there a file that gets created/modified when the daemon fully starts it could be tracked with one of the path directives in systemd (https://www.freedesktop.org/software/systemd/man/latest/systemd.path.html#PathExists=) Can't really comment to much on the code to implement this as I'm not familiar with the code base or go-lang in general EDIT: |
|
@Hazematman you could also use |
|
I'm still testing it for robustness but this is what I have now for systemd services I have a ipfs-ssh-forward.service unit file that looks like Then I have a ipfs-ssh-forward.path systemd path file I'm using the ipfs.service basically unmodified described here https://github.com/ipfs/kubo/tree/master/misc Then to enable things I do The ipfs service should startup and then once the The one weird thing I'm trying to debug is that it seems that the first launch of the ipfs-ssh-forward service always fails. I'm not 100% sure why but one theory is that when the api file is created, ipfs isn't ready for p2p listen commands yet. |
# Conflicts: # docs/changelogs/v0.40.md
- add dedicated docs/p2p-tunnels.md covering: - why p2p tunnels (NAT traversal, no public IP needed) - quick start with netcat - background and foreground modes - systemd integration with path-based activation - security considerations and troubleshooting - document Experimental.Libp2pStreamMounting in docs/config.md - simplify docs/experimental-features.md, link to new doc - add "Learn more" links to ipfs p2p listen/forward --help - update changelog entry with doc link - add cross-reference in misc/README.md
fixes race condition where $IPFS_PATH/api and $IPFS_PATH/gateway files were written before the HTTP servers were ready to accept connections. this caused issues for tools like systemd path units that immediately try to connect when these files appear. changes: - add corehttp.ServeWithReady() that signals when server is ready - wait for ready signal before writing address files - use sync.WaitGroup.Go() (Go 1.25) for cleaner goroutine management - add TestAddressFileReady to verify both api and gateway files
|
Thank you @Hazematman, there was indeed a race condition related to creation of Also, check If this PR looks sensible, we will include this in 0.40. |
- buffer error channel with len(listeners) to prevent deadlock when multiple servers write errors simultaneously - wait for ALL listeners to be ready before writing api/gateway file, not just the first one Feedback-from: #11099 (review)
reframe to lead with user benefit and add example output
|
With 80b703a I'm not seeing the startup race condition I saw before with the same tests I did restarting my machine. The |
# Conflicts: # docs/changelogs/v0.40.md
the "First launch fails but restarts work" troubleshooting section described a race where the api file was written before the daemon was ready. this was fixed in 80b703a which ensures api/gateway files are only written after HTTP servers are ready to accept connections.
This PR mostly adds
docs/p2p-tunnel.mddocumentation with useful examples.It also
-f/--foregroundoption that keeps the command running until interrupted (SIGTERM/Ctrl+C) or closed viaipfs p2p close. the listener/forwarder is automatically removed when the command exits. This is very useful for systemd services and scripts that need cleanup on exit.$IPFS_PATH/api|gatewayfiles being created before goroutine that initializes listener is executed (80b703a)