Corrected loading of log4j.conf at runtime
[aquarium] / dist / aquarium.sh
1 #!/usr/bin/env bash
2 #
3 # Aquarium init script 
4
5 #set -x
6
7 # resolve links - $0 may be a softlink
8 PRG="$0"
9
10 while [ -h "$PRG" ]; do
11   ls=`ls -ld "$PRG"`
12   link=`expr "$ls" : '.*-> \(.*\)$'`
13   if expr "$link" : '/.*' > /dev/null; then
14     PRG="$link"
15   else
16     PRG=`dirname "$PRG"`/"$link"
17   fi
18 done
19
20 # Get standard environment variables
21 PRGDIR=`dirname "$PRG"`
22
23 # Only set CATALINA_HOME if not already set
24 [ -z "$AQUARIUM_HOME" ] && AQUARIUM_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
25
26 AQMAIN=gr.grnet.aquarium.Main
27 PID=$AQUARIUM_HOME/bin/aquarium.pid
28 LIB=$AQUARIUM_HOME/lib
29 LOG=$AQUARIUM_HOME/logs/aquarium.log
30 CONF=$AQUARIUM_HOME/conf
31
32 # Check the application status
33 check_status() {
34
35     if [ -f $PID ]; then
36         aqrunning=`ps -ef|grep java|grep aquarium`
37         if [ -z "$aqrunning" ]; then
38             return 0
39             echo "Aquarium running, but no pid file found"
40         else
41             return 1
42         fi 
43     else
44        return 0
45     fi
46     
47     return 1
48 }
49
50 # Starts the application
51 start() {
52     check_status
53     if [ $? -ne 0 ] ; then
54         echo "Aquarium is running"
55         exit 1
56     fi
57
58     echo "Starting Aquarium"
59
60     # Build classpath
61     CLASSPATH=`find $LIB -type f|grep jar$|tr '\n' ':'|sed -e 's/\:$//'`
62     
63     # load log4j from classpath
64     CLASSPATH=$CONF:$CLASSPATH
65
66     # default properties
67     PROPS="-Dlog4j.debug=true"
68
69     echo "Using AQUARIUM_HOME $AQUARIUM_HOME"
70     echo "Using CLASSPATH $CLASSPATH"
71     echo "Using configuration files in $CONF"
72     echo "Using MAIN $AQMAIN"
73     java -cp $CLASSPATH $PROPS $AQMAIN >> $LOG 2>&1 &
74     echo $! > $PID 
75     echo "OK [pid = $!]"
76 }
77
78 # Stops the application
79 stop() {
80     check_status
81     if [ $? -eq 0 ] ; then
82         echo "Aquarium is not running"
83         exit 1
84     fi
85
86     # Kills the application process
87     echo -n "Stopping Aquarium: "
88     kill `cat $PID`
89     rm $PID
90     echo "OK"
91 }
92
93 # Show the application status
94 status() {
95     check_status
96     if [ $? -ne 0 ] ; then
97         echo "Aquarium is running (pid=$pid)"
98     else
99         echo "Aquarium is stopped"
100     fi
101 }
102
103 # Main logic, a simple case to call functions
104 case "$1" in
105     start)
106         start
107         ;;
108     stop)
109         stop
110         ;;
111     status)
112         status
113         ;;
114     restart|reload)
115         stop
116         start
117         ;;
118     *)
119         echo "Usage: $0 {start|stop|restart|reload|status}"
120         exit 1
121 esac
122
123 exit 0
124
125 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
126