Shell腳本注冊(cè)到Linux系統(tǒng)服務(wù)實(shí)例
注冊(cè)一個(gè)系統(tǒng)服務(wù),開機(jī)自啟動(dòng).
1 腳本編寫
#vim test.sh
#!/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注冊(cè)服務(wù)
# chmod 700 test.sh
# cp test.sh /etc/init.d/
# chkconfig --add test.sh
# chkconfig --list
3.刪除服務(wù)
# chkconfig --del test.sh
相關(guān)文章
linux中shell腳本實(shí)現(xiàn)下載完關(guān)機(jī)
本文給大家分享的是個(gè)人在實(shí)際應(yīng)用中制作的一個(gè)小程序,十分的實(shí)用,推薦給大家,有需要的小伙伴可以參考下。2015-03-03實(shí)現(xiàn)自動(dòng)清除日期目錄shell腳本實(shí)例代碼
這篇文章主要介紹了實(shí)現(xiàn)自動(dòng)清除日期目錄shell腳本實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-04-04Linux?自動(dòng)化構(gòu)建工具make/Makefile的使用詳解
這篇文章主要介紹了Linux?自動(dòng)化構(gòu)建工具?make/Makefile,要如何編譯.c文件,關(guān)鍵就在于Makefile是怎么寫的,下面我們主要介紹這兩者的使用,需要的朋友可以參考下2022-04-04linux?命令中的大于號(hào)、小于號(hào)的作用及代表的意思
在linux中,大家也許會(huì)經(jīng)??吹?<???、<<?、<<<?、>、>>?這幾個(gè)小于號(hào)、大于號(hào),那么他們分別代表什么意思呢?下面小編通過本文給大家介紹下linux?命令中的大于號(hào)、小于號(hào)的作用,感興趣的朋友一起看看吧2023-01-01Linux更新Python版本及修改python默認(rèn)版本的方法
很多情況下拿到的服務(wù)器python版本很低,需要自己動(dòng)手更改默認(rèn)python版本,但是有好多朋友都被這個(gè)問題難倒了,接下來,通過本篇文章給大家介紹linux更新Python版本及修改默認(rèn)版本的方法,感興趣的朋友一起學(xué)習(xí)吧2015-12-12bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpret
這篇文章主要介紹了bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory,需要的朋友可以參考下2014-10-10