I am running a python script on my Pi 3 B+ and registered it in a crontab @reboot so it is executed when booting the system. On my development Pi everything works fine, but when I clone the SD-Card and boot another Pi it takes up to 5 minutes until the python script is executed (thismeans an increase by factor 10). So I wonder if there is any known issue that may cause this behavior. I am running Raspbian Stretch (latest version).

  • 1
    How have you catered for network addresses being the same? – joan Oct 18 '19 at 20:41
  • @joan: The tested Pis are behaving like this without being connected to any network. – AlexRust Oct 19 '19 at 16:48

Raspbian is using systemd as init system and to manage services and to emulate old style daemons from the deprecated SysV init system. For compatibility issues look at Compatibility with SysV. crontab is such an emulated system in particular its @reboot function. systemd uses its own *.timer services and Unit files to start services.

In man 5 crontab you can find:

Please note that startup, as far as @reboot is concerned, is the time when the cron(8) daemon startup. In particular, it may be before some system daemons, or other facilities, were startup. This is due to the boot order sequence of the machine.

This is the reason why your script starts later on the productive installation: it does not have the same boot order of its services. And no, you can't define a boot order. On systemd with its parallel execution of starting services a boot order doesn't make sense. You have to define dependencies.

You should use a regular Unit file to start your python script. You will find many examples here on this site how to do it.

  • I don't follow. Surely a cloned card has the same software. Why should the boot sequence be different? – joan Oct 19 '19 at 10:33
  • @joan Its running on a different hardware. Anyway, its always a good idea not to use deprecated functions in particular if you have problems. – Ingo Oct 19 '19 at 12:16
  • The OP doesn't say there are any hardware differences. – joan Oct 19 '19 at 12:21
  • @joan Quote: "..and boot another Pi it takes up to 5 minutes until the python script is executed". – Ingo Oct 19 '19 at 12:22
  • Yes, I understand it is a different physical Pi. I just disagree that the boot sequence will have any relevance in these circumstances. The OP has made no mention of any difference in the hardware. – joan Oct 19 '19 at 12:27

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.