adamwight
Any interest in a library that wraps rsync?
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
Most Liked
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:
- API docs: Rsync — rsync v0.1.0
- Library: rsync | Hex
- Source: Adam Wight / rsync_ex · GitLab
akash-akya
since the OS PID mapping is strictly internal and can’t be accessed from code.
BEAM does return OS PID: erlang — erts v16.1.1
iex> port = Port.open({:spawn_executable, "/usr/bin/cat"}, [])
#Port<0.11>
iex> {:os_pid, pid} = Port.info(port, :os_pid)
{:os_pid, 367095}
iex> {output, 0} = System.cmd("ps", [to_string(pid)], into: IO.stream())
PID TTY STAT TIME COMMAND
367095 ? Ss 0:00 /usr/bin/cat
adamwight
Thanks for the suggestion, here are my observations as a blog post: Elixir/Ports and external process wiring - ludd
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 kill sense 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!







