0

There are many other questions about running a script on startup, but I am specifically interested in getting a short Python script to run as soon as possible when the Pi boots.

All it requires is SPI to write to a TFT display (ILI9341). The screen is initially white, so I'd like to display something as soon as possible to appease the user. I'm running Raspbian Stretch on a RasPi 3 and it takes 16 seconds from when I connect power to when the script runs.

The script is in /etc/init.d/MSDriver.sh, which runs a show-logo.py. Currently the following is used to make it run on startup: sudo update-rc.d MSDriver.sh defaults 95 05 I've tried lowering 95 to 01, as from what I understand a lower number means a higher start priority. Even still, it takes 16 seconds from power-on to when the script runs.

Here's my LSB header: (I've prepended slashes only to stop raspi.SE from rendering them as headers) \#!/bin/sh \### BEGIN INIT INFO \# Provides: MSDriver \# Required-Start: hostname $local_fs \# Required-Stop: \# Should-Start: \# Default-Start: 2 3 4 5 \# Default-Stop: 0 1 6 \# Short-Description: Start/stop MSDriver \# Description: This script starts/stops MSDriver. \### END INIT INFO

How can I get this script to run sooner?

(kindly let me know if there's anything I can do to improve my question, thanks! :)

1

You might for starters use a systemd service file instead of a SysV style script, since those are supported for backward compatibility only (SysV is no longer used on most current linux distros, including Raspbian, so do not bother with online blogs etc. which reference it). This will provide you with some more fine tuned control. See in particular the Before and After clause in man systemd.unit:

Before=, After= A space-separated list of unit names. Configures ordering dependencies between units. If a unit foo.service contains a setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service is started up. Note that this setting is independent of and orthogonal to the requirement dependencies as configured by Requires=, Wants= or BindsTo=....

You might have a look at the output of systemd-analyze critical-chain for clues about what you want to to use in a "Before" clause; see man systemd-analyze for how to interpret the output. A more detailed big picture is available with systemd-anaylze plot (see here for an example of that).

Examples of service files can be found in /etc/systemd/system and /lib/systemd/system; they are enabled/disabled/started/stopped etc. via systemctl ... (see man systemctl).

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.