1

I am trying to run Sphinx4-Http-server on RHEL. If I am in the directory /home/alex/Sphinx4-HTTP-server and run the command /home/alex/apache-maven-3.6.1/bin/mvn exec:java -Dexec.mainClass="org.jitsi.sphinx4http.server.HttpServer", then the server will run. However, when I make a .service file for the program (as shown below), I get a program error (specifically java.lang.ClassNotFoundException: "org.jitsi.sphinx4http.server.HttpServer"). Using this file on Ubuntu works (with adjusted path names), and using similar .service files for other programs on RHEL works. Why would the program run in the shell but not with systemd, even though the systemd file works on another system and similar systemd files work on the same system? How would I go about fixing it?

sphinx.service:

[Service]
WorkingDirectory=/home/alex/Sphinx4-HTTP-server
ExecStart=/home/alex/apache-maven-3.6.1/bin/mvn exec:java -Dexec.mainClass="org.jitsi.sphinx4http.server.HttpServer"
Restart=always
StandardOutput=syslog
SyslogIdentifier=sphinx
User=alex

[Install]
WantedBy=multi-user.target
  • Does this help? stackoverflow.com/a/49482664/9447571 – filbranden May 9 '19 at 9:28
  • @filbranden, thanks, but it still fails when systemd is run as root. I've also looked at all the solutions suggested at "Why doesn't my app work under systemd when I can run it directly?", but none of them appear to apply here. – alexwho314 May 9 '19 at 19:35
  • 1
    Maybe take another look at environment variables, I'd say that's the most likely source of discrepancy here. Are you setting any related to classpath in the profile or rc file of the user? Perhaps looking for classes in the current directory is not the default and you're overriding it somewhere in the environment? I'm not very familiar with Maven, so I couldn't tell for sure... But that's where I'd look next. – filbranden May 10 '19 at 22:33
1

After some research and trying various fixes out, it seems the solution was number 6 on "Why doesn't my app work under systemd when I can run it directly?".

Instead of using

ExecStart=/home/alex/apache-maven-3.6.1/bin/mvn exec:java -Dexec.mainClass="org.jitsi.sphinx4http.server.HttpServer"

I needed to use the line

ExecStart=/bin/bash -c '/home/linguini/apache-maven-3.6.1/bin/mvn exec:java -Dexec.mainClass="org.jitsi.sphinx4http.server.HttpServer"'

The important part was running /bin/bash -c '' to run the command in the proper shell.

| 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.