Statistics
| Branch: | Tag: | Revision:

root / scripts / aquarium.sh @ 04156e06

History | View | Annotate | Download (5.2 kB)

1
#!/usr/bin/env bash
2
#
3
# Copyright 2012 GRNET S.A. All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
#
9
#   1. Redistributions of source code must retain the above copyright
10
#      notice, this list of conditions and the following disclaimer.
11
#
12
#  2. Redistributions in binary form must reproduce the above copyright
13
#     notice, this list of conditions and the following disclaimer in the
14
#     documentation and/or other materials provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
# SUCH DAMAGE.
27
#
28
# The views and conclusions contained in the software and documentation are
29
# those of the authors and should not be interpreted as representing official
30
# policies, either expressed or implied, of GRNET S.A.
31

    
32
#
33
# Init script for Aquarium
34
#
35
#-----------------------
36
# Supported environment variables
37
#
38
# JAVA_OPTS       Runtime options for the JVM that runs Aquarium
39
#                 (default: -Xms1024M -Xmx4096M)
40
#
41
# AQUARIUM_PROP   Java system properties understood by Aquarium
42
#                 (default: -Dlog4j.debug=true)
43
#
44
# AQUARIUM_OPTS   Runtime options for Aquarium
45
#                 (default: "")
46
#
47
# AQUARIUM_HOME   Location of the top level Aquarium dir
48
#                 (default: .)
49
#----------------------
50

    
51
#set -x
52

    
53
# resolve links - $0 may be a softlink
54
PRG="$0"
55

    
56
while [ -h "$PRG" ]; do
57
  ls=`ls -ld "$PRG"`
58
  link=`expr "$ls" : '.*-> \(.*\)$'`
59
  if expr "$link" : '/.*' > /dev/null; then
60
    PRG="$link"
61
  else
62
    PRG=`dirname "$PRG"`/"$link"
63
  fi
64
done
65

    
66
# Get standard environment variables
67
PRGDIR=`dirname "$PRG"`
68

    
69
# Only set supported environment variables if not already set
70
[ -z "$AQUARIUM_HOME" ] && AQUARIUM_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`
71
[ -z "$AQUARIUM_PROP" ] && AQUARIUM_PROP=""
72
[ -z "$AQUARIUM_OPTS" ] && AQUARIUM_OPTS=""
73
[ -z "$JAVA_OPTS" ]     && JAVA_OPTS="-Xms1024M -Xmx4096M"
74

    
75
export AQUARIUM_HOME
76

    
77
PID_FILE=$AQUARIUM_HOME/bin/aquarium.pid
78

    
79
AQUARIUM_LIB=$AQUARIUM_HOME/lib
80
AQUARIUM_CONF=$AQUARIUM_HOME/conf
81
AQUARIUM_LOGFILE=$AQUARIUM_HOME/logs/aquarium.log
82

    
83
AQUARIUM_MAIN_CLASS=gr.grnet.aquarium.Main
84

    
85
# We use jbootstrap to start the application.
86
# No need to manually setup the CLASSPATH
87
JBOOT_JAR=$AQUARIUM_LIB/jbootstrap-3.0.0.jar
88
JBOOT_MAIN_CLASS=com.ckkloverdos.jbootstrap.Main
89

    
90
# Check the application status
91
check_status() {
92
    if [ -f $PID_FILE ]
93
    then
94
        aqrunning=`ps -ef|grep java|grep $AQUARIUM_MAIN_CLASS`
95
        if [ -z "$aqrunning" ]
96
        then
97
            return 0
98
            echo "Aquarium running, but no pid file found"
99
        else
100
            return 1
101
        fi 
102
    else
103
       return 0
104
    fi
105
    
106
    return 1
107
}
108

    
109
# Starts the application. If "debug" is passed as argument, aquarium starts
110
# in debug mode
111
start() {
112
    check_status
113
    if [ $? -ne 0 ]
114
    then
115
        echo "Aquarium is running"
116
        exit 1
117
    fi
118

    
119
    echo "Starting Aquarium"
120

    
121
    CLASSPATH=$JBOOT_JAR
122

    
123
    echo "Using initial CLASSPATH $CLASSPATH"
124
    echo "Using AQUARIUM_HOME $AQUARIUM_HOME"
125
    echo "Using MAIN $AQUARIUM_MAIN_CLASS"
126
    echo "Using AQUARIUM_PROP $AQUARIUM_PROP"
127
    echo "Using JAVA_OPTS $JAVA_OPTS"
128
    echo "nohup java $JAVA_OPTS -cp $CLASSPATH $AQUARIUM_PROP $JBOOT_MAIN_CLASS -lib $AQUARIUM_LIB $AQUARIUM_MAIN_CLASS > $AQUARIUM_LOGFILE"
129

    
130
    nohup java $JAVA_OPTS -cp $CLASSPATH $AQUARIUM_PROP $JBOOT_MAIN_CLASS -lib $AQUARIUM_LIB $AQUARIUM_MAIN_CLASS > $AQUARIUM_LOGFILE 2>&1 &
131
    echo $! > $PID_FILE
132
    echo "OK [pid = "`cat $PID_FILE`"]"
133
}
134

    
135
# Stops the application
136
stop() {
137
    check_status
138
    if [ $? -eq 0 ]
139
    then
140
        echo "Aquarium is not running"
141
        exit 1
142
    fi
143

    
144
    # Kills the application process
145
    echo -n "Stopping Aquarium: "
146
    kill `cat $PID_FILE`
147
    rm $PID_FILE
148
    echo "OK"
149
}
150

    
151
# Show the application status
152
status() {
153
    check_status
154
    if [ $? -ne 0 ]
155
    then
156
        echo "Aquarium is running (pid="`cat $PID_FILE`")"
157
    else
158
        echo "Aquarium is stopped"
159
    fi
160
}
161

    
162
ps_aquarium() {
163
  ps -ef | grep java | grep gr.grnet.aquarium.Main
164
}
165

    
166
forcekill() {
167
  local PIDS=`ps_aquarium | awk '{print $2}'`
168
  for pid in $PIDS; do
169
    echo Killing $pid
170
    kill -9 $pid
171
  done
172
}
173

    
174
# Main logic, a simple case to call functions
175
case "$1" in
176
  start)
177
    start
178
    ;;
179
  stop)
180
    stop
181
    ;;
182
  status)
183
    status
184
    ;;
185
  restart)
186
    stop
187
    start
188
    ;;
189
  ps)
190
    ps_aquarium
191
    ;;
192
  forcekill)
193
    forcekill
194
    ;;
195
  *)
196
      echo "Usage: $0 {start|stop|restart|status|ps|forcekill}"
197
      exit 1
198
    esac
199
exit 0
200

    
201
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
202