- 論壇徽章:
- 0
|
我寫了腳本放到/etc/init.d下面做成服務,start服務總是啟動之后就終止.
具體情況是這樣的,寫了腳本test放到/etc/init.d下面,里面提供start,stop等功能.
start是執(zhí)行java程序,
1、用java -cp test.jar com.test.test可以執(zhí)行,但是會占用終端。
2、用service test start運行,java程序確實運行了,但是之后馬上終止了.
service test stop等命令執(zhí)行卻沒有問題。,.
腳本如下
#!/bin/bash
#
# chkconfig: 235 99 99
# description: Starts and stops test service
prog="test"
version="$prog Ver 2006.04.04 Distrib 1.1.2, for linux"
prog_path="/usr/local/test"
start() {
pre=$(ps -ax|grep java|grep "test.jar"|grep -v grep)
if [ -n "$pre" ]
then
echo -e "$prog is already running!"
exit 0
fi
if cd $prog_path
then
stty tostop
/usr/local/jdk/bin/java -cp /usr/local/test/test.jar com.test.test &
fi
echo -n "Starting $prog "
psstart=$(ps -ax|grep java|grep "test.jar"|grep -v grep)
if [ -n "$psstart" ]
then
echo -e " [ OK ]"
else
echo -e " [ FAILED ]"
fi
}
status() {
test=$(ps -ax|grep java|grep "test.jar"|grep -v grep)
echo -n "$prog "
if [ -n "$test" ]
then
echo -e "is running."
else
echo -e "is stopped."
fi
}
stop() {
befpid=$(ps -ax|grep java|grep "test.jar"|grep -v grep)
if [ -n "$befpid" ]
then
pid=$(ps -ax|grep java|grep "test.jar"|grep -v grep|cut -d" " -f1)
if [ -z "$pid" ]
then
pid=$(ps -ax|grep java|grep "test.jar"|grep -v grep|cut -d" " -f2)
fi
stty -echo
kill -9 "$pid"
stty echo
fi
sleep 1
psstop=$(ps -ax|grep java|grep "test.jar"|grep -v grep)
echo -n "Shut down $prog "
if [ -n "$psstop" ]
then
echo -e " [ FAILED ]"
else
echo -e " [ OK ]"
fi
}
version() {
echo "$version"
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
status)
status
;;
version)
version
;;
*)
echo -e $"$version \nUsage: $0 {start|stop|restart|status|version}"
exit 1
esac
[ 本帖最后由 placidy 于 2006-5-10 09:19 編輯 ] |
|