forked from carloscm/cassandra-commitlog-extract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-csv-single-postgre.sh
executable file
·52 lines (44 loc) · 2.02 KB
/
read-csv-single-postgre.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
source `dirname $0`/common.sh
tipo=reader-csv-single-postgre
csvdir=/etl/postgresql/
pidfile=/var/run/etlagentPostgre.pid
logfile=/var/log/etl/read-csv-single-postgre.log
javapath=/usr/java/jre1.7.0_21/bin/java
statusfile=/cassandra/etl-agent/agent/status/statusPostgre.conf
# param 1: absolute path to the conf folder
# param 2: name of the exporter to run
status=`md5sum $logfile`
echo "El md5sum del log es $status. Me espero 30 segundos."
sleep 30
status2=`md5sum $logfile`
echo "Ahora el md5sum del log es $status2"
[ "$status" != "$status2" ] && echo "Como son diferentes, hay un proceso en marcha que escribe en el log, mejor no me meto. Saliendo" && exit 0
while [ -f $pidfile ];do
echo "Nadie escribe en el log y hay un pidfile... Voy a ver si el proceso esta en marcha"
PID=`cat $pidfile`
if [ -e /proc/$PID -a /proc/$PID/exe -ef $javapath ]; then
echo "Esta en marcha. Seguramente esta colgado, asi que lo mato."
kill `cat $pidfile`
sleep 10
if [ -e /proc/$PID -a /proc/$PID/exe -ef $javapath ]; then
echo "Aun sigue en marcha, esta muy colgado... le meto un kill -9"
kill -9 `cat $pidfile`
fi
now=`date`
echo "\"0\",\"$now\"" > $statusfile
else
echo "No esta en marcha. Borro el pidfile."
fi
rm -f $pidfile
echo "Como habia un pidfile, he hecho gestiones para arreglar el problema pero no proceso csv's. Si todo ha ido bien, la siguiente ejecucion los procesara a toda pastilla"
exit 0
done
while [ -n "`ls $csvdir/*csv`" ];do
sleep 1
[ "`cat $statusfile|cut -d'\"' -f2`" == "2" ] && echo "Ha habido un error segun el statusfile" && exit 1
[ "`cat $statusfile|cut -d'\"' -f2`" == "1" ] && echo "Segun el fichero de control de java, hay otro proceso corriendo, pero yo no lo he visto... Algo pasa, yo salgo por si acaso" && exit 0
csvnumber=`ls $csvdir/*csv|wc -l`
echo "Number of csv: $csvnumber"
java -server -Xmx2048m -cp $CLASSPATH -Dlog4j.configuration=file:$AGENT_HOME/log4j/read-csv-single-postgre.properties agent.Main $AGENT_HOME/conf $tipo
done