#!/bin/bash accountid=$(cat /etc/ctrinfo.json | jq .server_admin | sed -e 's/"//g') pid_file=/var/run/dovecot_lmtp_watch.sh.pid exec 9>> ${pid_file} flock -n 9 if [[ $? -ne 0 ]] ; then echo "${pid_file} locked, other process running" exit 1 fi # if [[ -e /var/fixlmtpstack/sh_config ]] ; then source /var/fixlmtpstack/sh_config fi maxproc=$(doveconf | grep default_process_limit | awk -F"=" '{print $2}' |sed -e 's/[[:space:]][[:space:]]*//g') threshholdproc=$(echo $maxproc ${THRESHHOLDRATIO} | awk '{printf("%d\n",$1 * $2 / 100 ) }') echo "Start lmtp process num check" curproccnt=$(pgrep -f 'dovecot/lmtp' | wc -l) if [[ ${curproccnt} -le ${threshholdproc} ]] ; then echo "lmtp process num (${curproccnt}) is less than ${threshholdproc}" flock -u 9 exit 0 fi rstflg=0 for chkcnt in `seq ${LOOPCOUNT}` ; do curproccnt=$(pgrep -f 'dovecot/lmtp' | wc -l) if [[ ${curproccnt} -gt ${THRESHOLDPROC} ]] ; then rstflg=$( expr ${rstflg} + 1 ) fi sleep ${SLEEPTIME} done if [[ ${rstflg} -eq 3 ]] ; then echo "lmtp process num is greter than ${threshholdproc}, dovecot restart" timeout 5 systemctl restart dovecot fi flock -u 9 exit 0