Shell腳本注冊到Linux系統(tǒng)服務實例
更新時間:2015年05月11日 09:33:49 投稿:junjie
這篇文章主要介紹了Shell腳本注冊到Linux系統(tǒng)服務實例,本文給出一個可以作為Linux服務的腳本實例,及加入服務的方法等步驟,需要的朋友可以參考下
注冊一個系統(tǒ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注冊服務
復制代碼 代碼如下:
# chmod 700 test.sh
# cp test.sh /etc/init.d/
# chkconfig --add test.sh
# chkconfig --list
3.刪除服務
復制代碼 代碼如下:
# chkconfig --del test.sh
相關文章
Linux?自動化構建工具make/Makefile的使用詳解
這篇文章主要介紹了Linux?自動化構建工具?make/Makefile,要如何編譯.c文件,關鍵就在于Makefile是怎么寫的,下面我們主要介紹這兩者的使用,需要的朋友可以參考下2022-04-04Linux更新Python版本及修改python默認版本的方法
很多情況下拿到的服務器python版本很低,需要自己動手更改默認python版本,但是有好多朋友都被這個問題難倒了,接下來,通過本篇文章給大家介紹linux更新Python版本及修改默認版本的方法,感興趣的朋友一起學習吧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