zoukankan      html  css  js  c++  java
  • linux重启服务的脚本命令

    最近做网站测试,每次测试完成都要重启服务,为此写了一个简单的shell脚本

    linux服务重启shell脚本示例
    2014年12月18日
    
          linux服务重启脚本,如何实现linux服务的定时重启,可以借助shell脚本来完成,ps命令捕获进程信号,kill命令杀死进程,然后linux服务重新启动。
    
          例如:
    
          #ls -l
          drwxr-xr-x. 4 richmail richmail     4096 12月  8 15:17 admin 
          drwxr-xr-x. 5 richmail richmail     4096 12月 11 09:56 help 
          -rw-rw-r--. 1 richmail richmail 46398327 12月 11 11:25 help.zip 
          drwxr-xr-x. 4 richmail richmail     4096 12月 10 17:39 mail 
          -rwxr-xr-x. 1 richmail richmail      500 12月  5 17:56 restartTomcat.sh 
          -rw-r--r--. 1 richmail richmail 51784276 12月 10 17:40 ThinkMail_webmail(V2.0.0)_201412101739.zip 
          drwxr-xr-x. 9 richmail richmail     4096 11月 17 18:17 tomcat7 
          -rw-rw-r--. 1 richmail richmail        0 10月 22 13:12 x 
          [richmail@datanode1 webmailsvr]$ cat restartTomcat.sh  
          #Author : dengliang 
          #Desc : restart tomcat 
          #Time : 2014-12-05 
          tomcatpath="/home/richmail/web/webmailsvr/tomcat7"
    
          linux服务重启shell脚本,以tomcat服务为例: 
    
          复制代码 代码示例:
    
          #!/bin/sh 
          #kill tomcat pid 
    
          pidlist=`ps -ef|grep $tomcatpath |grep -v "grep"|awk '{print $2}'` 
          if [ "$pidlist" = "" ] 
          then 
          echo "no tomcat pid alive!" 
          else 
          echo "tomcat pid list :  $pidlist" 
          echo "killing pidlist :  $pidlist" 
          kill -9 $pidlist 
          echo "tomcat stopped successfully!"  
          sleep 1  
          fi 
          echo "now starting tomcat......" 
          cd $tomcatpath/bin 
    
          调用:
    
          ./startup.sh 
          cd - 
          #!/bin/sh
    
          #kill tomcat pid
    
          pidlist=`ps -ef|grep tomcat_message_8002|grep -v "grep"|awk '{print $2}'`  //找到tomcat的PID号
    
          echo "tomcat Id list :$pidlist"  //显示pid
    
          kill -9 $pidlist  //杀掉改进程
    
          echo "KILL $pidlist:" //提示进程以及被杀掉
    
          echo "service stop success"
    
          echo "start tomcat"
    
          cd /home/app/tomcat_message_8002
    
          rm -rf work/*
    
          cd bin
    
          ./startup.sh ;tail -f ../logs/catalina.out
  • 相关阅读:
    Centos7.6安装教程 && history设置显示执行命令的时间
    C# 调用第三方webapi 接口的示例(使用httpclient)
    asp.net core 上传文件
    Sql中CHARINDEX用法---判断数据库某个字段是否包含某个字符
    ASP.NET上传文件出现“404-找不到文件或目录”的解决办法
    C# 中转换的几种方式
    C# 向文件写入和读取文件内容
    C# 中正则表达式
    C# 写的通用得到富文本框中的图片路径
    C# 正则表达式输入验证必须为汉字
  • 原文地址:https://www.cnblogs.com/qmfsun/p/6305567.html
Copyright © 2011-2022 走看看