I have a python application running on a raspberry pi. Since the pi will be used mostly for display (no keyboard except for password input on boot because the pi user home directory is encrypted) the application needs to be started a boot. I know I have a few options, like a few files where I could place some simple bash stuff to run the application on boot. For example, just adding /usr/bin/python3 my_app.py in /home/pi/.profile would do the job I believe. It would only start the application when pi user logs in and the home directory is decrypted. Downside to that is that the application would be launched on each new terminal opened I believe, or ssh connection. So a bit of bash would need to be added to make sure this does not happen.

This type of stuff kind of screams systemd service to me, but I am no expert in that. Would a service allow me to start the application upon pi user login ? Is a service overkill for such a simple use case ? Personally I like the idea that the service can also restart the app when it crashes. Would a unit file like that (placed in the pi user home directory and enabled with --user) achieve what I am going for ?

Description=My app

WorkingDirectory=/path/to/my/repo/  # I think I need this because my_app imports some other python files in my repo
ExecStart=/usr/bin/python3 my_app.py
StandardOutput=journal # File logging would be nice as well


Those are my questions, someone more experienced with Linux (and maybe raspbian) could give me his opinion on this matter ? Are both solutions acceptable ? Is one better/cleaner/faster ?


To execute something when pi logs in, put @/home/pi/Desktop/pythonscript in /home/pi/.config/lxsession/LXDE-pi/autostart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.