I am using CentOs 7.5.1804 and have a problem with a service. When i start my service with systemctl it fails with the message

which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Java not found!

Following the error message i did a which java

and it returns

which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Java not found!

But when i log in to the system as the user app i get a feedback from java java -version

java version "1.8.0_161" 
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Here is a snip of my service located in /etc/systemd/system

ExecStart=/opt/div/ui/bin/service.sh -s start -t myserver
ExecStop=/opt/div/ui/bin/service.sh -s stop -t myserver

What do i miss? Any suggestions ?

  • what do you get, if you log in as user app and run a which java? I think if you run java -version with the same user, that has an error with which java, you won't get a correct version feedback – chloesoe Aug 23 '18 at 20:39
  • When i use which java i get the reply:/opt/jdk/current/bin/java When i use java -version the reply is: java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode – Mchoeti Aug 24 '18 at 9:12

Systemd uses a fixed search path and strongly encourages using full paths for executables.

From the systemd.exec man page:

Systemd uses a fixed value of

Best solution is to use the full path to the java executable in your service.sh script.

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.