1

I want to start a graphical application via systemd. I tried to do that via udev before, but the application is killed after the rule terminates. It works when I run the application directly via systemd, but not when I run the script that starts the application with some constraints.

My service file looks like this:

[Unit]
Description=App starter

[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DISPLAY=:0
Environment=HOME=/home/user/
ExecStart=/home/user/runApp

[Install]
WantedBy=multi-user.target

journalctl -xe gives me

Sep 25 13:50:00 host systemd[1]: Starting App starter...
Subject: A start job for unit app.service has begun execution
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
A start job for unit xournalpp.service has begun execution.
 
The job identifier is 19196.
Sep 25 13:50:00 host runApp[313232]: App is not running
Sep 25 13:50:00 host systemd[1]: app.service: Main process exited, code=exited, status=1/FAILURE
Subject: Unit process exited
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
An ExecStart= process belonging to unit xournalpp.service has exited.
 
The process' exit code is 'exited' and its exit status is 1.
Sep 25 13:50:00 host systemd[1]: app.service: Failed with result 'exit-code'.
Subject: Unit failed
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
The unit xournalpp.service has entered the 'failed' state with result 'exit-code'.
Sep 25 13:50:00 host systemd[1]: Failed to start App starter.
Subject: A start job for unit app.service has failed
Defined-By: systemd
Support: https://forum.manjaro.org/c/support
 
A start job for unit app.service has finished with a failure.
 
The job identifier is 19196 and the job result is failed.

Here is the script. Might it be due to the running in background by &? In need this because I want to reuse the script.

#!/bin/bash

  if pgrep app
  then
      echo App is running
          wmctrl -x -a app
          wmctrl -x -r app -b "add,maximized_vert,maximized_horz"
          
  else
          echo App is not running
          /usr/bin/app & disown
  fi
  • Can you show the content of the script? What if the content is very simple (e.g. echo 1) - it might just be a problem with e.g. loading the environment in the script. You are also defining DISPLAY, thus maybe graphical.target instead of multi-user.target seems more fitting. Last but not least it looks like the user should run it on login, I guess? Please specify. – Fiximan Sep 25 at 12:14
  • The & was the problem apparently. I think this is also not the right way to do what I want to do, since the unit keeps on running. – neolith Sep 25 at 12:36
0

It might be a permission problem.

/home/user usually does not allow any user other to access them and security system like apparmor and selinux usualy forbidden such usage.

If you want to use a script in systemd, you'd better put it in /usr/local/bin.

| improve this answer | |

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.