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

How to Run ros2 launch file using service file [closed]

asked 2021-02-09 09:11:25 -0500

Flash gravatar image

updated 2021-02-09 12:57:32 -0500

gvdhoorn gravatar image

Hi, I am trying to run launch file in ros2 using service file but I am unable to do it.

[Unit]
After=network-online.target
Description=desc

[Service]
Environment=source home/$USER/dev_ws/install/setup.bash
ExecStart=ros2 launch topics topic.launch.py
RemainAfterExit=no
Restart=on-failure
RestartSec=2s

[Install]
WantedBy=user.target

This is the error I am getting

Invalid environment assignment, ignoring: source
Feb 09 09:59:54 USER-pc systemd[1]: /etc/systemd/system/name.service:6: Invalid environment assignment, ignoring: home/USER/dev_ws/install/setup.bash
Feb 09 09:59:54 USER-pc systemd[1]: /etc/systemd/system/name.service:7: Executable "ros2" not found in path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Can anyone please helpme

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Flash
close date 2021-10-07 15:02:22.936492

1 Answer

Sort by ยป oldest newest most voted
4

answered 2021-03-25 10:37:03 -0500

Flash gravatar image

I was able to resolve this issue by sourcing and running the launch file by using /bin/bash -c

ExecStart=/bin/bash -c 'source /opt/ros/foxy/setup.bash; source home/$USER/dev_ws/install/setup.bash; ros2 launch pkg_name launch_file_name.launch.py; sleep 60'
edit flag offensive delete link more

Comments

Hi there, why do you have sleep 60? How is this important? Some sort of protection?

robopo gravatar image robopo  ( 2021-11-23 07:07:11 -0500 )edit

not that necessary, just gave it 60 sec before it starts again. If you have any other processes that need to close before you restart this might be a good option.

Flash gravatar image Flash  ( 2021-11-23 10:06:32 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-02-09 09:11:25 -0500

Seen: 960 times

Last updated: Mar 25 '21