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