ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Remotely Launch Nodes in ROS2

asked 2020-10-26 06:30:10 -0600

smorad gravatar image

Is there a way to remotely launch nodes in ROS2? This could be done in ROS1 using the <machine> attribute. It's listed in the ROS2 design document but I can't figure out how to use it. I'm using the python launch and launch_ros libraries.

edit retag flag offensive close merge delete


Hi. Same need. I didn't find into the documentation...

resnault gravatar image resnault  ( 2021-04-01 03:34:10 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2022-04-26 06:23:11 -0600

afrixs gravatar image

updated 2022-04-26 11:59:52 -0600

I've just found a way to perform a remote launch from a python launch file using the ExecuteProcess launch action. There are several problems you're going to face if you go this way, so here are the workarounds I used to solve them (on Ubuntu 20.04).

First, let's state what we are trying to achieve:

  1. We have a main machine A and a machine B reachable via ssh pi@ from machine A (without a password, i.e. use ssh-keygen -t rsa -b 2048 && ssh-copy-id pi@ first)
  2. We have a launch file in drinks_hmi_bringup package on machine B (we can launch it from machine B via ros2 launch drinks_hmi_bringup
  3. We have a launch file in drinks_bringup package on machine A which is supposed (among other actions) to launch on machine B

Now the following command should work from machine A, i.e. it launches the nodes, prints out output and can be terminated via SIGINT (Ctrl+C):

ssh -t pi@ 'bash -i -c "ros2 launch drinks_hmi_bringup"'

However, after putting it directly into ExecuteProcess action in, the process complains about not having a proper tty console and the nodes on machine B are not terminated after terminating the ros2 launch drinks_bringup process.

A workaround is to call the above command inside a detached screen (use sudo apt install screen if not present). This, however, raises two further problems:

  • The screen does not pass SIGINT from calling process to inner processes, so it does not terminate the nodes when Ctrl+C is pressed. However it can be terminated explicitly using a remote_launch_terminator node which calls screen -S hmi -X quit (see the complete solution below)
  • The screen does not pass output from inner processes to calling process, so this needs to be done explicitly by redirecting inner output to outer

The complete solution is as follows:


import rclpy
from rclpy.node import Node
import os

def main(args=None):

    node = Node('remote_launch_terminator')
    node.declare_parameter('screen_pid', 'remote')
    screen_pid = node.get_parameter('screen_pid').get_parameter_value().string_value


    print('Terminating ' + screen_pid)
    os.system('screen -S ' + screen_pid + ' -X quit')

if __name__ == '__main__':


import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions.execute_process import ExecuteProcess

def generate_launch_description():
    return LaunchDescription([

        # other actions

        # remote launch
            cmd=['{ outer_stdout=$(readlink -f /proc/self/fd/3); } 3>&1 && screen -DmS hmi bash -i -c "ssh -t pi@ \'bash -i -c \\"ros2 launch drinks_hmi_bringup\\"\' > $outer_stdout"'],
            parameters=[{'screen_pid': 'hmi'}]

Hope this helps, cheers! ;)

Note: ExecuteProcess action does not work inside OnShutdown event, that's why ... (more)

edit flag offensive delete link more

answered 2021-06-07 23:16:00 -0600

shonigmann gravatar image

updated 2021-06-07 23:17:44 -0600

As far as I can tell, this is still a work in progress, but has been on the backlog to get merged into the documentation. Lots of discussion here, and it seems the change to the documentation is awaiting approval to get merged in.

The tentative document can be found here, but it doesn't look like the proposed changes have made their way into code yet.

I'd imagine it is pretty low priority because ssh is possible on all the tier 1 platforms (ever since Windows joined the club).

edit flag offensive delete link more



It has been quite some time since this was posted. Could anyone comment on when support for remote-launching nodes via roslaunch can be expected to make it into ROS2?

alikureishy gravatar image alikureishy  ( 2022-02-17 14:04:33 -0600 )edit

answered 2022-09-19 11:50:06 -0600

gerok gravatar image

My answer to this is to use the existing linux system to do this: systemd. Basically do the following:

On the target machine, the machine you want to run remote nodes on, do the following:

  1. Make sure the nodes you want to run are on the remote machine already and it's already built on that machine.
  2. Make a bash script that executes ros2 launch and sources the right install directory. We'll call this This is a script because you might want to do other things with this.
  3. Make a remote_ros.service file that runs the script. This can be setup to start on boot or not.

On the local machine, the machine you want to launch remote nodes on, do the following:

  1. Make a launch script that SSHes into the remote machine and executes systemctl stop remote_ros and/or systemctl start remote_ros. This can be done with the ExecuteProcess launch action.

Stop will kill the nodes and start will bring them up. If you don't want to stop the nodes, I believe start is a NOOP if they are already running.

I think this solution is more straight forward than the others presented and ideally the service just runs all the time, but you can always kill it with the systemctl stop command.

edit flag offensive delete link more

answered 2023-05-20 07:15:56 -0600

ketill gravatar image

I have found a solution that works for me be using rosbridge to remotely publish service messages to start or stop processes.

  1. First I made rosbridge and a ros2 node start on boot of the device by:

sudo vim /etc/systemd/system/ros2node.service

Description=Start ROS2 Node

ExecStart=/bin/bash -c 'source /opt/ros/humble/setup.bash; source 
/home/ketill/Documents/ros2_script/ros2_ws/install/setup.bash; ros2 launch rosbridge_server 
rosbridge_websocket_launch.xml; ros2 run node_starter talker'


sudo systemctl enable ros2node.service sudo systemctl start ros2node.service

and similar for the node. 2. The a node for handling the processes depending on the service message for the gui

class NavigationService(Node):

def __init__(self):
    self.srv = self.create_service(SetBool, 'start_navigation', self.handle_service)
    self.process = None
    self.hasStartedOnce = False

def handle_service(self, request, response):
    response.success = self.run_navigation_launch_file(
    response.message = 'Navigation launch started.' if response.success else 'Failed to start navigation launch.'
    return response

def run_navigation_launch_file(self, start):
    if start and not self.hasStartedOnce:
        command = "source /opt/ros/humble/setup.bash; source /home/ggeo/auto_gpr/install/setup.bash; ros2 launch auto_gpr"
        self.process = subprocess.Popen(command, shell=True, executable="/bin/bash", preexec_fn=os.setsid)
        self.hasStartedOnce = True
        return self.process.poll() is None  # return True if process is running
        # Implement logic to stop the process here
        if self.process is not None:
            os.killpg(os.getpgid(, signal.SIGINT)  # Send the signal to all the process in the group
            self.process = None
            self.hasStartedOnce = False
        return False

def main(args=None):

navigation_service = NavigationService()



if __name__ == '__main__':

This solution make it possible to start remotely as long as the devices are on the same network.

edit flag offensive delete link more

Question Tools



Asked: 2020-10-26 06:27:28 -0600

Seen: 1,549 times

Last updated: Sep 19 '22