欢迎来到云服务器

Directadmin Linux面板

用ipcs/ipcrm自动删除apache信号量

如果您经常需要使用ipcs / ipcrm工具删除apache信号量,并且如果您无法理清它们为何继续建立起来,那么使用cronjob自动清除它们,如果它们堆积起来可能会有所帮助。
 
更新:DirectAdmin 1.53.0+现在有一个可以调用的钩子脚本,而不是使用cron。 这应该可以提供更快的反应时间,从而降低服务质量:
https://www.directadmin.com/features.php?id=2101
在确认“$ service”是“httpd”之后,您将使用以下脚本,例如:

if [ "$service" != "httpd" ]; then
       exit 1;
fi

插入#!/bin.sh行的正下方。
 
否则为cron方法,请在以下位置创建脚本:

/etc/cron.hourly/ipcs_check

内容:

#!/bin/sh

EMAIL=your@email.com
MAX_SEMAPHORES=15

IPCS=/usr/bin/ipcs
IPCRM=/usr/bin/ipcrm
MAIL=/bin/mail

COUNT=`${IPCS} | grep apache | wc -l`

if [ "$COUNT" -le $MAX_SEMAPHORES ]; then
       #all is well, there are no semaphore build-ups.
       exit 0;
fi

#we have more than MAX_SEMAPHORES, so clear them out and restart Apache.

LIST=/root/sem.txt

${IPCS} | grep apache | awk '{print $2}' > ${LIST}
for i in `cat ${LIST}`; do
{
       ${IPCRM} -s $i;
};
done;

/etc/init.d/httpd restart

TXT="${COUNT} semaphores cleared for apache for `hostname`"
echo "${TXT}" | ${MAIL} -s "${TXT}" ${EMAIL}

exit 1;

然后将脚本chmod到755:

chmod 755 /etc/cron.hourly/ipcs_check


在每个小时检查一次/ var / log / cron,以确保crond正在运行它。
如果一切正常,那么不应该有任何问题,脚本将退出,返回码为0。
腾讯云代理

Copyright © 2003-2021 MFISP.COM. 国外vps服务器租用 梦飞云服务器租用 版权所有 粤ICP备11019662号