守護進程的shell--tipserver

來源:互聯網
上載者:User

守護進程的shell--tipserver 1:可以直接關掉終端,在後台運行2:可以查詢服務的狀態 3:可以定時啟動需要啟動並執行程式(範例為17點啟動) 4:可以在運行時避免重複啟動tipserver #!/bin/sh run_main_programer(){while truedoif [ "$date_hour" = '17' ]thenas=`date +'%Y%m%d_%H%M%S'`sh ./control_sh.sh >log/control_sh_$as.logsleep 3600fisleep 300date_hour=`date +'%H'`done}  myself=`echo $0 | sed 's/^\.\///g'`  if [ $# -eq 0 ]then  echo "Unknown command option"  echo "Usage::"  echo "       $myself start | stop | status"  exitfi  case "x$1"inxstart)#當前後台啟動並執行線程列表thread=`ps -ef | grep -v grep | grep -w "$myself" | grep "start" | awk '{ print $2 }'`#只有本線程運行if [ "$thread" = "$$" ]thennohup sh $myself start >/dev/null &sleep 3echo "The $myself have been started."else#取得父線程號father_thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | grep "$$" | awk '{ print $3 }'`#當前線程的父線程存在if [ `ps -ef | grep -v grep | grep "$myself" | grep "start" | grep "$father_thread" | wc -l` -eq 2 ]thenrun_main_programerfiecho "The $myself is running."fi;;xstop)thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | awk '{ print $2 }'`if [ -n "$thread" ]thenkill -9 ${thread} 2>/dev/nullfiecho "The $myself have been stoped.";;xstatus)thread=`ps -ef | grep -v grep | grep "$myself" | grep "start" | awk '{ print $2 }'`if [ -n "$thread" ]thenecho "The $myself is running."elseecho "The $myself is not running."fi;;*)echo '  Error parameter.'esac 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.