1
$\begingroup$

I have two service files that are running ros code . When I start my system the service file B complains about not able to look for the robot model, then when I stop both service files and start manual using command roslaunch project-name launch file, and then starts service B it works , after that I close the manual roslaunch command using control c and start service file A and now when I restart service file B it works .

[Unit]
Description=ROS Launch Service
After=network.target

[Service]
ExecStartPre=/home/orangepi/one/killall_roscore_check.sh 
ExecStartPre=/bin/sleep 5
ExecStart=/home/orangepi/one/requried-files/run2.sh
Restart=always
User=orangepi

[Install]
WantedBy=multi-user.target

killall_roscore_check.sh

#!/bin/bash

if pgrep -x "roscore" > /dev/null; then
    echo "ROS is running. Restarting with rosmaster kill..."
    killall -9 rosmaster
else
    echo "ROS is not running. Skipping rosmaster kill."
fi

run2.sh

#!/bin/bash

# Source necessary setup files
source /opt/ros/noetic/setup.bash
source /home/orangepi/one/catkin_ws/devel/setup.bash

# Launch the ROS launch file and pipe its output to a while loop
roslaunch /home/orangepi/one/catkin_ws/src/project1/launch/run2_robot.launch





[Unit]
Description=ROS Launch Service
After=one.service

[Service]
#ExecStartPre=/bin/sleep 5
ExecStart=/bin/bash -c "source /opt/ros/noetic/setup.bash && source /home/orangepi/one/catkin_ws/devel/setup.bash && roslaunch /home/orangepi/one/catkin_ws/src/abc/project/launch/run.launch"
Restart=always
User=orangepi

[Install]
WantedBy=multi-user.target
$\endgroup$

1 Answer 1

1
$\begingroup$

Okay , I resolved this problem by providing service 2 20 seconds when restarting the computer using,

#ExecStartPre=/bin/sleep 20

By doing this I made sure that that that service file 1 is has provided everything on the parameter service and has launched all required file successfully.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.