Shell脚本实现温和方式重启Centos系统
主要目的是用于重启后台比较重要的进程,如果采用killall -9强制kill掉,可能会引起问题。比如数据库进程。代码如下:
#!/bin/sh
if [ -z "$1" ]; then
/bin/echo "$0 <command line>"
exit 1
fiparam=''
list='2 3 4 5 6 7 8 9'
for i in $list; do
eval p='$'$i
if [ -z $p ]; then
break
fi
param="$param $p"
doneif [ -f /bin/awk ]; then
AWK=/bin/awk
else
AWK=/usr/bin/awk
fiif [ -f /bin/grep ]; then
GREP=/bin/grep
else
GREP=/usr/bin/grep
fiprogram=`/bin/echo $1 | $AWK -F '/' '{print $NF;}'`
count=`/bin/ps auxww | $GREP -w $program | $GREP -v grep | /usr/bin/wc -l`
if [ $count -gt 0 ]; then
i=0
/bin/echo "stopping $program ..."
while [ 1 -eq 1 ]; do
if [ $i -eq 0 ]; then
/usr/bin/killall $program
else
/usr/bin/killall $program >/dev/null 2>&1
fiif [ $? -ne 0 ]; then
break
fi/usr/bin/printf .
/bin/sleep 1
let i=$i+1
done
fi/bin/echo ""
count=`/bin/ps auxww | $GREP -w $program | $GREP -v grep | $GREP -v $0 | /usr/bin/wc -l`
if [ $count -eq 0 ]; then
/bin/echo "starting $program ..."
exec $1 $param
else
/bin/ps auxww | $GREP -w $program | $GREP -v grep | $GREP -v $0
/bin/echo "already running $program count: $count, restart aborted!"
fi
您可能感兴趣的文章:
- Shell脚本实现温和方式重启Centos系统
- CentOS6.7下使用非root用户(普通用户)编译安装与配置mysql数据库并使用shell脚本定时任务方式实现mysql数据库服务随机自动启动
- 使用c和shell实现远程tomcat的重启备份脚本
- 用shell脚本实现linux系统上wifi模式(STA和soft AP)的转换
- 《怎样实现通过shell脚本将用户踢出系统》
- CentOS 6.x系统升级Python到2.7版本的Shell脚本分享
- linux系统资源负载过高自动重启apache的shell脚本
- android 2种切换语言方式:应用内切换和随系统而切换 代码实现重启应用
- 实现释放CentOS系统内存的Shell脚本分享
- Android系统关机或重启的几种实现方式
- Shell实现系统时间和BIOS时间同步校准脚本分享
- Android系统关机或重启的几种实现方式
- 以脚本的方式实现启用系统还原
- Shell实现多级菜单系统安装维护脚本实例分享
- centos系统服务优化SHELL脚本
- CentOS 6.4 Linux vsftpd shell管理系统脚本完整版
- 实现释放CentOS系统内存的Shell脚本分享
- 工作流系统之自定义脚本的实现方式
- Shell实现多级菜单系统安装维护脚本实例分享
- shell脚本实现对系统的自动分区