0

How can I get systemctl status tomcat to return 'success' instead of 'failed'?

This is my etc/systemd/system/tomcat.service file:

    [Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JRE_HOME=JAVA_HOME='/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/'
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
#Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

now when i check the status of my tomcat it says

# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2019-08-10 14:03:10 EDT; 55min ago
 Main PID: 22165 (code=exited, status=127)

Aug 10 14:03:10 localhost.localdomain kill[22167]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Aug 10 14:03:10 localhost.localdomain kill[22167]: -p, --pid              print pids without signaling them
Aug 10 14:03:10 localhost.localdomain kill[22167]: -l, --list [=<signal>] list signal names, or convert one to a name
Aug 10 14:03:10 localhost.localdomain kill[22167]: -L, --table            list signal names and numbers
Aug 10 14:03:10 localhost.localdomain kill[22167]: -h, --help     display this help and exit
Aug 10 14:03:10 localhost.localdomain kill[22167]: -V, --version  output version information and exit
Aug 10 14:03:10 localhost.localdomain kill[22167]: For more details see kill(1).
Aug 10 14:03:10 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Aug 10 14:03:10 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Aug 10 14:03:10 localhost.localdomain systemd[1]: tomcat.service failed.



Caused by: java.net.ConnectException: Connection refused (Connection refused)

I got this error trying to run sudo certbot --apache

Error while running apachectl graceful.

Job for httpd.service invalid.

Unable to restart apache using ['apachectl', 'graceful']
Error while running apachectl restart.

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

Encountered exception during recovery: 
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/certbot/error_handler.py", line 124, in _call_registered
    self.funcs[-1]()
  File "/usr/lib/python2.7/site-packages/certbot/auth_handler.py", line 220, in _cleanup_challenges
    self.auth.cleanup(achalls)
  File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2332, in cleanup
    self.restart()
  File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2202, in restart
    self._reload()
  File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2229, in _reload
    raise errors.MisconfigurationError(error)
MisconfigurationError: Error while running apachectl restart.

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

This is my journalctl -xe: https://pastebin.com/JvJ8Uej0 This is my journalctl -b -u tomcat: https://pastebin.com/zPqEBGXH

Tried killing proccess but dont work none:

# kill 23656
bash: kill: (23656) - No such process

enter image description here What may be the cause this? How do I fix these error? The website is working fine but I'm getting these errors.

Philip Rego
  • 190
  • 1
  • 4
  • 12
  • 1
    It looks like you're asking about two completely different and unrelated problems here. – Michael Hampton Aug 10 '19 at 19:24
  • Idk I thought they could be related. I tried to give adaquate details . If we can get systemctl to say success that'll be great. – Philip Rego Aug 10 '19 at 19:29
  • Your Apache problem is answered [here](https://serverfault.com/q/200118/126632). Your Tomcat problem needs more information. Try `journalctl -b -u tomcat` to get journal entries, and look at `catalina.out` if one was created. – Michael Hampton Aug 10 '19 at 19:36
  • I uploaded `journalctl -b -u tomcat`. That doesnt give the answer. I already know its saying theres another proccess but theres no way to kill it or figure out where its coming from. – Philip Rego Aug 10 '19 at 19:54
  • I'm getting this error: `$ cat catalina.out /opt/tomcat/bin/catalina.sh: line 467: JAVA_HOME='/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre/bin/java'/bin/java: No such file or directory ` – Philip Rego Aug 10 '19 at 20:27
  • @MichaelHampton do you know how to fix? this is my line 467. ` eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \ -D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \ -classpath "\"$CLASSPATH\"" \ -Dcatalina.base="\"$CATALINA_BASE\"" \ -Dcatalina.home="\"$CATALINA_HOME\"" \ -Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \ org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_OUT" 2>&1 "&" ` – Philip Rego Aug 10 '19 at 20:28
  • your log tells that a Port is already in use, check this – djdomi Aug 10 '19 at 21:06
  • @djdomi I cleared all the processes and ran `systemctl start tomcat` but this is the only thing `journalctl -b -u tomcat` says now https://pastebin.com/bezXhtr6 – Philip Rego Aug 10 '19 at 23:51
  • httpd.service is now active. tomcat still failed – Philip Rego Aug 11 '19 at 00:05
  • Hi, it seems that your startup.sh doesn't run nicly esse paste it what the file do – djdomi Aug 11 '19 at 10:30
  • @djdomi i looked at startup.sh https://pastebin.com/L0YgXGYY and noticed it calls catalina.sh and I have this error in catalina.out. `/opt/tomcat/bin/catalina.sh: line 467: '/usr/lib/jvm/jre'/bin/java: No such file or directory` So in the unit file I took off the quoats around JAVA_HOME and now tomcat is starting successfully! – Philip Rego Aug 11 '19 at 16:56
  • @philiprego so i could help you to fix your issue? – djdomi Aug 11 '19 at 17:45
  • @djdomi you helped me fix this issue. I'm having this issue now https://serverfault.com/questions/978854/how-to-fix-error-in-catalina-out-libjli-so-cannot-open-shared-object-file-no – Philip Rego Aug 12 '19 at 06:06

1 Answers1

0

My issue was with the line in the unit file:

Environment=JRE_HOME=JAVA_HOME='/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/'

it should be without quotes:

Environment=JRE_HOME=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/

I was able to find this by trying systemctl restat tomcat and then looking at log catalia.out showed an error in /opt/tomcat/bin/catalina.sh which /opt/tomcat/bin/startup.sh calls which looked like an error with JAVA_HOME.

Thank you djdomi for helping me get there in the comments.

Philip Rego
  • 190
  • 1
  • 4
  • 12