0

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

0

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

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

[Unit]
Description=My GUI Auto Start APP
After=display-manager.service
[Service]
Type=simple
Environment=DISPLAY=:0
RootDirectory=/home/rajesh/
ExecStart=/usr/local/bin/myguiapp
Restart=always
RestartSec=5
[Install]
WantedBy=default.target

Enable the service by

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

NOTE:

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? – R. Rodrigues Mar 14 '17 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 '17 at 9:39
  • I don't have systemd directory in .config directory. I'm running other service and it is in /etc/systemd/system/ – R. Rodrigues Mar 14 '17 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.. – R. Rodrigues Mar 14 '17 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 '17 at 11:43

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.