編寫啟動指令碼

來源:互聯網
上載者:User

編寫啟動指令碼 以前寫的啟動指令碼都沒有顏色,研究了下functions ,functions 是個很好的啟動指令碼介面檔案,最重要的是daemon和killproc2個函數。於是自己跟著寫了nginx的 #!/bin/bash     #chkconfig:35 23 34   #description: nginx webserver#set -x  if [ -f  /etc/init.d/functions ] ; then  . /etc/init.d/functions     ##載入functions,. 在這裡相當於source的功能fiprog=nginx  ##服務名,會多處調用RETVAL=0  ##狀態傳回值,functions 函數會調用這個值nginx=/usr/local/nginx/sbin/nginxNGINX_CONF_FILE=/usr/local/nginx/conf/nginx.confpidfile=/usr/local/nginx/logs/nginx.pidlockfile=/var/lock/subsys/${prog}  ##subsys目錄下的檔案是用於給其他程式判斷服務的執行個體運行狀態的  start() {      echo  -n $"Starting $prog: "      daemon $nginx  -c  $NGINX_CONF_FILE ###daemon調用後面的命令執行情況      RETVAL=$?      echo       [ $RETVAL  -eq  0  ] &&  touch ${lockfile}      return $RETVAL}stop () {      echo  -n $"Stopping $prog: "      killproc  -p ${pidfile}    ###killproc 從pidfile 擷取到pid,並殺死      #RETVAL=$?      echo       [ $RETVAL  -eq  0  ] &&  /bin/rm -f ${lockfile}      return $RETVAL}  case $1 in start) start;;stop)stop;;restart)stopstart;;  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.