3

I’ve got a little program that uses an spi hat that I set to start running from rc.local.
It was all running fine under Jessie, but I’ve upgraded to Stretch and now it appears rc.local is being called before the /dev/spidev.* device files have been created, so the application fails to start. Once the login prompt appears I can start the app manually and the spi system works fine, so it just seams like a matter of timing and waiting for the spi dev files to be created.

I’m trying to work out what part of the boot process is creating the files in dev, so I can setup a systemd service that waits for them before starting my app. I have a working service that calls the app, but it’s having the same issue as rc.local and starting too early.

Anyone have any ideas or pointers as to where I should look?

nebulus
  • 41
  • 5

2 Answers2

1

rc.local is part of the old init which was made obsolete by systemd, introduced in Jessie.

systemd boot runs many processes in parallel, and the only way to manage these is with a systemd service which manages dependencies.

There is NO simple fix.

NOTE systemd attempts to run rc.local, but is only successful for simple tasks - it is best to avoid it.

Generally you should setup SPI devices in Device Tree.

You should ask a more specific question about the devices you are attempting to use.

Milliways
  • 62,573
  • 32
  • 113
  • 225
1

It is difficult to give concrete advices with your only general information. The way to solve your problem is systemd. The old style SysV init system with rc.local is only emulated by systemd and it seems with higher versions of systemd the developer take less care of backward compatibility. I can understand this.

Polling for services isn't the right way to think. As already said systemd is working parallel. The order of execution of services at boot time is not defined! You only have to think in dependencies. A good entry to this issue is systemd bootup. For your problem with /dev/spidev.* is not available it may be good to start your program After=local-fs.target or After=.paths.target. After=basic.target is always a good general dependency. RequiresMountsFor=/dev/spidev or ConditionPathExists=/dev/spidev are also possibilities (see man systemd.unit). Look at the references for some examples.


references:
[1] Run script to setup Socks Proxy on Pi Startup
[2] Running a script after an internet connection is established
[3] Python script run from crontab does not recognize USB drive mounted later
[4] No access to USB port, when running python script on boot
[5] Python script does not run when called by service

Ingo
  • 42,961
  • 20
  • 87
  • 207