1

I have a Raspberry Pi 3b+ that is booting to the pi user terminal, no GUI. I need to have a small CLI app run after the pi has finished booting.

So far I have tried editing /etc/rc.local, and using the @reboot in crontab.

Are these the best/correct ways to start an app that needs to be interacted with after bootup?

2 Answers 2

1

Many people like to use /etc/rc.local or @reboot from cron so I will not say it is not the best choice. But I will give you some infos that you have to take attention by using this.

Since version Jessie Raspbian replaces classic SysV init for booting with systemd. To be compatible it emulates SysV and /etc/rc.local is part of SysV. Look at Compatibility with SysV. You will find there:

Some SysV systems support an "rc.local" script that is supposed to be called "last" during boot. In systemd, the script is supported, but the semantics are less strict, as there is simply no concept of "last service", as the boot process is event- and request-based, parallelized and compositive. In general, it's a good idea to write proper unit files with properly defined dependncies, and avoid making use of rc.local.

For the same reason the starting conditions with @reboot in crontab can change. man 5 crontab says:

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.

A boot order sequence isn't defined with systemd.

0

Create a file with a name ending in .service in /etc/systemd/system with the following content:

[Unit]
Description=Write a short description
[Service]
Type=simple
User=pi
PermissionsStartOnly=true
ExecStart=/path/to/program
[Install]
WantedBy=multi-user.target

Now execute systemctl daemon-reload so that systemd picks up your new service, and systemctl enable myservice (replacing "myservice" with the name of your .service file) to enable it. Your program will run as the pi user on reboot.

If your program requires network connectivity to function, then add After=network.target to the [Unit] section.

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.