唐弟蒋姐|唐弟蒋姐app|www.tdjj.net|tdjj app|app应用下载    应用:10787 当日:0 新闻:59 当日:0

linux 服务停止自动重启 脚本| 服务停止自动重启 脚本

来源: 唐弟蒋姐|唐弟蒋姐app|www.tdjj.net|tdjj app|app应用下载    时间:2016-07-15 10:44:26

HTTPD服务停止自动重启脚本
 
#!/bin/sh
 
while :
do
  stillRunning=$(ps -ef |grep "/usr/sbin/httpd" |grep -v "grep")
  if [ "$stillRunning" ] ; then
    echo "httpd service was already started"              
  else
    echo "httpd service was not started"
    echo "Starting service ..."
    /etc/init.d/httpd start
    echo "httpd service was exited!"
  fi
  sleep 10
done
 
MYSQL-Server   服务停止自动重启脚本
#!/bin/sh
 
while :
do
  MYSQLRunning=$(ps -ef |grep " /usr/bin/mysqld_safe" |grep -v "grep")
  if [ "$MYSQLRunning" ] ; then
    echo "mysqld service was already started"
  else
    echo "mysqld service was not started"
    echo "Starting service ..."
    /etc/init.d/mysqld start
    echo "mysqld service was exited!"
  fi
  sleep 15
done


合并后的脚本 
 
#!/bin/sh
 
while :
do
  stillRunning=$(ps -ef |grep "/usr/sbin/httpd" |grep -v "grep")
  if [ "$stillRunning" ] ; then
    echo "httpd service was already started"               
  else
    echo "httpd service was not started"
    echo "Starting service ..."
    /etc/init.d/httpd start
    echo "httpd service was exited!"
  fi
  sleep 10
 
  MYSQLRunning=$(ps -ef |grep " /usr/bin/mysqld_safe" |grep -v "grep")
  if [ "$MYSQLRunning" ] ; then
    echo "mysqld service was already started"
  else
    echo "mysqld service was not started"
    echo "Starting service ..."
    /etc/init.d/mysqld start
    echo "mysqld service was exited!"
  fi
  sleep 15
done

执行方式
可以使用crontab 调用
也可以让他在后台执行
path/xxx.sh &