Search code examples
bashfirebase-realtime-databaseraspberry-piraspbianboot

Firebase DB program works when logged in but not on boot using raspberry pi


I am creating an IOT device with raspberry pi and using firebase admin sdk to communicate over the web. The code works exavtly how I want it to... Until I try adding it into local.rc for using it headlessly.

I'm unable to copy the error as it is only being thrown on boot. Here is a picture.

https://drive.google.com/open?id=0B9zzhouEyyN_RmttYVVOZXE0d2JXNWtTZHBjTlZYRTZkdy1N

From what I can read it has to do with an authority problem from where the program is being run. This is my rc.local:

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

#My line

sudo sh /home/pi/superscript.sh

exit 0

the supercript is

sudo python home/pi/servo.py & sudo python home/pi/buttonCheck.py&

I've tried with and without sudo.

Thanks for any help.


Solution

  • I switched my process from running in rc.local to being a service in systemd, thanks to Kamil Cuk. Here is a link to the documentation for using systemd service method. Though I am not experiencing any crashing, but putting Restart=Always will restart it after crash if applicable.

    This is what it looks like.

     [Unit]
     Description=Room controller
     After=multi-user.target
    
     [Service]
     Type=idle
     ExecStart=/usr/bin/python /home/pi/servoController.py & /usr/bin/python /home/pi/buttonListener.py
     Restart=always
    
     [Install]
     WantedBy=multi-user.target