Skip to content

Control systemd services using ROS2 standard services

Notifications You must be signed in to change notification settings

Fixit-Davide/ros-systemctl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ROS2-systemctl Node

Ubuntu 22.04 Iron Build Ubuntu 22.04 Rolling Build

systemctl is a command line utility that is used to control and manage system services on Linux operating system. This Node enables the communication with systemctl using basic ROS2 services (std_srvs::srv::Request). It allows the user to start, stop, restart and visualize the status of a specific system service.

How to Use:

  • In order to function correctly as a normal user, the custom Systemd unit file has to be generated in the ~/.config/systemd/user/ directory.
  • In the params file the names of the systemd services can be set as a simple list omitting the .service extension of the name.
  • Similarly, it is possible to change the name of the ROS2 services in order to make node integration and customization easier.

Custom systemd services

The rover automatically launch a set of custom systemd services which start the CanBus channel, the locomotion and joystick ROS2 node when the system is turned-on. In this way the rover can be moved around without launching any nodes through a terminal.
The custom service files are located in:

  • ~/.config/systemd/user/ : for the services that are controlled by the user.
  • /etc/systemd/system/ : for the services that are generated by the root.

Each service calls for a custom program located in /usr/local/bin/ directory that executes a determined set of commands.
To write a custom systemd service:

  • First create a file inside the ~/.config/systemd/user/ folder (if the folder does not exsit create one) or the /etc/systemd/system/. The file's name must end with the .service appendix (example foo.service).
  • Each service file must follow a specific convention in order to be executed correctly by the system.
[Unit]
Description= brief description of the service.
# number of try to restart the service.
StartLimitIntervalSec=100
StartLimitBurst=5
#In order to start a specific service is required before.
Wants=foo_required.service
#Start after another service.
After=foo_required1.service

[Service]
#The service calls for a specific exec file.
ExecStart=/usr/local/bin/foo
Restart=on-failure
RestartSec=3s

# Hardening
SystemCallArchitectures=native
NoNewPrivileges=true

[Install]
WantedBy=default.target
  • Create an exec file inside the folder /usr/local/bin/ that is called by the service. (In matter of fact any other folder can be used). It is preferable to use the /usr/local/bin/ mainly due to the fact that the exec becomes a simple bash command that can be also called using the terminal. (i.e. example file)
#!/bin/bash
source /home/roxy/ros2_iron/install/setup.sh
source /home/roxy/ros2_iron_ws/install/setup.sh
ros2 launch foo_node foo_node.launch.py