Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 103

Importación tarea puppet utilaula

Ver diferencias:

tareas_puppet/servidores_aula/utilaula/files/reinicio
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#Reinicia el servidor de aula si no hay nadie logeado. Tambien apaga
#los ordenadores de los host conectados(Evita que se queden fritos
#algunos tipos de clientes ligeros como los Dominion)
#No tiene en cuenta si hay logeados alumnos
if ! who | grep -q "(:0)"; then
ejecutaenhosts poweroff
/sbin/shutdown -r now
fi
tareas_puppet/servidores_aula/utilaula/files/ejecutaenhosts
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#
#Permite ejecutar el comando que se le pase como parámetro en todos los hosts, ya
#sean portatiles o clientes ligeros que esten conectados en esa clase en ese instante.
#Con el parametro -p se ejecuta en paralelo en todos los equipos(la salida resultante
#se almacena en un fichero), sin el parametro -p el comando se va ejecutando maquina a
#maquina
#
#Ricardo Salgado Cid
#IESO Galisteo
#
#26/01/11 Release incial ()
#09/02/11 Opciones mas restrictivas en los ssh para evitar esperas infinitas
if [ $# -lt 1 ]; then
echo "Permite ejecutar el comando que se le pase como parametro en todos los hosts"
echo "sean portatiles o clientes ligeros que esten conectados en esa clase en ese instante."
echo "Con el parametro -p se ejecuta en paralelo en todos los equipos"
echo "Uso: $0 [-p] comando"
exit
fi
if [ "$1" \= "-p" ] ; then
enparalelo="yes"
shift
fi
listahosts=$(avahi-browse -trpk -d local _workstation._tcp 2>/dev/null | grep 192.168.0. | grep -v '_pro\|\-pro' | cut -d";" -f7,8 | sed 's/.local//' | sort)
if [ -z "$listahosts" ]; then
echo "No se ha encontrado ninguna maquina conectada"
exit 2
else
echo "El comando se ejecutará sobre $(echo $listahosts | tr " " "\n" | wc -l ) maquina/s"
fi
for hostip in $listahosts
do
if [ -z $enparalelo ]; then
salida=/dev/stdout
else
salida=/dev/null
fi
host=$(echo $hostip | cut -d";" -f1)
ip=$(echo $hostip | cut -d";" -f2)
echo "Salida del comando en el host $host($ip):" > $salida
echo __________________________________________________________________________ > $salida
if [ -z $enparalelo ]; then
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=9 -o ServerAliveCountMax=2 -o ServerAliveInterval=15 -i /var/lib/portatil/.ssh/id_rsa root@$ip $*
else
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=9 -o ServerAliveCountMax=2 -o ServerAliveInterval=15 -i /var/lib/portatil/.ssh/id_rsa root@$ip $* > /tmp/salida_host_$host.log 2>&1 &
fi
echo __________________________________________________________________________ > $salida
echo -e "\n\n" > $salida
done
if [ -z "$enparalelo" ]; then
exit 0
else
salida="salidas_comando_$(date +%Y%m%d_%H%M).log"
echo -n "Esperando a que terminen los procesos "
for job in $(jobs -p)
do
echo -n "."
wait $job
done
echo -e "\n"
echo "Hecho!"
echo "Salidas del comando: \"$*\"" > $salida
echo $(date) >> $salida
for hostip in $listahosts
do
host=$(echo $hostip | cut -d";" -f1)
ip=$(echo $hostip | cut -d";" -f2)
echo "Salida del comando en el host $host($ip):" >> $salida
echo __________________________________________________________________________ >> $salida
cat /tmp/salida_host_${host}.log >> $salida
rm /tmp/salida_host_${host}.log
echo __________________________________________________________________________ >> $salida
done
echo "Salidas almacenadas en el fichero: $salida"
# read -n1 -p "¿Mostrar fichero? (s/N) "
# echo
# [[ $REPLY == [sSyY] ]] && less /root/$salida
#
# read -n1 -p "¿Borrar fichero? (s/N) "
# echo
# [[ $REPLY == [sSyY\n] ]] && rm $salida
fi
tareas_puppet/servidores_aula/utilaula/files/conectahost
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#
#Ricardo Salgado(IESO Galisteo)
#
#Conecta a un host (portatil o workstation) que esté conectado a la red del aula en ese momento
#toma como parametro el nombre del host(o una parte de el)
#
#Ricardo Salgado Cid
#IESO Galisteo
#
#26/01/11 Release incial ()
#09/02/11 Opciones mas restrictivas en los ssh para evitar esperas infinitas
if [ $# -ne 1 ]; then
echo "Conecta a un host (portatil o workstation) que este conectado a la red del aula en ese momento"
echo "Uso: $0 nombre_equipo"
exit
fi
hostip=$(avahi-browse -trpk -d local _workstation._tcp 2>/dev/null | grep 192.168.0. | grep -v '\-pro\|_pro' | grep $1.* | cut -d";" -f7,8 | sed 's/.local//' | sort | tail -1 )
host=$(echo $hostip | cut -d";" -f1)
ip=$(echo $hostip | cut -d";" -f2)
echo "Conectando a $host($ip)"
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=9 -o ServerAliveCountMax=2 -o ServerAliveInterval=15 -i /var/lib/portatil/.ssh/id_rsa root@$ip
tareas_puppet/servidores_aula/utilaula/files/apagado
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#Apaga el servidor de aula si no hay nadie logeado. Tambien apaga
#los ordenadores de los host conectados(Evita que se queden fritos
#algunos tipos de clientes ligeros como los Dominion)
#No tiene en cuenta si hay logeados alumnos
if ! who | grep -q "(:0)"; then
ejecutaenhosts poweroff
/sbin/shutdown -h now
fi
tareas_puppet/servidores_aula/utilaula/files/arreglosportatil
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#
#
# Ricardo Salgado(IESO Galisteo)
#
# Ejecuta los comandos contenidos en la variable "comandos" en todos los portatiles conectados al aula.
# Los comandos deben terminar con el caracter ";" a excepcion del ultimo
# Pensado solo para los portatiles, cuidado con ejecutarlo sobre los clientes ligeros
# Pasando como parametro -p al script los comandos se ejecutaran en paralelo en todos los host.
# Sin parametros se ejecutaran host a host
comandos="
/etc/init.d/puppet stop;
dpkg --configure -a --force-all;
puppetd -tv;
pkgsync;
nss_updatedb ldap;
apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold--reinstall install autofs5;
/etc/init.d/puppet start
"
if [ "$1" \= "-p" ] ; then
/sbin/ejecutaenhosts -p $comandos
else
/sbin/ejecutaenhosts $comandos
fi
tareas_puppet/servidores_aula/utilaula/files/listahosts
#!/bin/bash
##############################################################################
# utilaula is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# utilaula is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with utilala. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#
#Lista los hosts, sean portatiles o clientes ligeros que esten conectados en esa clase
#en ese instante.
#
#Ricardo Salgado Cid
#IESO Galisteo
#
#09/02/11 Release incial ()
listahosts=$(avahi-browse -trpk -d local _workstation._tcp 2>/dev/null | grep 192.168.0. | grep -v '_pro\|\-pro' | cut -d";" -f7,8 | sed 's/.local//' | sort)
if [ -z "$listahosts" ]; then
echo "No se ha encontrado ninguna maquina conectada"
exit 2
else
echo "Hay $(echo $listahosts | tr " " "\n" | wc -l ) maquina/s conectadas:"
fi
for hostip in $listahosts
do
host=$(echo $hostip | cut -d";" -f1)
ip=$(echo $hostip | cut -d";" -f2)
echo "--$host($ip)"
done
tareas_puppet/servidores_aula/utilaula/leeme.txt
utilaula
Tarea de puppet que añade comandos que hace posible conectarse facilmente
a los ordenadores(portatiles o clientes ligeros) que estan encendidos en un
determinado momento en un aula desde el ordenador del profesor. Para instalar
la tarea solo hay que descomprimir en /etc/puppet/modules del servidor nfs y
añadirla a clase-especifica. Los comandos son los siguientes:
*listahosts: devuelve una lista de las máquinas conectadas(hostname e ip).
*conectahost: abre una sesión de ssh como root en la maquina que se le indique.
(No es necesario teclear el nombre entero,basta con los primeros caracteres)
*ejecutaenhosts: ejecuta el comando que se le pase como parámetro en todos los hosts
(Con el parametro -p se ejecuta en paralelo en todos los equipos)
*arreglosportatil: ejecuta los comandos de configuracion basica de los portatiles.
(mirar dentro del script para mas detalles)
*reincio: reincia el servidor de aula si no hay nadie logeado.
*apagado: apaga el servidor de aula si no hay nadie logeado
Ricardo Salgado Cid
IESO Galisteo
Febrero 2011
tareas_puppet/servidores_aula/utilaula/changelog
16/02/11 v0.7 Corregidos permisos en la carpeta files
10/02/11 v0·6 Corregido bug(No se creaba la carpeta .ssh dentro del root de la imagen ltsp)
10/02/11 v0.5 Release incial con soporte de portatiles
tareas_puppet/servidores_aula/utilaula/manifests/init.pp
class utilaula {
file {
"/sbin/conectahost":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/conectahost";
"/sbin/listahosts":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/listahosts";
"/sbin/ejecutaenhosts":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/ejecutaenhosts";
"/sbin/arreglosportatil":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/arreglosportatil";
"/sbin/apagado":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/apagado";
"/sbin/reinicio":
owner => root, group => root, mode => 750,
source => "puppet:///utilaula/reinicio";
"/opt/ltsp/i386/root/.ssh":
owner => root, group => root, mode => 755,
ensure => directory,
before => File["/opt/ltsp/i386/root/.ssh/authorized_keys2"];
"/opt/ltsp/i386/root/.ssh/authorized_keys2":
owner => root, group => root, mode => 600,
source => "/var/lib/portatil/.ssh/id_rsa.pub",
notify => Exec[crear-imagen-utilaula];
}
exec { "crear-imagen-utilaula":
command => "/usr/sbin/ltsp-update-image --arch i386",
refreshonly => true;
}
}

Exportar a: Unified diff