I need to write this line of code on my Pi terminal in order to make my music software to work

sudo systemctl restart my_puredata.service 

How can I make Pi automatically execute this line of code every time is booting?

Is it also to give it some delay time? Meaning run this line of code but only after 6 seconds from boot?


  • Search for run a command after boot. This question has been asked and answered many times.
    – joan
    Dec 2, 2022 at 9:44
  • I have added this line: sudo systemctl restart my_puredata.service to the rc-local file. but it not seems to help. is there anyway I could delay that command in a few seconds?
    – user150653
    Dec 2, 2022 at 10:47
  • Use sudo systemctl enable my_puredata.service to get it running at every boot.
    – Dougie
    Dec 2, 2022 at 13:47

3 Answers 3


https://linuxhint.com/use-etc-rc-local-boot/ You don't need the "sudo" but it is important to remember /etc/rc.local is discontinued and replaced by Systemd, and instructions for using that are further down the same page


Here, because of the delay requested, I would choose to use cron.

Create a script /usr/local/bin/puredata.cron.sh with:


sleep 6
systemctl restart my_puredata.service

and make it executable (chmod a+rx /usr/local/bin/puredata.cron.sh)

In the crontab for root add (sudo crontab -e)

@reboot /usr/local/bin/puredata.cron.sh
  • how do I creat a script: " /usr/local/bin/puredata.cron.sh"
    – user150653
    Dec 2, 2022 at 21:21
  • I type into terminal : sudo nano /usr/local/bin/puredata.cron.sh I then write the script you suggested. after saving I run: chmod a+rx /usr/local/bin/puredata.cron.sh . I'm getting error: chmod changing permission of ... : Operation not permitted . How can I fix that?
    – user150653
    Dec 2, 2022 at 22:26
  • sudo chmod a+rx /usr/local/bin/puredata.cron.sh
    – starkus
    Dec 3, 2022 at 7:35
  • how can I delete the puredata,cron.sh thatI created? I went into: ls /usr/local/bin/ . I then type: rm puredata.cron.sh. but it not give me to delete it
    – user150653
    Dec 3, 2022 at 17:59
  • The questions that you ask in the comments show that you need an introduction to the Linux command line. Google "introduction to the linux command line" ans select one. Dec 3, 2022 at 22:08

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:

  1. Write a systemd unit
  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.