clearpathrobotics / robot_upstart

ROS package of helper functions related to bringing up roslaunch on system startup.
BSD 3-Clause "New" or "Revised" License
196 stars 96 forks source link

Please add systemd WorkingDirectory to service template #125

Open symmetryninja opened 2 months ago

symmetryninja commented 2 months ago

Greetings, I love this plugin and use it often!

Recently I've attempted to use robot_upstart to run a ros launch file that called a service that uses the LGPIO library (https://pypi.org/project/rpi-lgpio/) to interact with the GPIO pins on the PI. The lgpio library creates some sort of hardlink or softlink to call the gpio access with non-root privileges, it does this wherever the launch file is executed.

When run as a service, the launch file is triggered in a folder unwritable to the user and thus can't create the link and therefore can't call the GPIO pins.

Guidance on the internets is to run the service as root, which is clearly a bad idea.

After running the upstart in python, I can make the code work by editing the service file:

# THIS IS A GENERATED FILE, NOT RECOMMENDED TO EDIT.
[Unit]
Description="bringup gpio_flasher"
After=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/gpio_flasher-start
WorkingDirectory=/home/ubuntu/ros2_ws
[Install]
WantedBy=multi-user.target

It would be great if this was part of the python code so this hacky fix could survive re-runs.