一、httpd:unrecognized service 解决办法

将apache安装为系统服务
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
然后 vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面)
# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server
最后,运行chkconfig把Apache添加到系统的启动服务组里面:
# chkconfig --add httpd
# chkconfig httpd on
然后再service httpd start

 

一、apache服务监控脚本

#!/bin/bash
function check_httpd_status()
{
httpd=`ps -ef  |grep httpd |awk '{if($3==1)print $0}'|awk '{if($1=="root")print $3 }'`
if [ "$httpd" != 1 ];then
#   service httpd restart &> /dev/null
   echo "httpd 服务已经宕机,本程序已经重启过,请确认是否成功" >> /var/log/messages
sleep 300
  if [ "$httpd" == 1 ];then
   echo "httpd 服务已经重启成功" >> /var/log/messages
else
   echo "httpd 服务重启不成功,请登录服务器查明原因,手动启动!"  >> /var/log/messages
  fi
fi
}
check_httpd_status