¿Cómo ejecutar un script bash con un servicio systemd?

¿Cómo ejecutar un script bash con un servicio systemd?

Quiero iniciar una aplicación gráfica a través de systemd. Intenté hacerlo a través de udev antes, pero la aplicación se cierra después de que finaliza la regla. Funciona cuando ejecuto la aplicación directamente a través de systemd, pero no cuando ejecuto el script que inicia la aplicación con algunas restricciones.

Mi archivo de servicio se ve así:

[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 me da

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.

Aquí está el guión. ¿Podría deberse a que se está ejecutando en segundo plano &? Necesito esto porque quiero reutilizar el 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

Respuesta1

Puede que sea un problema de permisos.

/home/userPor lo general, no permite que ningún otro usuario acceda a ellos y los sistemas de seguridad como Apparmor y Selinux generalmente prohíben dicho uso.

Si desea utilizar un script en systemd, será mejor que lo coloque en /usr/local/bin.

información relacionada