Run Python Script on Reboot
Question
Is there a method to run a Python script when the EV3 Hub reboots? I want the script to run just as if I ran it using the VSCode plugin or using SSH and the brickrun command.
I was able to run an sh file using a systemd service. I can confirm that it was running as it was creating new files in my user folder. I had a line in the sh file that executed a python script using python and I tried running it using brickrun (absolute references to everything), but the python script did not seem to run.
I need the python script to run in a way that the screen changes to the play symbol (like when executed by VSCode or brickrun vis SSH).
Thanks!
You can write a systemd service to do this.
Totally untested, but maybe something like this at /etc/systemd/system/my-script.service. Then run sudo systemctl daemon-reload and sudo systemctl enable my-script.service.
[Unit]
Description=My Script
[email protected]
[Service]
Type=simple
ExecStart=/usr/bin/brickrun /home/robot/my-script.py
User=robot
[Install]
WantedBy=multi-user.target
Docs at
- https://manpages.debian.org/stretch/systemd/systemd.unit.5.en.html
- https://manpages.debian.org/stretch/systemd/systemd.service.5.en.html