In most modern Linux systems (incl the RPi OS), what happens during the boot process is controlled by the init
process. While there are several different init
software implementations, many of today's distros (including RPi OS) have adopted systemd
- as you have recognized by use of your prototype sudo systemctl restart my_puredata.service
.
In general, for RPi OS, you have two good options for starting a program during or shortly after the boot process:
- Write a systemd unit
- Set up a
cron
job under the @reboot
schedule
If your program/service has complex dependencies, and/or needs to start at a specific point in the boot process, you may be best-served by creating a systemd
unit. If your program is not that complex, cron
may serve your needs with less effort. (FYI: The cron
daemon is actually started by systemd
)
You didn't provide much information on your application/service, and therefore it's not clear from here what your best choice is. However, both cron
and systemd
provide facilities for delaying the start of a service by a specified sleep
time:
For systemd
it's rather more arcane, but there's a detailed description in this SO Q&A
For cron
it's simpler - just append a sleep
command prior to the command/script to start your service: e.g. in your crontab
:
@reboot /usr/bin/sleep 6; /path/to/startscript > /home/pi/cronjoblog 2>&1
Here's a link to another answer that provides a comparison between cron
and systemd
.
One final note: If you're using cron
, and the service requires root privileges, you must use the root crontab
; i.e. sudo crontab -e
instead of crontab -e
.
sudo systemctl enable my_puredata.service
to get it running at every boot.