Roslaunch Using SystemD Services
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:
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?
What should I have the service file config parameters set to for Killmode, Restart, Reload, etc... ?
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
Asked by grejj on 2020-09-17 12:58:45 UTC
Answers
Please refer to: https://answers.ros.org/question/245089/systemd-roslaunch/
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
Asked by twdragon on 2023-04-27 10:44:51 UTC
Comments