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