1

I'm creating a time-lapse camera to attach to a pair of glasses.

I tried out my script (python 3) and it works, but I need to get my script to work upon startup up since it will powered by a powerbank and I can't manually start the script because of that. (filename is "GlassCam.py" in the folder named "GlassCam")

This is what I've tried in the command line:

sudo nano ~/.config/lxsession/LXDE-pi/autostart

then in the menu

sudo /usr/bin/python3 /home/pi/GlassCam/GlassCam.py

(control+x and then y to save)

yet it won't start when I reboot it or shut it down and plug it back in

Ingo
43k20 gold badges87 silver badges207 bronze badges
asked Jun 12, 2018 at 4:19
3
  • look through the 10 posts just before your post ... one of them may have what you need Commented Jun 12, 2018 at 6:17
  • put your script in rc.local file in /etc. Before the exit keyword, write python3 /path/to/script/GlassCam.py Commented Jun 12, 2018 at 7:54
  • rc.local from old style SysVInit is only emulated by systemd and becomes more and more deprecated. There are some feedback here on this site that it no longer work as expected. You should really use a systemd unit to start programs. Commented Jun 12, 2018 at 8:51

1 Answer 1

1

For starting programs on boot you should make a systemd unit. I do not have enough information of detailed dependencies from your python script but as template for your needs I suggest to start with:

rpi ~$ sudo systemctl --force --full edit glasscam.service

In the editor insert these statements, save it and quit the editor:

[Unit]
Description=startup GlassCam
After=graphical.target
Wants=graphical.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/GlassCam/GlassCam.py
[Install]
WantedBy=graphical.target

Check with systemctl cat glasscam.service and systemctl status glasscam.service. Enable the new service with:

rpi ~$ sudo systemctl enable glasscam.service

Reboot.

answered Jun 12, 2018 at 9:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.