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

Roslaunch Using SystemD Services

asked 2020-09-17 12:58:45 -0600

grejj gravatar image

I am currently having issues related to using systemd services to start launch files, roscore, etc... mainly with regard to restarting services, processes getting stuck, taking a long time to shutdown etc...

I currently have just single launch file on my robot that launches all the necessary nodes, loads URDF, etc...

To start this from boot, I am using 2 systemd services, one to start roscore and one to start the main launch file. The systemd service files for both of these services are listed below.

My main questions are:

  1. Should I have 2 separate services, one for roscore and one for roslaunch since roslaunch will automatically start a roscore instance if one is not running?

  2. What should I have the service file config parameters set to for Killmode, Restart, Reload, etc... ?

  3. Any other advice for this or better ideas on how to initiate the roslaunch from startup is appreciated.

roscore.service ----------

[Unit] Description= Ros Core Service
Wants=network-online.target
After=network.target network-online.target

[Service]
Type=simple
EnvironmentFile=
ExecStart=/usr/bin/roscore.sh
#ExecReload=/bin/kill -HUP $MAINPID
#KillMode=process
#TimeoutStopSec=3
#Restart=on-failure
#RestartSec=5

[Install]
Alias=roscore
#WantedBy=multi-user.target

automation.service----------

[Unit]
Description=Automation Service
Requires=roscore.service

[Service]
Type=idle
EnvironmentFile=
ExecStart=/usr/bin/automation.sh
#ExecReload=/bin/kill -HUP $MAINPID
#KillMode=control-group
#TimeoutStopSec=3
#Restart=on-failure
#RestartSec=5

[Install]
WantedBy=multi-user.target

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-27 10:44:51 -0600

twdragon gravatar image

updated 2023-04-27 10:46:31 -0600

Please refer to: https://answers.ros.org/question/2450...

I use the following unit files for running roscore and ROS websocket bridge (my ROS installation is isolated):

roscore:

[Unit]
Description=Robot Operating System core RPC driver [system-wide]
Documentation=http://wiki.ros.org/
After=syslog.target network.target time-sync.target network-online.target
Wants=network-online.target 

[Path]
PathExists=/util/ros

[Service]
Type=simple
Restart=on-failure
User=robot
Group=robot
Environment=ROS_MASTER_URI=http://localhost:11311
Environment=LD_LIBRARY_PATH=/util/lib:/util/llvm/lib:/util/ffmpeg/lib:/util/qt/lib:/util/ros/lib:$LD_LIBRARY_PATH
#Runtime
ExecStart=/bin/bash -c 'source /util/ros/activate.bash; roscore'

#Accounting
CPUAccounting=true
CPUQuota=100%
MemorySwapMax=0

[Install]
WantedBy=multi-user.target

ros-websocket-server:

[Unit]
Description=Robot Operating System Autobahn Websocket server [system-wide]
Documentation=http://wiki.ros.org/
After=ros-core.service
Requires=ros-core.service

[Service]
Environment=ROS_MASTER_URI=http://localhost:11311
Environment=LD_LIBRARY_PATH=/util/lib:/util/llvm/lib:/util/ffmpeg/lib:/util/qt/lib:/util/ros/lib:$LD_LIBRARY_PATH
User=robot
Group=robot
Type=simple
Restart=on-failure

#Runtime
ExecStart=/bin/bash -c 'source /util/ros/activate.bash; roslaunch --wait rosbridge_server rosbridge_websocket.launch'
RestartSec=2s
KillSignal=SIGINT
TimeoutStopSec=5s

#Accounting
MemoryAccounting=true
MemoryHigh=512M
MemoryMax=1024M
MemorySwapMax=0

[Install]
WantedBy=multi-user.target

The activation script /util/ros/activate.bash:

#!/usr/bin/env bash
ROS_INIT_SCRIPT="/util/ros/setup.bash"
if [[ -f "${HOME}/.bashrc" ]]
then
    source ${HOME}/.bashrc
fi

PS1="[ROS] ${PS1}"

source ${ROS_INIT_SCRIPT}

export ROS_LOG_DIR="/util/ros/log"
export ROS_ENVIRONMENT_ACTIVATED=1
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-09-17 12:58:45 -0600

Seen: 1,621 times

Last updated: Apr 27 '23