0

I have the following service:

[Unit]
Description=Create test directory
After=graphical.target

[Service]
Type=oneshot
RemainAfterExit=yes
User=pi
ExecStart=/home/pi/Desktop/startup-script.sh

[Install]
WantedBy=graphical.target

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

My startup-script is looking like:

#!/bin/bash

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.

0
2

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:

[Unit]
Description=My exe program
After=graphical.target

[Service]
ExecStartPre=/bin/mkdir -p /home/pi/Desktop/test
ExecStart=/home/pi/Desktop/exe

[Install]
WantedBy=graphical.target

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.

7
  • 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 '20 at 9:35
  • @jrn6270 How long is exe running?
    – Ingo
    Mar 25 '20 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 '20 at 10:57
  • @jrn6270 OK, that's a real service always running in the background. I will modify my answer.
    – Ingo
    Mar 25 '20 at 10:59
  • @jrn6270 If my answer helped you, it would be nice, if you could accept it? :-)
    – Ingo
    Mar 25 '20 at 11:20

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.