This package provides and implementation of the launch.Machine
class that
can be used to launch processes on remote machines via SSH. It is intended
to be used together with the multi-machine-launching
branch in my fork of
the launch
repository:
https://github.com/pjreed/launch/tree/multi-machine-launching
This has been tested in ROS 2 Foxy on Ubuntu 22.04. It
also requires the python3-asyncssh
package.
Create a workspace, or clone these repos into an existing one:
# Set up the workspace
. /opt/ros/foxy/setup.bash
mkdir -p ssh_machine_ws/src
cd ssh_machine_ws/src
git clone -b multi-machine-launching https://github.com/pjreed/launch.git
git clone https://github.com/pjreed/ssh_machine.git
# Install dependencies
rosdep install . -y --from-paths -i
# Build it
cd ..
colcon build --symlink-install --allow-overriding launch launch_testing launch_testing_ament_cmake launch_xml launch_yaml
. install/setup.bash
# Run the demo; edit ssh_machine/launch/pub_sub.launch.py to use a machine you can access
ros2 launch ssh_machine pub_sub.launch.py
In my fork of the launch
repository, the launch.actions.ExecuteProcess
class
has been modified to accept a machine=
argument that defines how the process
should be launched. That repo also contains a launch.LocalMachine
class that
implements the previous functionality and will launch a process on the local host;
this is the default behavior if no machine is specified.
This repository defines an ssh_machine.SshMachine
class that uses the asyncssh
library to launch processes on a remote host. It works by creating an SSH channel
to the configured host, then running processes in the background; when it is
told to shut down, it kills all background processes and then exits. It takes
two arguments; a hostname
that specifies the host name (or IP) of the remote
host, and an env
that specifies a script that should be sourced to configure
the environment (for example, /opt/ros/foxy/setup.bash
).
This is a naive implementation that needs to be made more robust for practical use. Currently:
demo_nodes_cpp
and executable talker
on a remote host, if the
local host is using ROS Foxy, then it will be resolved to
/opt/ros/foxy/lib/demo_nodes_cpp/talker
before it is executed on the
remote host.