| 1 |
d2a8c3fd
|
Marc NICOLAS
|
#! /bin/bash
|
| 2 |
|
|
|
| 3 |
|
|
# ---------
|
| 4 |
|
|
# Fonctions
|
| 5 |
|
|
# ---------
|
| 6 |
|
|
usage() {
|
| 7 |
|
|
echo "USAGE"
|
| 8 |
|
|
echo " ${prog} <start|stop|restart|status>"
|
| 9 |
|
|
echo " "
|
| 10 |
|
|
}
|
| 11 |
|
|
|
| 12 |
|
|
start() {
|
| 13 |
|
|
if [ -f ${SITOOLS_PID} ];then
|
| 14 |
|
|
status
|
| 15 |
|
|
else
|
| 16 |
|
|
if [ "${SITOOLS}" != "" ];then
|
| 17 |
|
|
local SITOOLS_START="${START_DIR}/${SITOOLS}"
|
| 18 |
|
|
[ ! -x ${SITOOLS_START} ] && echo "Impossible de lancer ${SITOOLS_START}" && exit 1
|
| 19 |
|
|
echo -e "Demarrage de ${SITOOLS_START}...\c "
|
| 20 |
|
|
nohup ${SITOOLS_START} 2>&1 >> ${LOG} &
|
| 21 |
|
|
if [ ${?} -ne 0 ];then
|
| 22 |
|
|
echo "[ERREUR]" | tee -a ${LOG}
|
| 23 |
|
|
echo "Un probleme semble empecher ${SITOOLS_START} de demarrer..." | tee -a ${LOG}
|
| 24 |
|
|
echo "Veuillez controler le script avant de relancer." | tee -a ${LOG}
|
| 25 |
|
|
else
|
| 26 |
|
|
echo "[OK]" | tee -a ${LOG}
|
| 27 |
|
|
fi
|
| 28 |
|
|
fi
|
| 29 |
|
|
fi
|
| 30 |
|
|
}
|
| 31 |
|
|
|
| 32 |
|
|
stop() {
|
| 33 |
|
|
echo -e "Arret de sitools...\c "
|
| 34 |
|
|
if [ ! -f ${SITOOLS_PID} ];then
|
| 35 |
|
|
echo "[ERREUR]"
|
| 36 |
|
|
echo "Le fichier ${SITOOLS_PID} est introuvable..."
|
| 37 |
|
|
isRunning=`ps -ef | grep -v 'grep' | grep 'fr.cnes.sitools.server.Starter' | awk '{print $2}'`
|
| 38 |
|
|
if [ "${isRunning}" != "" -a "`echo ${isRunning} | tr -d [:digit:]`" = "" ];then
|
| 39 |
|
|
echo " "
|
| 40 |
|
|
echo "Tentative d'arret..."
|
| 41 |
|
|
kill ${isRunning}
|
| 42 |
|
|
else
|
| 43 |
|
|
echo "sitools semble etre arrete..."
|
| 44 |
|
|
fi
|
| 45 |
|
|
else
|
| 46 |
|
|
kill `cat ${SITOOLS_PID}`
|
| 47 |
|
|
if [ ${?} -eq 0 ];then
|
| 48 |
|
|
echo "[OK]"
|
| 49 |
|
|
\rm ${SITOOLS_PID}
|
| 50 |
|
|
|
| 51 |
|
|
else
|
| 52 |
|
|
echo "[ERREUR]"
|
| 53 |
|
|
fi
|
| 54 |
|
|
fi
|
| 55 |
|
|
}
|
| 56 |
|
|
|
| 57 |
|
|
status() {
|
| 58 |
|
|
echo -e "Etat de sitools..."
|
| 59 |
|
|
if [ -f ${SITOOLS_PID} ];then
|
| 60 |
|
|
local pid=`cat ${SITOOLS_PID}`
|
| 61 |
|
|
if [ "${pid}" != "" ];then
|
| 62 |
|
|
isRunning=`ps -ef |grep "${pid}" | grep -v 'grep' | grep 'fr.cnes.sitools.server.Starter'`
|
| 63 |
|
|
if [ "${isRunning}" != "" ];then
|
| 64 |
|
|
echo "sitools est lance (pid: ${pid})"
|
| 65 |
|
|
else
|
| 66 |
|
|
echo "Etrange... Le fichier PID est present (${pid}) mais le processus semble absent."
|
| 67 |
|
|
fi
|
| 68 |
|
|
else
|
| 69 |
|
|
echo "le fichier ${SITOOLS_PID} est vide! Une erreur a du se produire lors du lancement..."
|
| 70 |
|
|
fi
|
| 71 |
|
|
else
|
| 72 |
|
|
isRunning=`ps -ef |grep 'java' | grep -v 'grep' | grep 'fr.cnes.sitools.server.Starter'`
|
| 73 |
|
|
if [ "${isRunning}" != "" ];then
|
| 74 |
|
|
echo "Etrange... Le fichier PID est absent mais le processus semble fonctionner en memoire."
|
| 75 |
|
|
else
|
| 76 |
|
|
echo "sitools est arrete."
|
| 77 |
|
|
fi
|
| 78 |
|
|
fi
|
| 79 |
|
|
}
|
| 80 |
|
|
|
| 81 |
|
|
# ---------
|
| 82 |
|
|
# Principal
|
| 83 |
|
|
# ---------
|
| 84 |
|
|
prog=`basename ${0}`
|
| 85 |
|
|
myDir=`dirname ${0}`
|
| 86 |
|
|
myPid=${$}
|
| 87 |
|
|
|
| 88 |
|
|
# Parametrage de l'environnement
|
| 89 |
|
|
[ -f ${HOME}/.bash_profile ] && . ${HOME}/.bash_profile
|
| 90 |
|
|
|
| 91 |
|
|
LOG_DIR="${HOME}/LOG"
|
| 92 |
|
|
[ ! -d ${LOG_DIR} ] && mkdir -p ${LOG_DIR}
|
| 93 |
|
|
|
| 94 |
|
|
LOG="${LOG_DIR}/sitools.log"
|
| 95 |
|
|
|
| 96 |
|
|
[ "${1}" = "" ] && usage && exit 0
|
| 97 |
|
|
|
| 98 |
|
|
START_DIR="${HOME}/sitools-distribution/workspace/prototype"
|
| 99 |
|
|
SITOOLS="startSitools.sh"
|
| 100 |
|
|
SITOOLS_START="${START_DIR}/${SITOOLS}"
|
| 101 |
|
|
SITOOLS_PID="${LOG_DIR}/${SITOOLS}.run"
|
| 102 |
|
|
|
| 103 |
|
|
if [ ! -x ${SITOOLS_START} ];then
|
| 104 |
|
|
echo "--- ERREUR ---" | tee -a ${LOG}
|
| 105 |
|
|
echo "${SITOOLS_START} introuvable ou non executable. Abandon." | tee -a ${LOG}
|
| 106 |
|
|
echo "--- ERREUR ---" | tee -a ${LOG}
|
| 107 |
|
|
exit 1
|
| 108 |
|
|
fi
|
| 109 |
|
|
|
| 110 |
|
|
|
| 111 |
|
|
|
| 112 |
|
|
case ${1} in
|
| 113 |
|
|
start)
|
| 114 |
|
|
start
|
| 115 |
|
|
;;
|
| 116 |
|
|
stop)
|
| 117 |
|
|
stop
|
| 118 |
|
|
;;
|
| 119 |
|
|
restart)
|
| 120 |
|
|
stop
|
| 121 |
|
|
start
|
| 122 |
|
|
;;
|
| 123 |
|
|
status)
|
| 124 |
|
|
status
|
| 125 |
|
|
;;
|
| 126 |
|
|
*)
|
| 127 |
|
|
echo "option '${1}' inconnue"
|
| 128 |
|
|
usage
|
| 129 |
|
|
exit 1
|
| 130 |
|
|
;;
|
| 131 |
|
|
esac
|
| 132 |
|
|
|
| 133 |
|
|
# -------------
|
| 134 |
|
|
# Fin du script
|
| 135 |
|
|
# -------------
|