自定義服務啓動腳本

Redhat 裝軟件通常會帶有服務啓動的腳本,若是遇到一些軟件或者程序須要源碼安裝則須要,本身編寫軟件服務的啓動程序shell

1,自定義編寫apache的apache

[root@IBM rc5.d]# cat /etc/init.d/Apache
#!/bin/bash
#下面註釋對自己的shell沒什麼做用,可是對checkconfig這個程序會讀取這個註釋,- 是默認值,任何級別都不開,能夠設置成2345,
#chkconfig: - 80 90
file=/var/run/httpd/httpd.pid
start(){
    if [ ! -f $file ];then
        /usr/sbin/httpd
        echo "httpd 正在運行"
    else
        echo "已經啓動過了"
    fi
}
stop(){
    if [ -f $file ];then
        kill `cat $file`
        echo "httpd 正在中止"
    else
        echo "已經中止了"  
    fibash

}函數

case $1 in
start)
    start;;
stop)
    stop;;
restart)
    kill `cat $file`
    echo "httpd 正在中止"
    sleep 1
    /usr/sbin/httpd
    echo "httpd 正在啓動";;
status)
    if [ -f $file ];then
        echo "Aapche 正在運行"
    else
        echo "Apache 沒有運行"
    fi;;
*)
    echo "usage: {start|stop|status}";;
esac.net


#重複的代碼能夠作成一個函數,直接掉rest

相關文章
相關標籤/搜索