systemctl Failed to start service, Invalid argument

1

I need to run a Qt application on startup with root permission , below is the script I created using systemctl named QtApp.service

[Unit]
Description=QtApp

[Service]
ExecStart= exec su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'
Restart=always

[Install]
WantedBy=multi-user.target

But when I run the command to start the service sudo systemctl start QtApp.service I am getting following error

Failed to start QtApp.service: Unit QtApp.service is not loaded properly: Invalid argument.

Here is the details of error

systemctl status QtApp.service
● QtApp.service - QtApp
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Jul 06 15:23:54 user-pc systemd[1]: [/etc/systemd/system/QtApp.service:5] Executable path is not absolute, ignoring: exec su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'
Jul 06 15:23:54 user-pc systemd[1]: QtApp.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Jul 06 15:26:08 user-pc systemd[1]: [/etc/systemd/system/QtApp.service:5] Executable path is not absolute, ignoring: exec su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'
Jul 06 15:26:08 user-pc systemd[1]: QtApp.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

CodeDezk

Posted 2018-07-06T11:18:34.067

Reputation: 117

Answers

1

Executable path is not absolute -- it means exec.

Generally exec makes no sense here. It's a shell builtin that replaces the shell with a given command. There is no absolute path to exec executable because there is no executable.

su is an executable. The line may be

ExecStart=/bin/su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'

But using su may not be a good idea in systemd service. See: How do I make my systemd service run via specific user and start on boot?

Kamil Maciorowski

Posted 2018-07-06T11:18:34.067

Reputation: 38 429

1

Generally, the "Invalid argument" here is the unit definition file itself. To debug it you can use:

sudo systemd-analyze verify QtApp.service

or in case of user's local service:

sudo systemd-analyze --user verify QtApp.service

teejay

Posted 2018-07-06T11:18:34.067

Reputation: 141

0

The error says

Executable path is not absolute, ignoring: exec su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'

Try to use the absolut path (e.g. /usr/local/QtInst/QtApp) instead of /QtInst/QtApp.

This might be relevant.

Andy Powers

Posted 2018-07-06T11:18:34.067

Reputation: 1

Actually the executable is in the folder in /QtInst/ – CodeDezk – 2018-07-06T11:32:56.543

Have you tried to delete the space after ExecStart= ? and set it in quotes, ExecStart="exec su -l user -c 'export DISPLAY=:0; /QtInst/QtApp'" – Andy Powers – 2018-07-06T11:39:07.180

No, I will try it – CodeDezk – 2018-07-06T11:45:18.167