To check status of Tomcat server in Linux - linux

I need to know whether Tomcat 7.0.2.3 is on or not.
I got an error page that shows this message:
HTTP Status 404 - /cas/login
type Status report
message /cas/login
description The requested resource (/cas/login) is not available.
Apache Tomcat/7.0.23
I need to check the status and start the service of Tomcat in Linux. I have tried:
#/bin/startup.sh
#rctomcat7 start
But all these are not working.

Like others have pointed out, if you are receiving an HTTP standard response code of 404 then it means that Tomcat is up.
But to answer your question, you can try
#rctomcat7 status

I have used below script. This script check tomcat post and process is running up or not,if not then start the tomcat.
Tomcat Start script
if netstat -tulpen | grep 18880 && ps -ef | grep tomcat | grep java
then
echo "Tomcat Running"
else
echo "Tomcat Stopped"
/bin/sh /tomcat/bin/startup.sh
fi

Related

Cron script to restart service on Error 503

Dear Community Members,
I'm facing an issue in which my website redis service is making my website showing 503 error on regular interval. Previously it was in 2-3days so I made a cronjob to delete redis dump file and restart service at night every day. But now I'm still facing the issue sometimes it comes in 1 week and sometimes it comes twice in a day.
So I was thinking if there is a shell script which can check 503 error on my website and restart services. I had the script to check httpd service is active or not and restart it if it goes down.
#!/bin/sh
RESTART="systemctl start httpd"
SERVICE="httpd"
LOGFILE="/opt/httpd/autostart-apache2.log"
#check for the word inactive in the result of status
if systemctl status httpd | grep -q inactive
then
echo "starting apache at $(date)" >> $LOGFILE
$RESTART >> $LOGFILE
else
echo "apache is running at $(date)"
fi

Why do we use"/etc/init.d/process start"

Why do we use /etc/init.d/httpd start in the below program? Why can't we use service httpd start? For me it's showing as unrecognized service. (I have installed httpd already.)
#!/bin/bash
if (( $(ps -ef | grep httpd | wc -l) > 1 ))
then
echo "httpd is running!!!"
else
/etc/init.d/httpd start
fi
:-) vishal I don't mean to frustrate you. However, it's difficult to answer your question without a lot of assumptions.
Some considerations for not using /etc/init.d/httpd start
hard-coded location
assumes that httpd is stored in file /etc/init.d/httpd and not say apache2 or nginx or something else.
even the ps -ef test assumes the process name to be httpd and sometimes it's not
Some considerations for not using service httpd start
There may also be good reasons for not using service httpd start in this script because it may have side effects. For example,
service may not have httpd registered as a service
if you use service you may end up relaunching other dependent services which you may not want to do
service may bury the errors during start up and you may want to.

shell script to automatically restart tomcat if stopped

I am using a shell script to start tomcat server if it is not running. I am running this script in cronjob to check it frequently. This is my script
#! /bin/sh
SERVICE=/etc/init.d/tomcat7
STOPPED_MESSAGE="Tomcat Servlet Engine is not running."
if [ "`$SERVICE status`" -eq "$STOPPED_MESSAGE" ]; then
$SERVICE start
fi
But whenever I run this script, it gives me an error. If tomcat is not running then the error is :
[: ILLEGAL NUMBER : * Tomcat Servlet Engine is not running.]
And if tomcat is running the error is :
[: ILLEGAL NUMBER : * Tomcat Servlet Engine is running with pid 6130.]
I think the error is related to $SERVICE status but I am unable to resolve it. I am a new bee to shell scripting. Please help me out.
I cannot move forward until I resolve this issue.
-eq expects 2 integers for comparison (see man test). You should use = there for strings.
Or, could you be more tolerant about output from the script?
if $SERVICE status | grep -q "not running"; then
$SERVICE start
fi
Of course it would be much better to use a process monitoring tool like monit or supervisor.

Running Jconsole from a service: CentOS

I installed Tomcat on my CentOS 6.3 machine and I made it a service by creating the /etc/init.d/tomcat file.
It works with the basic start, stop, restart and status functionality just fine.
I use jconsole on the servers often, so I thought it would be nice to build this functionality into the service (by running service tomcat monitor) instead of having to run ps aux|grep java and then running the jconsole <Java PID> .
Here is my service script (Just the monitor section):
monitor)
# Check for Tomcat PID (greps are separated to prevent returning the single grep PID)
FOUND_PID=$(ps aux |grep $JAVA_HOME/bin/ | grep java |awk -F' ' '{print $2}')
if [[ $FOUND_PID ]]
then
echo -e $JAVA_HOME/bin/jconsole $FOUND_PID
$JAVA_HOME/bin/jconsole $FOUND_PID
else
echo -e "Failed: Tomcat is not currently running";
fi
;;
Everything inside of the monitor section works when I run the bash script directly it works, but when the service calls it, it just hangs at the jconsole line and doesn't do anything.
And when I run service tomcat monitor, I do get the correct path output, so I know that the path is correct.
Is there a way to get the jconsole to work when called from the services script?

Best way to start JBoss AS

I like to ask what is best way to start jboss AS.
Because, whenever i close terminal or press ctrl+c then jboss, which is already started with run.sh script, start with shutdown. I have already tried executing export LAUNCH_JBOSS_IN_BACKGROUND=1 before starting jboss via script .run.sh but it has not helped me much.
Secondly, i like to know how can i validate that jboss is running except browsing localhost:8080 or localhost:8080/admin-console.
I am using both mac-osx/linux and Jboss-AS-6.0.0.Final.
nohup /usr/local/jboss/bin/run.sh -b 0.0.0.0 > /dev/null & should do starting jb as well running it in background.
You can check for jboss running using ps -ef | grep java
For the first part of the question, try running:
./run.sh &
This will send the process to the background. Just hit enter once JBoss has finished starting up.
If you need to bring the process back to the foreground, run fg. You can then hit CTRL-C if you want stop JBoss.
To validate that jboss is running, you can run something like this :
ps -ef | grep jboss
or
ps -ef | grep run.sh
This will show the process id for JBoss or the run.sh script.
I hope this helps.

Resources