adamwight
I’ve written a crude module for retrieving files from a remote server using rsync, since I didn’t see any existing tools already. This could be useful anywhere one needs to efficiently move files across filesystem or network boundaries, and could even be used for better control and monitoring of deployments. Does it sound like something I should package into a library?
The inner logic takes advantage of the --info=progress2 reporting mode for rsync, reading status lines to monitor progress:
port = Port.open(
{:spawn_executable, System.find_executable("rsync")},
[args: ["-a", "--info=progress2"] ++ remote_urls ++ [local_path],
:binary, :exit_status, :hide, :use_stdio, :stderr_to_stdout]
)
receive do
{^port, {:data, data}} ->
....
{^port, {:exit_status, status}} ->
....
end
Trending in RFCs
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
I am not a reliable source but IMO that would be more interesting as a blog post showing how did you wrap
rsync.adamwight
A blog post is a good idea, and I ended up publishing as a library so there’ll be something to write about:
dimitarvp
Thanks. Had a quick look. IMO you should include a complete example with the error messages that your
GenServercan also emit (not only the happy path). I’d be interested in just copy-pasting such an entire block of code in a project of mine and then tuning the separatecasebranches for my goals. Better peace of mind.adamwight
I was also curious about error cases, so I added some tests that show reasonable behavior when rsync emits random junk (forward to Logger at :warning level) and when the process crashes (forward error to linked parent).
Deleted: random claims that the tests are a full example.Feel free to share the case statements you add for your own application goals.
adamwight
I struggle with basic OTP principles. Is the normal way to handle a start_link failure to run it under a Supervisor? Anyone feel like sharing a snippet showing how to run a brittle command like this and catch the error?
In my own app I’m letting Oban handle the retry logic and in tests I’ve trapped the exit but these are side-stepping typical usage I suspect.
adamwight
Thanks for the suggestion, here are my observations as a blog post: Elixir/Ports and external process wiring - ludd
pzingg
Very informative post, Adam. I am using ports to communicate with long-running OS processes and struggle to understand the niceties about how to signal them from the BEAM. I did not know about
erl_child_setupbut I see that it is used by two other OS process-oriented libraries: alcove and prx.adamwight
I’d be curious to hear more about the obstacles that you’ve run into. If you mean “signal” in the generic sense of sending data back and forth, there are certainly some complexities but it should be possible to accomplish whatever you need, just set up a gen_server to write and read to and from the process.
But if you mean “signal” in the POSIX
killsense I think it’s impossible to do with the built-in functions, since the OS PID mapping is strictly internal and can’t be accessed from code. If this is the intention, you could write a wrapper in C or shell, which listens for messages from BEAM and translates those into signals to send to child. But I wait to hear more!akash-akya
BEAM does return OS PID: erlang — OTP 29.0.2 (erts 17.0.2)
adamwight
@akash-akya thanks for pointing this out! I updated the linked blog with your correction but unfortunately can’t edit my post above, so the misinformation will linger…
The other shortcoming of the “kill” approach which I should mention here is that it’s hard to include as an automatic clean-up, for example if the controlling BEAM process tree is shut down. That’s what lead me to push the signaling down into erl_child_setup or the analogous C shim program included in the rsync library.