Created
July 9, 2011 16:33
-
-
Save alessandro-fazzi/1073720 to your computer and use it in GitHub Desktop.
Watch number of instances of a process and restart it if greater than x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
initscript="/etc/init.d/myprocess" | |
mail=$(which mail) | |
destinatario="[email protected]" | |
oggetto='Mail subject' | |
data=$(date) | |
limite=190 #must be an integer | |
process="" #if the process to restart differ from the name of the initscript, then set it here | |
#if $process isn't set than we set with the same name of the initscript | |
#+ e.g.: /etc/init.d/apache2 -> process will be "apache2" | |
[[ $process ]] || process=`basename $initscript` | |
if [ `ps -e -o comm= | grep $process | uniq -c | sed 's/[^0-9]//g'` -gt $limite ]; then | |
logger [process control] restarting `basename $initscript` due to $process processes saturation | |
${initscript} restart | |
pkill imapd | |
echo "Come da oggetto... Sto lavorando per voi. ${data}" | ${mail} -s "${oggetto}" ${destinatario} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment