Open numeroteca opened 7 years ago
El streaming puede dar errores por muchos motivos o pararse. Por ese motivo aconsejo lanzarlo desde una shell que lo rearranque si se para. Algo así:
#!/bin/bash
# shell script para llamar indefinidamente al streaming api y que espere 10 segundos despues de una caída
if [ $# -ne 5 ]
then
echo "uso: streaming_persistente script + parametros"
exit 1
fi
while true
do
echo ejecuto comando $1 $2 $3 $4 $5
$1 $2 $3 $4 $5
sleep 10
done
El comando se debe arrancar en background poniendole al final un &
También aconsejo poner en un shell script todos los comandos que arrancan los streamings e invocarlo desde el fichero /etc/rc.local. de esta manera al reiniciarse un servidor, se rearrancan todos los scripts
No me queda claro cómo sería el script y desde dónde ejecutarlo ¿me puedes poner un ejemplo real? ¡Gracias!
¿Sabemos por qué falla tanto el script del streaming?
Si el script que arranca indefinidamente un streaming se llamara streaming_persistente se invocaría así:
streaming_persistente tweet_streaming.py root experiment app_keys user_keys --words words.txt &
Cerciórate que solo hay un usuario por streaming. Aún así, los fallos de comunicaciones son intermitentes y dependen del estado de la infraestructura de Twitter o de la red dónde se encuentra el servidor, Ten en cuenta que es un socket está funcionando indefinidamente y expuesto a cualquier incidencia de la red. Por ejemplo en el streamning de bankia que tengo en la uc3m el día 14 de noviembre hubo bastantes cortes a las 11:20 y otro a las 19, sin embargo del 15 hasta hoy solo hay un corte a las 7:00 am, un corte propagado para resetear los streaming (reset preventivo)
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:25:36.215960
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:25:51.283075
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:26:11.357068
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:26:31.432870
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:26:51.510102
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:27:06.578062
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:27:26.655750
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:27:46.731146
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:28:06.800756
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:28:26.874860
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:28:41.942212
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:29:02.019883
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:29:22.097112
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:29:42.176392
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:29:57.243191
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:30:17.317187
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:30:37.388233
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:30:57.468139
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:31:17.542420
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:31:37.613097
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 11:31:57.689067
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-14 19:13:42.705435
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-15 07:00:11.108696
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-16 07:00:11.899815
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-17 07:00:11.480383
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-18 07:00:11.442825
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-19 07:00:11.653182
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-20 07:00:12.044749
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-21 07:00:11.555322
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-22 07:00:11.567470
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-23 07:00:11.167658
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-11-24 07:00:11.184399
Gracias por la explicación. Vamos a ello:
He creado el archivo streaming_persistente
en el directorio /scripts/
. Le he otorgado permisos de ejecución.
Luego desde /store/datos_rita/
he lanzado este script:
streaming_persistente tweet_streaming.py root rita app_keys user_keys --words words.txt &
No me funciona.
También he lanzado desde /store/datos_rita/
el script de bash (que previamente he copiado a este directorio). He usado el script que uso siempre de tweet_streaming
pero lo he precedido de streaming_persistente
:
./streaming_persistente tweet_streaming.py $HOME rita my_app.key numeroteca.key --words words.txt &
Tampoco me funciona.
¿sugerencias?
Debiera funcionar
./streaming_persistente tweet_streaming.py $HOME rita my_app.key numeroteca.key --words words.txt &
lo miro
sorry el scripts es
hay 7 parámetros
El script debe ser así
#!/bin/bash
# shell script para llamar indefinidamente al streaming api y que espere 10 segundos despues de una caída
if [ $# -ne 7 ]
then
echo "uso: streaming_persistente script + parametros"
exit 1
fi
while true
do
echo ejecuto comando $1 $2 $3 $4 $5 $6 $7
$1 $2 $3 $4 $5 $6 $7
sleep 10
done
pero me está dando el error 404
Lo probé y funciona bien.
Inténtalo tu a ver si te va bien
Como los streaming se puede quedar colgados con el tiempo, por esto es muy sano hacer un reset preventivo poniendo esta línea en el crontab (crontab -e)
Te lo pongo en modo imagen porque el wiki me quita comillas
Esta línea mata todos los streamings arrancados a la 7 de la mañana. Como los streaming se arrancan con el script persiatente tras 10 segundos se vuelven a rearracar.
Ya me he instalado el comando en crontab -e.
Tras ejecuar:
./streaming_persistente tweet_streaming.py $HOME tarjetasblack my_app.key numeroteca.key --words words.txt &
Y luego:
ps -e -o pid,args |grep streaming
Me salen estos dos streaming corriendo ¿es correcto?
11103 /bin/bash ./streaming_persistente tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt 11104 /usr/bin/python /home/numeroteca/t-hoarder/scripts/tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt 11163 grep --color=auto streaming
Perfecto, eso es lo que debe salir.
Con el reset preventivo se mata el proceso
1104 /usr/bin/python /home/numeroteca/t-hoarder/scripts/tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt
Que se rearranca 10 segundos después con el proceso
11103 /bin/bash ./streaming_persistente tweet_streaming.py /home/numeroteca tarjetasblack my_app.key numeroteca.key --words words.txt
Pues no sé qué pasa. Las últimas veces que he vuelto a entrar el server o bien los dos procesos estaban caídos o sólo se mantenía uno de ellos (streaming_persistente). En cualquiera de los casso se había parado de recopilar datos. ¿qué puede ser?
el log tiene estos rearranques. Pondré más información en el log para saber por qué se cae el socket
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt starting at 2016-12-08 01:13:48.687637
---------------->An error has occured! Status code = 406 at 2016-12-08 01:13:49.392530
---------------->An error has occured! Status code = 406 at 2016-12-08 01:13:55.063650
---------------->An error has occured! Status code = 406 at 2016-12-08 01:14:05.704151
---------------->An error has occured! Status code = 406 at 2016-12-08 01:14:26.314102
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-08 01:15:27.892429
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-08 01:16:41.741914
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-08 01:45:48.733464
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-08 01:49:49.091174
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-08 02:06:17.346383
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-09 02:41:21.653604
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-09 02:42:17.780764
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-09 12:51:45.435111
====================> file /home/numeroteca/t-hoarder/store/tarjetasblack_0.txt remaining at 2016-12-09 20:33:38.021138
Debe ser sel servidor de la UOC porque en streaming que tengo en la uc3m de bankia solo se ha retesado con el reset preventivo
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-01 07:00:11.207600
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-02 07:00:11.848081
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-03 07:00:11.323082
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-04 07:00:11.590623
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-05 07:00:11.173577
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-06 07:00:11.590224
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-07 07:00:11.382770
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-08 07:00:12.069793
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-09 07:00:11.530298
====================> file /home/mcongosto/experimentos/tweet_store/streaming_bankia_18.txt remaining at 2016-12-10 07:00:11.751828
A veces se me interrumpe el script, pero no sé por qué razón.
@congosto ¿te ha pasado antes?
Me ha dado este error: