• 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
  • 相关阅读:
    【WPF】WPF Behavior 行为 实现鼠标移入按钮自动旋转
    cgo遇到的几个坑
    工程师什么时机最合适选择跳槽?
    在 ASP.NET Core 中自动启用 CAP 事务
    轻量级压力测试工具http_load
    纯C语言AES-128(可修改)-ECB模式加密-zero模式
    内存字符串暴力搜索定位代码
    windbg配置网络版双机调试
    安装docker compose
    linux安装基础软件包
  • 原文地址:https://www.cnblogs.com/qmfsun/p/6305567.html
Copyright © 2020-2023  润新知