I replace ~/.config/lxsession/LXDE-pi/autostart file to run my script that runs my application. But when my application crashes never run again. I tried before run my app in a service, but as my app have GUI service doesn't run at startup..

How can i run my app and prevent if crashes? Thanks


2 Answers 2


You could specify watch my_script instead of just my_script in the autorun file. watch will re-run a command again and again when it terminates. Note that you won't be able to terminate your application properly (you'd have to run killall watch or something similar on the terminal).

If you need to avoid restarting your application if it exits properly (assuming it exits with a zero return value), you could instead specify:

bash -c "until my_script; do echo $?; done"

user based systemd service can help you. Try this example systemd service.

file location and name "~/.config/systemd/user/mygui.service".

Description=My GUI Auto Start APP

Enable the service by

systemctl --user enable mygui.service
systemctl --user start mygui.service
systemctl --user status mygui.service


GUI Applications some time required more environment variables. Set Proper environment variables and if possible use a environment file

  • Why difference between root directory and execstart? Mar 14, 2017 at 9:06
  • You can Ignore RootDirectory parameter, it is my app related param. to know more you can refer freedesktop.org/software/systemd/man/systemd.exec.html. Is this work for you?
    – rajesh6115
    Mar 14, 2017 at 9:39
  • I don't have systemd directory in .config directory. I'm running other service and it is in /etc/systemd/system/ Mar 14, 2017 at 10:10
  • I tried this before, and the problem is that my app needs to be run at a specific directory not in root directory and if execstart isn't a absolute path it gives an error.. Mar 14, 2017 at 10:15
  • if .config is not there then just create it using "mkdir -p ~/.config/systemd/user", also you can use "WorkingDirectory" in systemd service file
    – rajesh6115
    Mar 14, 2017 at 11:43

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.