0

I have several small python scripts that I want to run in the background all the time on my pi zero w set-up. I currently have this problem 'solved' using cron, but I am curious. I see many sources that recommend putting these kind of tasks into /etc/rc.local instead.

Does anyone have insight on the current best practice in the latest distro of raspbian or in what situations one solution would be preferable to the other?

Many thanks,

M

3
  • 1
    "I see many sources that recommend putting these kind of tasks into /etc/rc.local instead." -> Beware that this is depreciated under systemd, although it will no doubt continue to be supported forever or thereabouts. It is probably the easiest method if you just want to do something one off or launch a program that backgrounds itself properly. But if you want to learn the most flexible and dynamic option, start reading about systemd services.
    – goldilocks
    Apr 27 '20 at 19:44
  • Thank you for the comment. It basically answers my question. I found a good resource that other may find helpful, too slippytrumpet.io/posts/running-your-app-as-service-on-pi-zero-w
    – Mitch
    Apr 27 '20 at 20:02
  • 1
    Neither are recommended. Build your own systemd service file and use that to get your process running. unix.stackexchange.com/questions/47695/…
    – Dougie
    Apr 28 '20 at 9:58
1

rc.local is a hangover from SysV days. Modern Linux uses systemd and attempts to generate a systemd service from the script.

How successful this is depends on the script contents. Most simple scripts with no dependancies should work.

In contrast to SysV systemd starts services asynchronously. This results in an OS which boots more quickly and doesn't hang on slow tasks but the script may run before startup is complete.

Cron may also run before all services are started.

Either may be used for simple tasks with no dependencies.

The only reliable method is to write a systemd service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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