Restuful server instance on tomcat

0

Staff developed an app - link

I'm using a restfull server connection with the postgree database in hibernate.

This server is hosted in bitname on a tomcat, but sometimes for some reason it drops and it is necessary to restart the server manually, is there any other way to do this? I need to have two servers in case one falls I call the other? How does this final process work to get my server started?

    
asked by anonymous 05.11.2015 / 19:32

2 answers

2

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

It consists of checking from time to time whether a service or program is running and if it does not execute a boot command.

This is done using the scheduler (in Linux is Cron) with an acceptable time interval that the system to be monitored is out. Generally the average time the service takes to "stop + start" is used.

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

Suppose you save the script in your $ HOME with the name watchdog.sh, give permission to run 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
    
06.11.2015 / 21:02
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 standard for you to set up more assertive monitoring in Nagios.

Here's a starting point:

05.11.2015 / 21:44