A couple years ago I created a web app that I ran on a Pi 3. I added
sudo /home/pi/jobs/RotaryJobs &
to the /etc/rc.local file and it still works fine.
I have a new Pi 4 and rc.local no longer works. I can run the app by getting in the proper directory and typing
sudo ./RotaryJobs &
but I can’t start it with rc.local.
The Pi 3 has not been running since Covid shut down the Rotary club and the “apt-get update” returns say most of the repositories are no longer available so I am wondering if rc.local no longer works. Any suggestions for starting the app would be greatly appreciated.
I am running the latest version of Raspbian GNU/Linux 10 (buster)
I followed John’s example exactly just updating the app name to my latest app. It does not work. It may work for a regular app, but I found I had to run as root to use port 80. I switched to User=root, but it still does not work. I even tried putting an ampersand, &, after the app name the way I do when I run it in Terminal and it did not help.
Ideally, I would like to run the program in /opt under root so users won’t find it and corrupt anything.
FWIW, I did manage to just get a standalone app running on a Raspberry Pi 4 using a similar config to what is explained above. Just in case there are any differences, I’ll also document what I’m using here.
mkdir -p /opt/example
cd /opt/example
copy the entire build folder of your app into this folder (For this example, we’ll call it TestApp)
I followed Greg’s example to the letter changing only TestApp to LynxMaster. It is not working. Looking at the system log after rebooting the Pi, LynxMaster does not appear. When I start it using line 9 from Greg’s example I get this in the log
Feb 18 15:11:43 raspberrypi systemd[1]: Started Lynx Web Server.
Feb 18 15:11:43 raspberrypi systemd[1348]: LynxMaster.service: Failed to determine user credentials: No such process
Feb 18 15:11:43 raspberrypi systemd[1348]: LynxMaster.service: Failed at step USER spawning /opt/ezmeter/LynxMaster/LynxMaster: No such process
Feb 18 15:11:43 raspberrypi systemd[1]: LynxMaster.service: Main process exited, code=exited, status=217/USER
Feb 18 15:11:43 raspberrypi systemd[1]: LynxMaster.service: Failed with result ‘exit-code’.
When I go to the folder with the app and enter “sudo ./LynxMaster &” I get a blank screen in the browser (instead of the “This site can’t be reached” I get otherwise) and the system log shows entries from the app.opening and the first line of the session.opening. The next line of the session.opening calls the app method to connect to the database, but that does happen. When I recompiled for port 8080, it opens properly when I manually start the app. A Pi web app I wrote in 2018 needed a setcap command to allow it to use port 80. Should that have been in Greg’s code?
How can I solve the user credentials issue? I had set a root password earlier so I can SSH into the Pi with WinSCP. Would that have caused the problem?
An interesting thing I noticed. When I started the 8080 version of the program, it started with PID 931. When I tried to kill it, it said there was no such process. Kill 932 killed it. That’s not the way it used to work.
I’m not familiar with an empty app, so I tried it on a different rPi. On my first attempt, I had set a new root password and used WinSCP to copy the program into a folder under /opt. This time, I used a fresh install of the rPi OS and did not set a root password. Systemctl launched the program and reported success. Syslog revealed that the app started but the next step was to get a folderitem for the SQLite database and write the file path to syslog. That did not happen.
I am not going to worry about it now as we have decided to use Postgres instead of SQLite and that code has not been written yet.
I know very little about Linux, but it appeared to me that changing the root password affected systemctl’s ability to validate the root user. But after changing the root password, I experienced the same result as before changing it. I now have no idea why one rPi works and the other does not. Rather worrisome if this is to be a commercial product.