Server instance restuful in Tomcat

Asked

Viewed 96 times

0

Staff developed an app - https://play.google.com/store/apps/details?id=br.com.apprioconcurso

I am using a server restfull connection to the postgree bank in Hibernate.

This server is hosted in bitname on a Tomcat, but sometimes for some reason it crashes and it is necessary to restart the server manually, is there any other way to do this? I need to have two servers if one falls I call the other? how does this final process work to leave my server always startado?

2 answers

2


If you have cron access to your cloud, a very common way to do what you want is to use a script Watchdog.

It consists of checking from time to time if a service or program is running and if no runs a boot command.

For this is made use of the scheduler (in Linux is Cron) with an acceptable time interval that the system to be monitored is outside. Generally use the average time the service takes to "stop + start".

Below is an example script that serves many services.

Basically you tell the script which service to monitor, which command to start the service, email addresses for alerts, and paths to some binaries

Assuming you save the script to your $HOME under the watchdog.sh name, give execution permission with chmod +x $HOME/watchdog.sh", edit your crontable with contrab -e and add a line like this

*/5 * * * *  $HOME/watchdog.sh

Indicating that it will be checked every 5 minutes

Follow a Watchdog script

#!/bin/bash

NAME=tomcat
START=`which $NAME`
STARTCMD="$START + _ARGUMENTOS_"
NOTIFY=EMAIL1
NOTIFYCC=EMAIL2
GREP=`which grep`
PS=`which ps`
NOP=`which true`
DATE=`which date`
MAIL=`which mail` # ou sendmail dependendo da distro
RM=`which rm`

# $PS -ax|$GREP -v grep|$GREP $NAME >/dev/null 2>&1 # Caso tenha problema com serviço que roda com um usuario que roda muitos serviços
$PS -efx|$GREP -v grep|$GREP $NAME >/dev/null 2>&1
case "$?" in
   0)
   # Em execução, não fazer nada.
   $NOP
   ;;
   1)
   echo "$NAME NÃO ESTÁ EM EXECUÇÃO. INICIANDO $NAME E ENVIANDO AVISOS."
   $STARTCMD 2>&1 >/dev/null &
   mkdir -p "$HOME/tmp"
   NOTICE="$HOME/tmp/watchdog.txt"
   echo "$NAME não estava executando e foi iniciado em `$DATE`" > $NOTICE
   $MAIL -n -s "Aviso Watchdog" -c $NOTIFYCC $NOTIFY < $NOTICE
   $RM -f $NOTICE
   ;;
esac

exit

1

You can use Nagios to monitor your server, and with some parameters restart your server in an automated way. But I recommend that you investigate your server and try to find some pattern for you to set up a more assertive monitoring in Nagios.

Follow a point of departure:

Nagios tutorial Ubuntu

Browser other questions tagged

You are not signed in. Login or sign up in order to post.