1. Make test script
First, we need to make a script to test whether the self startup is effective.
pi@raspberry :~ $ nano /home/pi/start.sh
The contents of start.sh are as follows:
/usr/bin/python3 /home/pi/GeometryOperations.py
Here, you must pay attention to the use of absolute paths, otherwise there is a probability that the load will fail.
Then add an execution file to the script file
pi@raspberry :~ $ chmod 777 start.sh
Test the script function
pi@raspberry :~ $ ./start.sh
If you observe that the program is running normally, you can continue to the next step
2. Add self start
Modify rc.local file
pi@raspberry :~ $ sudo nano /etc/rc.local
Find exit 0 in the text. The code added before will be executed at startup. Add a line of code before exit 0:
su pi -c “exec /home/pi/start.sh &”
CTRL + O to save, Ctrl + X to exit and restart.
pi@raspberry :~ $ sudo reboot
After restart, the program can run.
3.DEBUG
If the raspberry pie does not respond after restart, you can check the status of RC local through systemctl
pi@raspberry :~ $ sudo systemctl status rc-local
After you go in, you can see the status of each step after you start up and check where the error will be reported.
4. Possible error reports
Process:454 ExecStart=/etc/rc.local start (code=exited,status=1/FAILURE)
This error is probably due to the script file
if you just start, you must write the file path as an absolute path, otherwise an error will be reported.
error: (-2:Unspecified error) Can’t initialize GTK backend in function ‘cvInitSystem’
This error will be reported if the self startup program contains code with window operation such as OpenCV
The reason is caused by the following sentence
su pi -c “exec /home/pi/start.sh &”
If your command needs to run for a long time (such as an endless loop) or cannot exit after running, you must ensure that the “& amp;” symbol is added at the end of the command to make the command run in its background
If the code contains window interface operations similar to the following
cv2.namedWindow(‘Cap’)
cv2.imshow(‘Cap’, frame)
It will conflict with the background operation, so that the back end of GTK cannot be initialized and an error will be caused
the solution is to delete all the operations related to the interface and window, and the program can run well!
Read More:
- Raspberry pie set up to run Python program automatically
- How to login raspberry pie
- RabbitMQ Startup Script (How to Set)
- Raspberry pie view IP address (command ifconfig) and exit Ping
- Raspberry pie upgrade to Python 3.7.3
- Several ways to check the IP address of raspberry pie
- Source code analysis of macOS startup process
- Java jar close startup script
- A method to solve the error – 110 whilst initializing SD card of raspberry pie
- The remote port occupation of Linux startup jar package script reports an error
- Error: Command ‘arm linux gnueabihf GCC’ failed with exit status 1, raspberry pie install paramiko
- Solution of apt unable to update in the docker container of raspberry pie
- Windows Java application startup batch script
- Raspberry pie 4B uses adafruit_ Pca9685 report error ioerror: [errno 121] remote I / O error solution
- Solve the problem of raspberry pie using GStreamer. Importerror: cannot import name XXX introspection typelib not found
- Using openfeign to remotely call the startup program to report an error
- Solution to error 2002 (HY000) in MySQL login startup
- Troubleshooting of samba error in Linux configuration startup
- Common problems of Hadoop startup error reporting
- Some problems about startup