0

I tried running two scripts on boot using below link.

https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/

One of the file just requires to open camera while other requires sending data to firebase real time database. Above tutorial successfully started file having requirement of opening camera but it didn't work for firebase file because Pi is connected to wifi after boot.

Is it possible to to run both scripts after my Pi 3 connects to wifi after boot? or another workaround?

2
  • This should be possible with systemd services. See e.g. raspberrypi.stackexchange.com/questions/78991/…
    – Dirk
    Nov 26, 2018 at 20:09
  • According to the linked tutorial you are using reboot from crontab but this is not good for services with critical dependencies. In man 5 crontab you find:"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.". Do you can successfully start both scripts from the command line? What exactly is its syntax then? I ask because we may be able to start them with systemd. Please address me with @Ingo.
    – Ingo
    Nov 26, 2018 at 20:47

1 Answer 1

1

There's six places where you can easily get things running at boot time.

  1. Add a line to /etc/rc.local with sudo nano /etc/rc.local. Add your program before the exit 0 line. Put an & on the end of the line if it starts a long running process.
  2. Add an @reboot line to your personal crontab with crontab -e
  3. Add an @reboot line to root's crontab with sudo crontab -e
  4. Add a cron line in /etc/crontab (not recommended).
  5. Add a line to your autostart file in /home/pi/.config/lxsession/LXDE-pi/autostart which looks like @/usr/bin/python3 /home/pi/thing_to_start.py
  6. Create a systemd service file in /etc/systemd/system/myscript.service which has this basic structure

    [Unit]
    Description=Thing to start at boot time
    
    [Service]
    Type=simple
    ExecStart=/usr/bin/python3 /home/pi/thing_to_start.py
    
    [Install]
    WantedBy=multi-user.target
    

There are other ways to get things running but those are the six most popular. If the program you're starting uses the GUI use the autostart method.

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.