1 |
d2a8c3fd
|
Marc NICOLAS
|
#! /bin/bash
|
2 |
|
|
|
3 |
|
|
# ---------
|
4 |
|
|
# Fonctions
|
5 |
|
|
# ---------
|
6 |
|
|
|
7 |
|
|
version() {
|
8 |
|
|
echo " SITools2 v.${version} ${copyright}"
|
9 |
|
|
}
|
10 |
|
|
|
11 |
|
|
usage() {
|
12 |
|
|
echo "USAGE"
|
13 |
|
|
echo " ${prog} <start|stop|restart|status> [-migration|-scalable]"
|
14 |
|
|
echo "PARAMETERS:"
|
15 |
|
|
echo " -migration : start Sitools2 in migration mode to skip XML fields that are not in the models anymore"
|
16 |
|
|
echo " -scalable : start Sitools2 in scalability mode"
|
17 |
|
|
echo " --version : display the version"
|
18 |
|
|
echo " "
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
# ---------
|
22 |
|
|
# This function is used to check when sitools must
|
23 |
|
|
# be allowed running even when a pid file is already
|
24 |
|
|
# present
|
25 |
|
|
#
|
26 |
|
|
# Returns 0 when both sitools is not running in memory and
|
27 |
|
|
# PID number exists in the the PID file
|
28 |
|
|
#
|
29 |
|
|
# Returns 1 when both PID number is present and sitools
|
30 |
|
|
# is running in memory
|
31 |
|
|
#
|
32 |
|
|
# Returns 2 when PID file is empty
|
33 |
|
|
#
|
34 |
|
|
# ---------
|
35 |
|
|
automaticCleanIsNeeded() {
|
36 |
|
|
local pid=`cat ${SITOOLS_PID}`
|
37 |
|
|
if [ "${pid}" != "" ];then
|
38 |
|
|
isRunning=`ps -ef |grep ${pid} | grep -v grep | grep ${SITOOLS_JAR_NAME}`
|
39 |
|
|
if [ "${isRunning}" != "" ];then
|
40 |
|
|
return 1
|
41 |
|
|
else
|
42 |
|
|
return 0
|
43 |
|
|
fi
|
44 |
|
|
else
|
45 |
|
|
return 2
|
46 |
|
|
fi
|
47 |
|
|
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
start() {
|
51 |
|
|
if [ -f ${SITOOLS_PID} ];then
|
52 |
|
|
automaticCleanIsNeeded
|
53 |
|
|
response=${?}
|
54 |
|
|
if [ ${response} -eq 1 ];then
|
55 |
|
|
status
|
56 |
|
|
elif [ ${response} -eq 0 ];then
|
57 |
|
|
rm ${SITOOLS_PID}
|
58 |
|
|
start ${1}
|
59 |
|
|
elif [ ${response} -eq 2 ];then
|
60 |
|
|
status
|
61 |
|
|
else
|
62 |
|
|
status
|
63 |
|
|
fi
|
64 |
|
|
else
|
65 |
|
|
if [ "${SITOOLS}" != "" ];then
|
66 |
|
|
cd ${START_DIR}
|
67 |
|
|
cp fr.cnes.sitools.core.jar ${SITOOLS_JAR_NAME}
|
68 |
|
|
local SITOOLS_START="./${SITOOLS}"
|
69 |
|
|
[ ! -x ${SITOOLS_START} ] && echo "Cannot start ${SITOOLS_START}" && exit 1
|
70 |
|
|
echo -e "Starting ${SITOOLS_START} ${1}...\c "
|
71 |
|
|
${SITOOLS_START} ${1} 2>&1 >> ${LOG}
|
72 |
|
|
if [ $? -ne 0 ];then
|
73 |
|
|
echo "[ERROR]" | tee -a ${LOG}
|
74 |
|
|
echo "A problem happens: cannot start ${SITOOLS_START} ..." | tee -a ${LOG}
|
75 |
|
|
echo "Please, check the script before starting." | tee -a ${LOG}
|
76 |
|
|
else
|
77 |
|
|
echo "[OK]" | tee -a ${LOG}
|
78 |
|
|
fi
|
79 |
|
|
fi
|
80 |
|
|
fi
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
stop() {
|
84 |
|
|
echo -e "Shutting down sitools...\c "
|
85 |
|
|
if [ ! -f ${SITOOLS_PID} ];then
|
86 |
|
|
echo "[ERROR]"
|
87 |
|
|
echo "The file ${SITOOLS_PID} cannot be found..."
|
88 |
|
|
isRunning=`ps -ef | grep -v grep | grep ${SITOOLS_JAR_NAME} | awk '{print $2}'`
|
89 |
|
|
if [ "${isRunning}" != "" -a "`echo ${isRunning} | tr -d [:digit:]`" = "" ];then
|
90 |
|
|
echo " "
|
91 |
|
|
echo "Try to stop sitools..."
|
92 |
|
|
kill ${isRunning}
|
93 |
|
|
else
|
94 |
|
|
echo "sitools seems to be stopped..."
|
95 |
|
|
fi
|
96 |
|
|
else
|
97 |
|
|
kill `cat ${SITOOLS_PID}`
|
98 |
|
|
if [ ${?} -eq 0 ];then
|
99 |
|
|
echo "[OK]"
|
100 |
|
|
rm ${SITOOLS_PID}
|
101 |
|
|
|
102 |
|
|
else
|
103 |
|
|
echo "[ERROR]"
|
104 |
|
|
fi
|
105 |
|
|
fi
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
status() {
|
109 |
|
|
echo -e "Status of sitools..."
|
110 |
|
|
if [ -f ${SITOOLS_PID} ];then
|
111 |
|
|
local pid=`cat ${SITOOLS_PID}`
|
112 |
|
|
if [ "${pid}" != "" ];then
|
113 |
|
|
isRunning=`ps -ef |grep ${pid} | grep -v grep | grep ${SITOOLS_JAR_NAME}`
|
114 |
|
|
if [ "${isRunning}" != "" ];then
|
115 |
|
|
echo "sitools is started (pid: ${pid})"
|
116 |
|
|
else
|
117 |
|
|
echo "Warning... Le PID file is there (${pid}) but the processus is absent. Please restart sitools"
|
118 |
|
|
fi
|
119 |
|
|
else
|
120 |
|
|
echo "the file ${SITOOLS_PID} is empty! An error may occured during starting sitools..."
|
121 |
|
|
fi
|
122 |
|
|
else
|
123 |
|
|
isRunning=`ps -ef |grep java | grep -v grep | grep ${SITOOLS_JAR_NAME}`
|
124 |
|
|
if [ "${isRunning}" != "" ];then
|
125 |
|
|
echo "... The PID file is absent but the processus seems working in memory."
|
126 |
|
|
else
|
127 |
|
|
echo "sitools is stopped."
|
128 |
|
|
fi
|
129 |
|
|
fi
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
# ---------
|
133 |
|
|
# Principal
|
134 |
|
|
# ---------
|
135 |
|
|
prog=`basename ${0}`
|
136 |
|
|
myDir=`dirname ${0}`
|
137 |
|
|
myPid=${$}
|
138 |
|
|
|
139 |
|
|
# Version de sitools
|
140 |
|
|
version="3.0"
|
141 |
|
|
copyright="Copyright 2010-2014 CNES"
|
142 |
|
|
|
143 |
|
|
# Parametrage de l'environnement
|
144 |
|
|
[ -f ${HOME}/.bash_profile ] && . ${HOME}/.bash_profile
|
145 |
|
|
|
146 |
|
|
LOG_DIR="/home/marc/sitoolsSource/source-3.0/LOG"
|
147 |
|
|
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
|
148 |
|
|
|
149 |
|
|
LOG="${LOG_DIR}/sitools.log"
|
150 |
|
|
|
151 |
|
|
[ "${1}" = "" ] && usage && exit 0
|
152 |
|
|
|
153 |
|
|
[ "${1}" = "--version" ] && version && exit 0
|
154 |
|
|
|
155 |
|
|
START_DIR="/home/marc/sitoolsSource/source-3.0/workspace/fr.cnes.sitools.core"
|
156 |
|
|
SITOOLS="startSitools.sh"
|
157 |
|
|
SITOOLS_START="${START_DIR}/${SITOOLS}"
|
158 |
|
|
SITOOLS_PID="${LOG_DIR}/${SITOOLS}.run"
|
159 |
|
|
SITOOLS_JAR_NAME="8182_fr.cnes.sitools.core.jar"
|
160 |
|
|
|
161 |
|
|
if [ ! -x ${SITOOLS_START} ];then
|
162 |
|
|
echo "--- ERROR ---" | tee -a ${LOG}
|
163 |
|
|
echo "${SITOOLS_START} cannot be found or executed. Abandon." | tee -a ${LOG}
|
164 |
|
|
echo "--- ERROR ---" | tee -a ${LOG}
|
165 |
|
|
exit 1
|
166 |
|
|
fi
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
case ${1} in
|
171 |
|
|
start)
|
172 |
|
|
start ${2}
|
173 |
|
|
;;
|
174 |
|
|
stop)
|
175 |
|
|
stop
|
176 |
|
|
;;
|
177 |
|
|
restart)
|
178 |
|
|
stop
|
179 |
|
|
start ${2}
|
180 |
|
|
;;
|
181 |
|
|
status)
|
182 |
|
|
status
|
183 |
|
|
;;
|
184 |
|
|
*)
|
185 |
|
|
echo "option '${1}' unknown"
|
186 |
|
|
usage
|
187 |
|
|
exit 1
|
188 |
|
|
;;
|
189 |
|
|
esac
|
190 |
|
|
|
191 |
|
|
# -------------
|
192 |
|
|
# Fin du script
|
193 |
|
|
# -------------
|