source: server/bin/ogagentqueue.cron @ 399af4d

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 399af4d was 0645906, checked in by ramon <ramongomez@…>, 8 years ago

#708: Nuevo script de ejecución cronológica para enviar a los OGAgent las operaciones pendientes; preparar su instalación en instalación y actualización.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5485 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 3.1 KB
Line 
1#!/bin/bash
2
3#/**
4#@file    ogagentqueue.cron
5#@brief   Cronfile to send pending operations to OGAgent.
6#warning  This file must be executed under system Cron every minute.
7#@version 1.1.0 - Initial version.
8#@date    2017-10-26
9#@author  Ramón M. Gómez - Univ. Sevilla
10#*/ ##
11
12
13# Variables.
14PROG=$(basename "$0")
15OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
16SERVERCONF=$OPENGNSYS/etc/ogAdmServer.cfg
17LOGFILE=$OPENGNSYS/log/remotepc.log
18MYCNF=/tmp/.my.cnf.$$
19
20# Basic error control
21if [ ! -r "$SERVERCONF" ]; then
22        echo "$PROG: Cannot access to configuration file." >&2
23        exit 2
24fi
25if ! touch "$LOGFILE"; then
26        echo "$PROG: Cannot write to the log file." >&2
27        exit 2
28fi
29
30# Fetching database access data.
31source "$SERVERCONF"
32# Composing connection credentils file.
33touch $MYCNF
34chmod 600 $MYCNF
35cat << EOT > $MYCNF
36[client]
37user=$USUARIO
38password=$PASSWORD
39EOT
40# Trap to delete temporal file if process ends.
41trap "rm -f $MYCNF" 0 1 2 3 6 9 15
42# Reading pending operations.
43mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse "
44SELECT ogagent_queue.id, ogagent_queue.exectime, ogagent_queue.operation,
45       ordenadores.idordenador, ordenadores.ip, ordenadores.agentkey
46  FROM ogagent_queue
47  JOIN ordenadores ON ogagent_queue.clientid=ordenadores.idordenador
48 WHERE exectime < NOW()
49 ORDER BY exectime;" | \
50        while read -r OPERID DATE TIME OPER CLNTID AGNTIP AGNTKEY; do
51                # Preparing operation data.
52                # TODO: preparing messages translation.
53                case "$OPER" in
54                        popup-10)       # Message:  min. before power off.
55                                AGNTURL=https://$AGNTIP:8000/opengnsys/popup
56                                DATA='{"title":"Apagado en 10 min.","message","Fin del tiempo de acceso remoto.\nEl ordenador se apagará automáticamente dentro de 10 minutos."}'
57                                ;;
58                        popup-5)        # Message: 5 min. before power off.
59                                AGNTURL=https://$AGNTIP:8000/opengnsys/popup
60                                DATA='{"title":"Apagado en 5 min.","message","El ordenador se apagará automáticamente dentro de 5 minutos.\nATENCIÓN: Este es el último aviso."}'
61                                ;;
62                        poweroff)       # Power off client.
63                                AGNTURL=https://$AGNTIP:8000/opengnsys/poweroff
64                                DATA=
65                                ;;
66                        *)              # Unknown operation.
67                                AGNTURL=
68                                ;;
69                esac
70                # Sending operation to OGAgent.
71                if [ -n "$AGNTURL" ]; then
72                        CODE=$(curl -ksm 1 -w "%{http_code}" -o /dev/null -H "'Authorization: $AGNTKEY'" ${DATA:+"-d '$DATA'"} "$AGNTURL")
73                         case "$CODE" in
74                                000)    # Client does not respond may be halted).
75                                        ;;
76                                200)    # Operation sended.
77                                        echo "$(date +"%FT%T%z"): $PROG: Operation sended to OGAgent: client=$AGNTIP, oper=$OPER, exectime=\"$DATE $TIME\"" >> $LOGFILE ;;
78                                *)      # Operation error.
79                                        echo "$(date +"%FT%T%z"): $PROG: Operation error: client=$AGNTIP, oper=$OPER, code=$CODE" >> $LOGFILE ;;
80                        esac
81                else    # Unknown operation.
82                        echo "$(date +"%FT%T%z"): $PROG: Unknown operation: client=$AGNTIP, oper=$OPER" >> $LOGFILE
83                fi
84                # Deleting operation from database.
85                mysql --defaults-extra-file="$MYCNF" -D "$CATALOG" -Nse "
86DELETE FROM ogagent_queue
87 WHERE id='$OPERID';
88UPDATE remotepc
89   SET reserved = NOW() - INTERVAL 1 SECOND, urllogin=NULL, urllogout=NULL
90 WHERE id = '$CNLTID';
91DELETE FROM acciones
92 WHERE idordenador = '$CLNTID'
93   AND descriaccion = 'RemotePC Session';"
94        done
Note: See TracBrowser for help on using the repository browser.