How to launch a node with sudo on boot of Ubuntu?
Hi people! I have a question: How to startup the application when the OS is booting/finished boot?
I tried the systemd
method but the roslaunch
or rosrun
doesn't worked (started the ethercat and roscore, but not rosrun)...
I have to launch 4 commands, so I made a script (.sh) to launch the app:
#!/bin/bash
source ~/.bashrc
sleep 5;
/etc/init.d/ethercat start &
sleep 2;
roscore &
sleep 4;
rosrun <package_name> ethercat_driver &
sleep 6;
rosrun <package_name> controller_ros.py &
ethercat_driver
is a ROS node made in C++ and interconnect the Python App with EtherCAT driver I made.controller_ros.py
is a ROS node that contains all logic, DB connections and some other stuff.
If I execute directly this .sh, open all wonderfully:
$ sudo -s
# ./ros_node.sh
But some commands need to be executed with sudo -s
and the last one cannot (because the Python file contains the GUI made in PyQt5 and losses some stuff directives in sudo mode - note: appear an error called XDG_RUNTIME_DIR NOT SET
that I can't solve with super user, but using a non-admin user (the user that I created on install of OS), this error doesn't appear at all (!?)).
So... How to effectively launch ROS node at boot?
PS.: some commands don't run with sudo, for example:
$ sudo rosrun <package_name> ethercat_driver
will return:
rosrun command not found
but if:
$ sudo -s
# rosrun <package_name> ethercat_driver
works fine.
Thanks for the help. Using Ubuntu 18.04.4 LTS
Have you looked at robot_upstart? It works well for launching regular nodes, but I'm not sure how well it will handle your specific use case where you require sudo.
This package also was appointed by Edouard Renard (Udemy course: ROS for Beginners). However I need to have access to Internet and the industrial computer that I need to do this initialization has no remote access or free Internet to install the package - he is physically installed within a machine I built for a client. To take it from there is a lot of bureaucracy. Edouard told me that have other methods, but I searched and found almost nothing. This method of robot_upstart is the most reliable? Or do you have any other suggestions? I already tried replacing the
rosrun
androslaunch
by direct executable directory of putting this:but it did ...(more)
Thomas, I tested the solution using robot_upstart... Unfortunately, it did not work ...
I followed the tutorial and wrote the launch of my package as follows (
boot.launch
):After that I gave permission for a non-admin user can access the EtherCAT network interfaces, in
/etc/udev/rules.d/99-EtherCAT.rules
file:Soon after, I created a service for
crontab -e
to boot the EtherCAT server through the follow script (I tested as service insystemd
aswell with similar results):and ran the command:
All went well until then. Only when I reboot the PC, the service shows several errors, such as the package in C++ cannot open the ethercat interface and the Python part cannot run in sudo user (because the XDG_RUNTIME_DIR problem explained above) so, this prevent to load the PyQt5 HMI interface.
Is there any other way to run?
PS.: when I run (individually) the shell script above and then:
Run everything ok and nice, including the PyQt5 HMI I developed and the complete access to network interfaces using a non-admin user. So I'm sure it's not my script or my launcher or any hardware permissions that are causing this trouble.