mardi 6 décembre 2011

Use script to start/stop/restart a java program

like start tomcat, write a script to start/stop/restart a java program:

script.sh
use: sh script.sh start

#!/bin/sh 
 
SERVER=/Users/cwang/desktop/test 
cd $SERVER 
 
case "$1" in 
 
  start) 
    nohup java -Xmx128m HelloWorld > $SERVER/server.log 2>&1 & 
    echo $! > $SERVER/server.pid 
    ;; 
 
  stop) 
    kill `cat $SERVER/server.pid` 
    rm -rf $SERVER/server.pid 
    ;; 
 
  restart) 
    $0 stop 
    sleep 1 
    $0 start 
    ;; 
 
  *) 
    echo "Usage: run.sh {start|stop|restart}" 
    ;; 
 
esac 
 
exit 0



Original: http://www.iteye.com/problems/14572

Aucun commentaire:

Enregistrer un commentaire