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

Systemd roslaunch

asked 2016-10-05 20:47:36 -0600

Andre_Preller_3000 gravatar image

updated 2016-10-05 20:49:55 -0600

I've recently migrated my ROS project to Ubuntu 16.04LTS and ROS kinetic since I was having stability issues with Ubuntu 14.04LTS. Unfortunately this means I can't use robot upstart anymore to run my roslaunch file at startup (afaik).

I've made an attempt at using systemd (based on this guide) to run a bash script which runs roslaunch at startup but I'm stuck trying to get everything to work.

my systemd file: (chmod 664)

[Unit]

Description=start runslam

After=mysql.service

[Service]

ExecStart=/usr/local/bin/runslam.sh

KillMode=process

[Install]

WantedBy=default.target

my bash script: (chmod +x)

#!/bin/bash

roslaunch runslam slam.launch

Just running the bash script from the terminal starts up roscore and my project runs fine but when running:

$ sudo systemctl start runslam.service

$ systemctl status runslam.service

I get the following output:

● runslam.service - start runslam
Loaded: loaded (/etc/systemd/system/runslam.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2016-10-06 11:36:29 AEST; 7s ago Process: 3746 ExecStart=/usr/local/bin/runslam.sh (code=exited, status=127) Main PID: 3746 (code=exited, status=127)

Oct 06 11:36:29 ausdroid-sbc-flt1 systemd[1]: Started start runslam.

Oct 06 11:36:29 ausdroid-sbc-flt1 runslam.sh[3746]: /usr/local/bin/runslam.sh: line 3: roslaunch: command not found

Oct 06 11:36:29 ausdroid-sbc-flt1 systemd[1]: runslam.service: Main process exited,> code=exited, status=127/n/a

Oct 06 11:36:29 ausdroid-sbc-flt1 systemd[1]: runslam.service: Unit entered failed state.

Oct 06 11:36:29 ausdroid-sbc-flt1 systemd[1]: runslam.service: Failed with result 'exit-code'.

I think "roslaunch: command not found" means that the ROS environment needs to be somehow specified in the systemd file does anyone know how to do this? Thanks.

edit retag flag offensive close merge delete

Comments

Note it may be advisable to use KillSignal=2 as roslaunch seems to respond to SIGINT instead of the default SIGTERM

Rufus gravatar image Rufus  ( 2020-03-19 04:46:50 -0600 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2016-10-06 00:37:35 -0600

Mani gravatar image

updated 2016-10-06 00:39:05 -0600

I have not used systemd myself for this task, but I've used the following method in a fairly similar situation to wrap roslaunch.

Change /usr/local/bin/runslam.sh to:

#!/usr/bin/env bash
bash -c "source /path/to/catkin_ws/devel/setup.bash && roslaunch runslam slam.launch"
edit flag offensive delete link more

Comments

Brilliant! Thankyou Mani that did it :)

And just for the sake of completeness, since posting I made the following changes to the systemd file:

  • "After=network.target"

*got rid of the KillMode line

*Added "Restart=on-abort" under [Unit]

Andre_Preller_3000 gravatar image Andre_Preller_3000  ( 2016-10-06 21:44:23 -0600 )edit
1

You are welcome. I am glad it worked. One thing you can do is to post your full solution online (i.e. as a Github gist) and provide a link in your question for future reference.

Mani gravatar image Mani  ( 2016-10-06 21:58:31 -0600 )edit

You sir are a boss. Thanks!

calvertdw gravatar image calvertdw  ( 2017-04-05 18:54:52 -0600 )edit
1

answered 2019-07-23 01:48:04 -0600

Floris gravatar image

updated 2019-07-24 01:13:06 -0600

FYI: (code=exited, status=127) means that a command is not recognized. This is because ROS hasn't been sourced when the service is starting up. As @Mani mentioned: just add the source /path/to/ros/setup.bash to you script file so it recognizes the ros commands you use.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-10-05 20:47:36 -0600

Seen: 6,990 times

Last updated: Jul 24 '19