| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #!/bin/bash
-
- BASE=/home/... # 프로그램 루트경로
-
- LIB=$BASE/lib
- PID=$BASE/.pid
- PSEXE="/bin/ps"
-
- classpath()
- {
- JARS=`ls $LIB/*.jar`
- for jar in $JARS
- do
- cp=$cp:$jar
- done
- }
- classpath
- export CLASSPATH=.:$CLASSPATH:$cp
-
- checkRunning(){
- if [ -f "$PID" ]; then
- if [ -z "`cat $PID`" ];then
- echo "ERROR: Pidfile '$PID' exists but contains no pid"
- return 2
- fi
- PID=`cat $PID | tail -1`
- RET=`$PSEXE -p $PID|grep java`
- if [ -n "$RET" ];then
- return 0
- else
- return 1
- fi
- else
- return 1
- fi
- return 1
- }
-
-
- invoke_start(){
- checkRunning
- retval=$?
- if [ "$retval" -eq 0 ];then
- PID=`cat $PID | tail -1`
- echo "already running (pid '$PID')"
- exit 0
- else
- exec java com.google.App & # 프로그램 실행 (자바는 java 클래스파일)
- PID=`ps -ef | grep App | head -n1 | awk ' {print $2;} '` # grep 다음에 프로그램 이름
- echo ${PID} > ${PID}
- fi
- }
-
- invoke_stop(){
- checkRunning
- retval=$?
- if [ "$retval" -eq 0 ];then
- PID=`cat $PID | tail -1`
- kill -9 $PID
- else
- echo "already stop "
- fi
- }
-
- invoke_status(){
- checkRunning
- retval=$?
- if [ $retval -eq 0 ];then
- PID=`cat $PID | tail -1`
- echo "Program is running (pid '$PID')"
- exit 0
- fi
- echo "Program not running"
- exit 1
- }
-
-
- case "$1" in
- 'start')
- invoke_start
- ;;
-
- 'stop')
- invoke_stop
- ;;
-
- 'status')
- invoke_status
- ;;
-
- *)
- echo "Usage: $0 { start | stop | status }"
- exit 1
- ;;
- esac
-
- exit 0
|