This seems to come up several times, but I've been through all the answers and tried everything I can find and I still can't get a Python script to run at startup on my Kubuntu 18.04 system.
I've got a project setting up a datalogger for a home automation project. It's an ESP32 board running Micropython that sends MQTT messages back over the WiFi to save on the computer. I've managed to get it all working, I now simply need to start a Python script running on the computer to grab the MQTT messages. I can run it from terminal and it works perfectly. I assumed it would be trivial to get it to automatically run at startup so I don't have to type it in every time I switch the computer on, but I've spend hours on it and it still won't do it!! Things I've tried:
python /home/rosebank/datalogger/datalogger_server.py
python /home/rosebank/datalogger/datalogger_server.py
, making it executable and using the Autostart GUI to run that script fileLiterally nothing I try will make this script run!! I simply can't understand how it's this difficult, as I say all I need to do it type the command into Terminal after booting up and it works, so why can I not make it work automatically?! I don't know what's happening. Is the code not running at all? Is it trying to run and giving an error message? Is there anywhere I can find if there's any error messages it's generated? As I say, the code works fine just running it from terminal, so I can't see why it shouldn't work at boot.
EDIT: To clarify, on this computer it logs in automatically when it's switched on and the only 'user' is rosebank. So it's totally fine to have it run at log in rather than at boot. It's also fine to have it run by the user not by root as it just needs to be able to write into the user's home folder and doesn't need (probably shouldn't have) any special permissions. I really am just looking for an automatic way of doing exactly the same as what happens when I type the command into terminal.
I faced the same problem when I run PyPI local server.
I developed a local PyPI server and it should be run using hostingpypi runserver --port PORT --host HOST
command.
So, borrowed systemd config file from https://pypi.org/project/pypiserver/#running-as-a-systemd-service and used it for running my script at Ubuntu startup.