I have the following service:

Description=Create test directory



This service is calling a script "startup-script.sh", located on the /Desktop.

My startup-script is looking like:


sudo mkdir /home/pi/Desktop/test

sudo lxterminal -e /home/pi/Desktop/exe

Now the script is creating a new directory test at startup via the service, but it is not opening a new terminal and running my C++ program exe in it.

Now, when I just run my startup-script like sudo ./startup-script.sh, it is both creating a new directory test and opening a new lxterminal and running my C++ exe program in it, but the terminal is not opening on startup and I want this to happen.

Is it possible to do anything like this in the startup service: (this is not working.)

sudo lxterminal -e ./home/pi/Desktop/startup-script.sh &

Any thoughts on a solution to this?

Update with info from comments:
The program home/pi/Desktop/exe must be run when the RPi is running, so all the time, but lxterminal does not have to been run on startup anyway.


1 Answer 1


When running a systemd service, there is only a very limited environment available to always have a defined starting point. In particular, you do not have a path variable set, so lxterminal and other programs will not be found. You have to use the full path for all called programs.

And please don't use sudo in your script. Instead omit line User=pi in the Unit file. Services are executed with root rights by default. There is no need to wrap the two commands into a bash script. It's only an additional level of execution. And as you updated, there is no need to run the program "exe" in a lxterminal, so you should use this Unit file:

Description=My exe program

ExecStartPre=/bin/mkdir -p /home/pi/Desktop/test


Now you can manage your service with:

rpi ~$ sudo systemctl enable myexe.service
rpi ~$ systemctl status myexe.service
rpi ~$ systemctl start|stop|restart myexe.service

and all other commands from systemctl.

  • Forget the delay. That was a mistake. The script is just making a folder and starting lxterminal with my exe program in it.
    – jrn6270
    Mar 25, 2020 at 9:35
  • @jrn6270 How long is exe running?
    – Ingo
    Mar 25, 2020 at 10:41
  • I must be run when the RPi is running, so all the time. I can't get it to work with your answer, but lxterminal does not have to been run on startup anyway... I made a little workaround. Thanks for the answer
    – jrn6270
    Mar 25, 2020 at 10:57
  • @jrn6270 OK, that's a real service always running in the background. I will modify my answer.
    – Ingo
    Mar 25, 2020 at 10:59
  • @jrn6270 If my answer helped you, it would be nice, if you could accept it? :-)
    – Ingo
    Mar 25, 2020 at 11:20

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .