Tkd-Alex / Telegram-InstaPy-Scheduling

A Telegram bot for scheduling InstaPy
152 stars 38 forks source link

main.py onStart? #29

Closed tE3m closed 5 years ago

tE3m commented 5 years ago

Is there any way of starting main.py everytime the computer starts? Cron and rc.local don't work from what I tested. My machine is a raspberry pi 3b+ that runs raspbian in cli mode.

Tkd-Alex commented 5 years ago

uhm you should create a service and enable with systemctl. follow this tutorial: https://timleland.com/how-to-run-a-linux-program-on-startup/

ExecStart= python3 main.py & should be work

tE3m commented 5 years ago

Thanks for your quick answer, but it doesn't work. systemctl status <job_name> outputs:

Dez 31 18:35:46 raspberrypi systemd[1]: [/etc/systemd/system/telegram.service:1] Assignment outside of section. Ignoring. Dez 31 18:35:46 raspberrypi systemd[1]: [/etc/systemd/system/telegram.service:3] Assignment outside of section. Ignoring. Dez 31 18:35:46 raspberrypi systemd[1]: [/etc/systemd/system/telegram.service:4] Assignment outside of section. Ignoring. Dez 31 18:35:46 raspberrypi systemd[1]: [/etc/systemd/system/telegram.service:8] Executable path is not absolute, ignoring: cd /home/pi/Projects/Telegram-InstaPy-Scheduling Dez 31 18:35:46 raspberrypi systemd[1]: telegram.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

Do you know what to do?

Tkd-Alex commented 5 years ago

No bro, I don't know

tE3m commented 5 years ago

My solution is the /etc/xdg/lxsession/LXDE-pi/autostart file. But there was a problem: an error occurs if one runs main.py via python3 /path/to/main.pybecause it can't find settings.json. That's because it searches for settings.json in the folder one is in instead of the Telegram-InstaPy-Schedule folder. I manually changed the main.py so that it doesn't open(settings.json) but open(my/path/to/settings.json). But I'm sure it's possible to create a variable in settings.json for db, like InstaPy does.

Tkd-Alex commented 5 years ago

Hi! You can try to do: cd /path/to ; python3 main.py