亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 為什么腳本中后臺運行java程序,java程序啟動之后總是自動終止! [打印本頁]

作者: placidy    時間: 2006-05-09 17:39
標(biāo)題: 為什么腳本中后臺運行java程序,java程序啟動之后總是自動終止!
我寫了腳本放到/etc/init.d下面做成服務(wù),start服務(wù)總是啟動之后就終止.

具體情況是這樣的,寫了腳本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 編輯 ]
作者: placidy    時間: 2006-05-09 18:11
大家都下班了?
作者: placidy    時間: 2006-05-10 08:50
是我哪里沒有說明白么?
作者: placidy    時間: 2006-05-10 09:09
整理一下我的問題,/etc/init.d/test 腳本中試過以下幾種:
1、java -cp test.jar com.test.test
可以運行,但是占用終端
2、java -cp test.jar com.test.test &
運行之后自動終止
3、nohup java -cp test.jar com.test.test
可以運行,但占用終端
4、nohup java -cp test.jar com.test.test &
運行之后自動終止
作者: waker    時間: 2006-05-10 10:28
說明 你的test.test需要終端,不能放在后面運行,改test.test
作者: placidy    時間: 2006-05-12 10:26
恩,我取消了終端交互,可以了.謝謝waker.




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2