From 06459061d3cff16b3ad4843e388d91c11d87b7d0 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 26 Oct 2017 11:30:11 +0000 Subject: [PATCH] =?UTF-8?q?#708:=20Nuevo=20script=20de=20ejecuci=C3=B3n=20?= =?UTF-8?q?cronol=C3=B3gica=20para=20enviar=20a=20los=20OGAgent=20las=20op?= =?UTF-8?q?eraciones=20pendientes;=20preparar=20su=20instalaci=C3=B3n=20en?= =?UTF-8?q?=20instalaci=C3=B3n=20y=20actualizaci=C3=B3n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://opengnsys.es/svn/branches/version1.1@5485 a21b9725-9963-47de-94b9-378ad31fedc9 --- installer/opengnsys_installer.sh | 7 ++- installer/opengnsys_update.sh | 7 ++- server/bin/ogagentqueue.cron | 94 ++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 6 deletions(-) create mode 100755 server/bin/ogagentqueue.cron diff --git a/installer/opengnsys_installer.sh b/installer/opengnsys_installer.sh index 6574bf5d..14ad5d32 100755 --- a/installer/opengnsys_installer.sh +++ b/installer/opengnsys_installer.sh @@ -1088,9 +1088,9 @@ function installWebFiles() # Cambiar permisos para ficheros especiales. chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/images/{fotos,iconos} chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/tmp/ - # Fichero de logs del agente OGAgent. - touch $INSTALL_TARGET/log/ogagent.log - chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/log/ogagent.log + # Ficheros de log de la API REST. + touch $INSTALL_TARGET/log/{ogagent,remotepc,rest}.log + chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/log/{ogagent,remotepc,rest}.log echoAndLog "${FUNCNAME}(): Web files installed successfully." } @@ -1467,6 +1467,7 @@ function openGnsysConfigure() echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker echo "* * * * * root [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete + echo "* * * * * root [ -x $INSTALL_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue echoAndLog "${FUNCNAME}(): Creating logrotate configuration file." sed -e "s/OPENGNSYSDIR/${INSTALL_TARGET//\//\\/}/g" \ diff --git a/installer/opengnsys_update.sh b/installer/opengnsys_update.sh index 5edee421..262dedfe 100755 --- a/installer/opengnsys_update.sh +++ b/installer/opengnsys_update.sh @@ -591,9 +591,9 @@ function updateWebFiles() done cp -a $COMPATDIR/imagenes.device.php $COMPATDIR/imagenes.device4.php - # Fichero de logs del agente OGAgent. - touch $INSTALL_TARGET/log/ogagent.log - chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/log/ogagent.log + # Fichero de log de la API REST. + touch $INSTALL_TARGET/log/{ogagent,rest,remotepc}.log + chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/{log/ogagent,rest,remotepc}.log echoAndLog "${FUNCNAME}(): Web files updated successfully." } @@ -824,6 +824,7 @@ function updateServerFiles() [ ! -f /etc/cron.d/torrentcreator ] && echo "* * * * * root [ -x $INSTALL_TARGET/bin/torrent-creator ] && $INSTALL_TARGET/bin/torrent-creator" > /etc/cron.d/torrentcreator [ ! -f /etc/cron.d/torrenttracker ] && echo "5 * * * * root [ -x $INSTALL_TARGET/bin/torrent-tracker ] && $INSTALL_TARGET/bin/torrent-tracker" > /etc/cron.d/torrenttracker [ ! -f /etc/cron.d/imagedelete ] && echo "* * * * * root [ -x $INSTALL_TARGET/bin/deletepreimage ] && $INSTALL_TARGET/bin/deletepreimage" > /etc/cron.d/imagedelete + [ ! -f /etc/cron.d/ogagentqueue ] && echo "* * * * * root [ -x $INSTALL_TARGET/bin/ogagentqueue.cron ] && $INSTALL_TARGET/bin/ogagentqueue.cron" > /etc/cron.d/ogagentqueue echoAndLog "${FUNCNAME}(): server files updated successfully." } diff --git a/server/bin/ogagentqueue.cron b/server/bin/ogagentqueue.cron new file mode 100755 index 00000000..b86dac1f --- /dev/null +++ b/server/bin/ogagentqueue.cron @@ -0,0 +1,94 @@ +#!/bin/bash + +#/** +#@file ogagentqueue.cron +#@brief Cronfile to send pending operations to OGAgent. +#warning This file must be executed under system Cron every minute. +#@version 1.1.0 - Initial version. +#@date 2017-10-26 +#@author Ramón M. Gómez - Univ. Sevilla +#*/ ## + + +# Variables. +PROG=$(basename "$0") +OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} +SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg +LOGFILE=$OPENGNSYS/log/remotepc.log +MYCNF=/tmp/.my.cnf.$$ + +# Basic error control +if [ ! -r "$SERVERCONF" ]; then + echo "$PROG: Cannot access to configuration file." >&2 + exit 2 +fi +if ! touch "$LOGFILE"; then + echo "$PROG: Cannot write to the log file." >&2 + exit 2 +fi + +# Fetching database access data. +source "$SERVERCONF" +# Composing connection credentils file. +touch $MYCNF +chmod 600 $MYCNF +cat << EOT > $MYCNF +[client] +user=$USUARIO +password=$PASSWORD +EOT +# Trap to delete temporal file if process ends. +trap "rm -f $MYCNF" 0 1 2 3 6 9 15 +# Reading pending operations. +mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse " +SELECT ogagent_queue.id, ogagent_queue.exectime, ogagent_queue.operation, + ordenadores.idordenador, ordenadores.ip, ordenadores.agentkey + FROM ogagent_queue + JOIN ordenadores ON ogagent_queue.clientid=ordenadores.idordenador + WHERE exectime < NOW() + ORDER BY exectime;" | \ + while read -r OPERID DATE TIME OPER CLNTID AGNTIP AGNTKEY; do + # Preparing operation data. + # TODO: preparing messages translation. + case "$OPER" in + popup-10) # Message: min. before power off. + AGNTURL=https://$AGNTIP:8000/opengnsys/popup + DATA='{"title":"Apagado en 10 min.","message","Fin del tiempo de acceso remoto.\nEl ordenador se apagará automáticamente dentro de 10 minutos."}' + ;; + popup-5) # Message: 5 min. before power off. + AGNTURL=https://$AGNTIP:8000/opengnsys/popup + DATA='{"title":"Apagado en 5 min.","message","El ordenador se apagará automáticamente dentro de 5 minutos.\nATENCIÓN: Este es el último aviso."}' + ;; + poweroff) # Power off client. + AGNTURL=https://$AGNTIP:8000/opengnsys/poweroff + DATA= + ;; + *) # Unknown operation. + AGNTURL= + ;; + esac + # Sending operation to OGAgent. + if [ -n "$AGNTURL" ]; then + CODE=$(curl -ksm 1 -w "%{http_code}" -o /dev/null -H "'Authorization: $AGNTKEY'" ${DATA:+"-d '$DATA'"} "$AGNTURL") + case "$CODE" in + 000) # Client does not respond may be halted). + ;; + 200) # Operation sended. + echo "$(date +"%FT%T%z"): $PROG: Operation sended to OGAgent: client=$AGNTIP, oper=$OPER, exectime=\"$DATE $TIME\"" >> $LOGFILE ;; + *) # Operation error. + echo "$(date +"%FT%T%z"): $PROG: Operation error: client=$AGNTIP, oper=$OPER, code=$CODE" >> $LOGFILE ;; + esac + else # Unknown operation. + echo "$(date +"%FT%T%z"): $PROG: Unknown operation: client=$AGNTIP, oper=$OPER" >> $LOGFILE + fi + # Deleting operation from database. + mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse " +DELETE FROM ogagent_queue + WHERE id='$OPERID'; +UPDATE remotepc + SET reserved = NOW() - INTERVAL 1 SECOND, urllogin=NULL, urllogout=NULL + WHERE id = '$CNLTID'; +DELETE FROM acciones + WHERE idordenador = '$CLNTID' + AND descriaccion = 'RemotePC Session';" + done