Revisión 0e375d59
Añadido por Ismael Campos Suárez hace más de 4 años
- Se actualiza sinc_puppet con nuevas funcionalidades:
Se añaden nuevas funcionalidades implementadas por Esteban Navas.
Se modifica solveapterrors para que contemple más problemas con la paquetería.
Se añade al fichero de configuración la línea certificate_revocation=false para compatibilidad con servidores en versión 6 de puppet.
Se añade la funcionalidad de traer ca.pem del servidor si el servidor está en version 6 de puppet.
Se afina la función dosync
- Se elimina basura encontrada en los ficheros.
- Versión 1.4.7
ubuntu/bionic/all/linex-ubuntu-puppet/debian/changelog | ||
---|---|---|
linex-ubuntu-puppet (2.0) linex; urgency=medium
|
||
linex-ubuntu-puppet (1.4.7) linex; urgency=medium
|
||
|
||
* Changed puppet and facter dep to debian version.
|
||
* Se actualiza sinc_puppet con nuevas funcionalidades:
|
||
Se añaden nuevas funcionalidades implementadas por Esteban Navas.
|
||
Se modifica solveapterrors para que contemple más problemas con la paquetería.
|
||
Se añade al fichero de configuración la línea certificate_revocation=false para compatibilidad con servidores en versión 6 de puppet.
|
||
Se añade la funcionalidad de traer ca.pem del servidor si el servidor está en version 6 de puppet.
|
||
Se afina la función dosync
|
||
* Se elimina basura encontrada en los ficheros.
|
||
|
||
-- Rafael J. García Perdigón <rafael.garciap@juntaex.es> Mon, 13 May 2019 10:33:22 +0200
|
||
-- ismael <ismael.campos@educarex.es> Tue, 17 Nov 2020 09:47:40 +0100
|
||
|
||
linex-ubuntu-puppet (1.4.6) linex; urgency=medium
|
||
|
ubuntu/bionic/all/linex-ubuntu-puppet/debian/control | ||
---|---|---|
|
||
Package: linex-ubuntu-puppet
|
||
Architecture: all
|
||
Depends: puppet, puppet-common, pkgsync, lockfile-progs, uuid-runtime, facter
|
||
Breaks:puppet-linex, puppet-linex-common, facter-linex
|
||
Conflicts:puppet-linex, puppet-linex-common, facter-linex
|
||
Depends: puppet-linex, puppet-linex-common, pkgsync, lockfile-progs, uuid-runtime, facter-linex, curl
|
||
Description: Configuración del cliente puppet
|
||
Instalación de las dependencias del cliente de puppet,
|
||
junto con la configuración necesaria para dicho cliente
|
ubuntu/bionic/all/linex-ubuntu-puppet/debian/postinst | ||
---|---|---|
|
||
gem install xmlrpc
|
||
|
||
#[ -x /bin/systemctl ] && systemctl disable puppet.service
|
||
|
||
pidof systemd 2>&1>/dev/null
|
||
|
||
if [ $? -eq "0" ]; then
|
||
... | ... | |
/usr/sbin/sinc_puppet -r -f now
|
||
fi
|
||
|
||
|
||
|
||
#/usr/sbin/sinc_puppet &
|
||
exit 0
|
||
|
ubuntu/bionic/all/linex-ubuntu-puppet/usr/share/linex-ubuntu-puppet/sinc_puppet | ||
---|---|---|
#!/bin/bash
|
||
# Script para tratar de realizar la sincronización del cliente puppet
|
||
# Esteban M. Navas Martín
|
||
# Fecha última modificación: 22/06/2018
|
||
# Modificado por Administracionsi: 13/07/2018
|
||
# Basado en la versión de Esteban M. Navas Martín 17/09/2020
|
||
# Fecha última modificación Administracionsi (Ismael): 03/11/2020
|
||
|
||
export DEBIAN_FRONTEND=noninteractive
|
||
export VERSION=2.16
|
||
export VERSION=2.17
|
||
export PATH="${PATH:+$PATH:}/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||
|
||
SCRIPT=`basename "$0"`
|
||
... | ... | |
echo ""
|
||
}
|
||
|
||
function preparapuppetv6 {
|
||
if ! `grep "certificate_revocation=false" /usr/share/linex-ubuntu-puppet/puppet.conf >/dev/null` ; then
|
||
sed '/\[main\]/a certificate_revocation=false' -i /usr/share/linex-ubuntu-puppet/puppet.conf
|
||
fi
|
||
}
|
||
|
||
function solveapterrors {
|
||
set +e
|
||
|
||
idioma=$LC_ALL
|
||
export LC_ALL=C
|
||
|
||
# Matamos procesos detenidos
|
||
stopped_processes=$(ps auwx | awk 'NR>1 && $8 ~ "T" {print $2}')
|
||
if [ "$stopped_processes" ]; then kill -9 $stopped_processes; fi
|
||
|
||
# Matamos el proceso más antiguo de sinc_puppet, si está corriendo
|
||
if [ $(pgrep -c sinc_puppet) -gt 1 ]; then pkill -o sinc_puppet; fi
|
||
|
||
apt-get check 1>/dev/null 2>/tmp/apterrors
|
||
|
||
if [ -s /tmp/apterrors ]; then
|
||
grep "Unmet dependencies. Try using -f." /tmp/apterrors && apt-get -yf install && dpkg --configure -a && apt-get -y autoremove
|
||
grep "dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem." /tmp/apterrors && dpkg --configure -a && apt-get -yf install && apt-get -y autoremove
|
||
grep -E 'Encountered a section with no Package: header|Problem with MergeList ' /tmp/apterrors && rm -rf /var/lib/apt/lists/
|
||
if `grep "Unmet dependencies. Try using -f." /tmp/apterrors >/dev/null 2>&1`; then
|
||
apt-get -yf install && dpkg --configure -a && apt-get -y autoremove
|
||
else
|
||
if `grep "dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem." /tmp/apterrors >/dev/null 2>&1`; then
|
||
dpkg --configure -a && apt-get -yf install && apt-get -y autoremove
|
||
else
|
||
if `grep -E 'Encountered a section with no Package: header|Problem with MergeList' /tmp/apterrors >/dev/null 2>&1`; then
|
||
rm -rf /var/lib/apt/lists/
|
||
else
|
||
apt-get -yf install && dpkg --configure -a && apt-get -y autoremove && apt-get clean && apt-get autoclean
|
||
fi
|
||
fi
|
||
fi
|
||
fi
|
||
|
||
# Instalamos paquetes a medio instalar
|
||
dpkg -l|grep ^iF | awk '{print $2}' || apt-get -y install $(dpkg -l|grep ^iF | awk '{print $2}')
|
||
|
||
export LC_ALL=$idioma
|
||
}
|
||
|
||
function dosync {
|
||
if [ "$1" == "-f" ] && [ "$2" == "now" ]; then
|
||
echo "Conexión con servidor de puppet. Sincronizando puppet....." | logger -s -t $0
|
||
puppet agent --onetime --no-daemonize >/dev/null 2>&1
|
||
if [ $? -eq "0" ]; then
|
||
echo "Sistema PUPPET correcto" | logger -s -t $0
|
||
exit 0
|
||
echo "Conexión con servidor de puppet." | logger -s -t $0
|
||
echo "Sincronizando puppet..." | logger -s -t $0
|
||
|
||
versionanterior=""
|
||
|
||
salida=$(puppet agent --onetime --no-daemonize --no-usecacheonfailure -v 2>/tmp/puppeterror.log);CODIGO_SALIDA=$?
|
||
grep 'certificate verify failed' /tmp/puppeterror.log
|
||
|
||
if [ $? -eq 0 ]; then
|
||
uuid=$(/usr/bin/uuidgen -t) && sed -i "s/certname=.*/certname=$uuid/" /usr/share/linex-ubuntu-puppet/puppet.conf
|
||
rm -r /var/lib/puppet/ssl/*
|
||
salida=$(puppet agent --onetime --no-daemonize --no-usecacheonfailure -v 2>/tmp/puppeterror.log);CODIGO_SALIDA=$?
|
||
fi
|
||
|
||
if [ $CODIGO_SALIDA -eq 0 ]; then
|
||
echo $salida
|
||
version=$(echo $salida | grep -oE "configuration version '[0-9]*'" | grep -oE '[0-9]*')
|
||
|
||
until [ "$version" == "$versionanterior" ]; do
|
||
versionanterior=$version
|
||
salida=$(puppet agent --onetime --no-daemonize --no-usecacheonfailure -v 2>/tmp/puppeterror.log);CODIGO_SALIDA=$?
|
||
echo $salida
|
||
version=$(echo $salida | grep -oE "configuration version '[0-9]*'" | grep -oE '[0-9]*')
|
||
done
|
||
|
||
if [ $CODIGO_SALIDA -eq "0" ]; then
|
||
echo "Sistema PUPPET correcto." | logger -s -t $0
|
||
exit 0
|
||
fi
|
||
fi
|
||
else
|
||
echo "Conexión con servidor de puppet." | logger -s -t $0
|
||
echo "Esperando un tiempo máximo de $SPLAYLIMIT para sincronizar puppet....." | logger -s -t $0
|
||
puppet agent --onetime --no-daemonize --splay --splaylimit $SPLAYLIMIT >/dev/null 2>&1
|
||
if [ $? -eq "0" ]; then
|
||
echo "Sistema PUPPET correcto" | logger -s -t $0
|
||
exit 0
|
||
fi
|
||
|
||
|
||
versionanterior=""
|
||
|
||
salida=$(puppet agent --onetime --no-daemonize --splay --splaylimit $SPLAYLIMIT --no-usecacheonfailure -v 2>/tmp/puppeterror.log);CODIGO_SALIDA=$?
|
||
|
||
if [ $CODIGO_SALIDA -eq 0 ]; then
|
||
echo $salida
|
||
version=$(echo $salida | grep -oE "configuration version '[0-9]*'" | grep -oE '[0-9]*')
|
||
|
||
until [ "$version" == "$versionanterior" ]; do
|
||
versionanterior=$version
|
||
salida=$(puppet agent --onetime --no-daemonize --no-usecacheonfailure -v 2>/tmp/puppeterror.log);CODIGO_SALIDA=$?
|
||
echo $salida
|
||
version=$(echo $salida | grep -oE "configuration version '[0-9]*'" | grep -oE '[0-9]*')
|
||
done
|
||
|
||
if [ $CODIGO_SALIDA -eq "0" ]; then
|
||
echo "Sistema PUPPET correcto" | logger -s -t $0
|
||
exit 0
|
||
fi
|
||
fi
|
||
fi
|
||
}
|
||
|
||
... | ... | |
stopped_processes=$(ps auwx | awk 'NR>1 && $8 ~ "T" {print $2}')
|
||
if [ "$stopped_processes" ]; then kill -9 $stopped_processes; fi
|
||
|
||
#Definimos fichero de lock
|
||
lockfile=/tmp/sincpuppet
|
||
|
||
# Matamos todos los procesos de sinc_puppet excepto el último que se haya
|
||
sinc_puppet_processes=$(pgrep -c sinc_puppet)
|
||
if [ "$sinc_puppet_processes" -gt "1" ]; then
|
||
kill -9 $(ps -ef|grep "sinc_puppet"|grep -v grep| awk '{print $2}' |grep -v $$) 2>/dev/null
|
||
#Si matamos con kill -9 todos los procesos sinc_puppet debemos borrar fichero de lock porque sino el proceso actual muere.
|
||
lockfile-remove $lockfile
|
||
fi
|
||
# Definimos el fichero de lock
|
||
lockfile=/var/lock/$(basename $0)
|
||
lockfile-create $lockfile || exit 2
|
||
lockfile-touch $lockfile &
|
||
BADGER="$!"
|
||
|
||
# Nos aseguramos de que sólo exista una instancia de sinc_puppet corriendo
|
||
# Eliminar fichero de bloqueo al salir
|
||
trap "lockfile-remove $lockfile; exit" INT TERM EXIT
|
||
|
||
lockfile-check $lockfile
|
||
if [ $? -eq 0 ] ; then
|
||
# Si existe el fichero de bloqueo
|
||
# echo >&2 "lock not acquired, giving up: $lockfile"
|
||
exit 1
|
||
else
|
||
# Si no existe el fichero de bloqueo
|
||
lockfile-create $lockfile # Creamos el fichero de bloqueo
|
||
# echo "lock acquired: $lockfile"
|
||
fi
|
||
trap "kill "${BADGER}" 2>/dev/null || true; lockfile-remove $lockfile; exit" QUIT INT TERM EXIT
|
||
|
||
LOCALES="es_ES.UTF-8"
|
||
|
||
... | ... | |
fi
|
||
|
||
solveapterrors
|
||
preparapuppetv6
|
||
|
||
echo
|
||
if [ $dife -lt 0 ]; then
|
||
... | ... | |
if [ "$renew" == "-r" ]; then
|
||
uuid=$(/usr/bin/uuidgen -t) && sed -i "s/certname=.*/certname=$uuid/" /usr/share/linex-ubuntu-puppet/puppet.conf
|
||
find /var/lib/puppet/ssl/ -type f -name *.pem -not -name ca.pem -not -name crl.pem -exec rm -f {} \;
|
||
dosync $force $now
|
||
dosync -f now
|
||
fi
|
||
|
||
|
||
... | ... | |
|
||
test -f /var/lib/puppet/ssl/certs/$uuid.pem
|
||
if [ $? -eq "0" ]; then
|
||
|
||
dosync $force $now
|
||
|
||
#Si existe el certificado uuid y no se consigue sincronizar. Se sincroniza la hora, se genera un nuevo uuid y se borran todos los certificados dentro de /var/lib/puppet/ssl
|
||
... | ... | |
|
||
dosync $force $now
|
||
fi
|
||
|
||
#Si falla puede ser porque la versión puppet del servidor sea la 6.
|
||
#Hay un problema al traer ca.pem del servidor en versiones del cliente puppet v3.x
|
||
curl -k https://$(puppet agent --configprint server):8140/puppet-ca/v1/certificate/ca > /tmp/ca.pem 2>/dev/null
|
||
if `grep "BEGIN CERTIFICATE" /tmp/ca.pem >/dev/null`; then
|
||
if ! `diff /tmp/ca.pem $(puppet agent --configprint localcacert) >/dev/null` ; then
|
||
cp -f /tmp/ca.pem $(puppet agent --configprint localcacert)
|
||
dosync $force $now
|
||
fi
|
||
fi
|
||
|
||
echo "NO SE HA PODIDO REALIZAR SINCRONIZACIÓN CON PUPPET" | logger -s -t $0
|
ubuntu/bionic/all/linex-ubuntu-puppet/usr/share/linex-ubuntu-puppet/sincpuppet.service | ||
---|---|---|
|
||
[Service]
|
||
Type=oneshot
|
||
EnvironmentFile=-/usr/share/linex-ubuntu-puppet/sincpuppet.default
|
||
TimeoutStartSec=120
|
||
RemainAfterExit=yes
|
||
ExecStart=/usr/sbin/sinc_puppet
|
||
ExecStart=/usr/sbin/sinc_puppet -f now
|
||
|
||
[Install]
|
||
WantedBy=network-online.target
|
Exportar a: Unified diff