Autostart service after system boot

Sometimes, It is more convenient to run ROS launch files automatically after robot’s computer boots up. For example, if you are working with multiple drones in a swarm, it is painful to log into each drone and run mavros manually. So, to solve this issue, we can run mavros automatically after system boots. This tutorial shows you one way on how to run ROS launch file after system starts.

Create a simple systemd service

Use case: auto start MAVROS node

  • Create a shell script and type the commands that you would execute in a normal terminal. Fro example,
mkdir ~/scripts
cd ~/scripts
chmod +x

Type the following in the file (you can use the nano command). It is assumed that the username is odroid

source /opt/ros/kinetic/setup.bash
source /home/odroid/catkin_ws/devel/setup.bash
roslaunch mavros px4.launch
  • Create mavros.service file in /lib/systemd/system
cd /lib/systemd/system
sudo nano mavros.service
  • Add the following contents:



Save and exit by hitting CTRL+x, then Y, then [ENTER]

Then run:

sudo systemctl daemon-reload

And enable it on boot:

sudo systemctl enable mavros.service

Then, reboot and px4.launch should be executed after boot.

To disable a service,

sudo systemctl disable mavros.service