javalinuxbashservicesystemd

Running a java application via a systemd service doesn't see additional directories (Rocky Linux)


I am trying to make a local machine restart to the new version control build of my java application. Let me run you through the flow:

What I am stuck upon is that I have a media directory in the working folder (where the jar file is as well). The application runs normal, compiled videos but from time to time it also runs videos from the media directory (I need that because I have an external video source as well).

When I start the file with the command by myself, it works. When I start the script by myself, it works. But when the service starts it, the directory isn't seen.

This is the service:

[Unit]
Description=DMR Service

[Service]
WorkingDirectory=/home/ops/DMR
ExecStart=sh run.sh
Restart=on-failure
RestartSec=15s
StartLimitInterval=500
StartLimitBurst=15
TimeoutSec=300
StandardOutput=journal
StandardError=journal
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/ops/.Xauthority
User=ops
Group=ops

[Install]
WantedBy=multi-user.target

I checked the path, it's the same because the application runs. I checked the rights to the directory and I have access with my user. What am I missing?

Edit: Added the script /home/ops/DMR/run.sh to leave out the possibility of subdirectories without rights

#!/bin/sh
set -e

cd /home/ops/DMR
ls -l

file=$(find . -maxdepth 1 -type f -name "*.jar" | head -n 1)

if [ -z "$file" ]; then
    echo "No .jar file found in the directory."
    exit 1
fi

echo "$file is a .jar file"
java -jar $file

I will put an emphasis again on the fact that if I run the script as ops user, the whole thing works.

ls -l output on working directory:

drwxr-xr-x. 4 ops ops        29 Mar 20 15:25 data
-rw-r--r--. 1 ops ops 263641531 Mar 21 10:31 <application-name>.jar
drwxr-xr-x. 2 ops ops      4096 Mar 21 10:59 logs
-rwxr-xr-x. 1 ops ops       235 Mar 21 10:34 run.sh

Edit 2 - what I think could be the problem:

I am suspecting that the problem is some environment variable about ffmpeg. I need it only for the videos in the external directory to be played - this was the problem before installing it. The pre-compiled videos in the jar file are still played and running - as expected - but the ones that require ffmpeg are not.


Solution

  • Found the solution. Indeed if you have a look at the question and why I needed ffmpeg for the "external" videos to play, you can figure out that there might be an audio problem somewhere. Well, even though I don't play audio on the device I run my application, the video still has audio.

    Now going further with the investigation, I found that Rocky Linux uses PipeWire as its audio driver (together with Alsa, but that didn't matter) and found the environment variables that PipeWire has for my user. Turns out it was XDG_RUNTIME_DIR - from here. Got the variable that my user had with the set command and now it's all up and running.

    Thank you for the suggestions, @Alex Crichton and @user1934428. You kinda pointed me in the right direction, because at first I didn't think it could be an env var missing.