国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Linux Shell > 正文

Shell腳本注冊到Linux系統(tǒng)服務(wù)實例

2020-07-27 19:06:43
字體:
供稿:網(wǎng)友

注冊一個系統(tǒng)服務(wù),開機(jī)自啟動.

1 腳本編寫

#vim test.sh

復(fù)制代碼 代碼如下:

#!/bin/bash 
 
#description: hello.sh 
#chkconfig: 2345 20 81 
 
EXEC_PATH=/usr/local/ 
EXEC=hello.sh 
DAEMON=/usr/local/hello.sh 
PID_FILE=/var/run/hello.sh.pid 
 
. /etc/rc.d/init.d/functions 
 
if [ ! -x $EXEC_PATH/$EXEC ] ; then 
       echo "ERROR: $DAEMON not found" 
       exit 1 
fi 
 
stop() 

       echo "Stoping $EXEC ..." 
       ps aux | grep "$DAEMON" | kill -9 `awk '{print $2}'` >/dev/null 2>&1 
       rm -f $PID_FILE 
       usleep 100 
       echo "Shutting down $EXEC: [  OK  ]"     

 
start() 

       echo "Starting $EXEC ..." 
       $DAEMON > /dev/null & 
       pidof $EXEC > $PID_FILE 
       usleep 100 
       echo "Starting $EXEC: [  OK  ]"         

 
restart() 

    stop 
    start 

 
case "$1" in 
    start) 
        start 
        ;; 
    stop) 
        stop 
        ;; 
    restart) 
        restart 
        ;; 
    status) 
        status -p $PID_FILE $DAEMON 
        ;; 
    *) 
        echo "Usage: service $EXEC {start|stop|restart|status}" 
        exit 1 
esac 
 
exit $? 

2注冊服務(wù)

復(fù)制代碼 代碼如下:

# chmod 700 test.sh
# cp test.sh /etc/init.d/
# chkconfig --add test.sh
# chkconfig --list

3.刪除服務(wù)
復(fù)制代碼 代碼如下:

# chkconfig  --del test.sh

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 甘孜| 图片| 阿拉善右旗| 大连市| 汝城县| 德江县| 临沂市| 河池市| 广丰县| 巫溪县| 巴东县| 新巴尔虎左旗| 遂昌县| 札达县| 区。| 平昌县| 武定县| 龙里县| 毕节市| 上虞市| 吉林市| 当阳市| 宝鸡市| 建始县| 柞水县| 铅山县| 定安县| 皋兰县| 马边| 六枝特区| 永善县| 曲水县| 宜都市| 霍林郭勒市| 兴城市| 囊谦县| 醴陵市| 紫金县| 临洮县| 娱乐| 梨树县|