Python script who generates threads

5 01 2018

#!/usr/bin/env python3
import time
from threading import Thread
num_threads = 100
sleep_secs= 60
def create_thread(i):
print "Sleeping "+ str(sleep_secs) +" secs - Thread %d \n" % i
for i in range(num_threads):
t = Thread(target=create_thread, args=(i,))
print "End"

View threads in top pressing “H”
View threads in ps with “-T”


Install VMware Horizon Client in Debian 8 Jessie

24 02 2017

Download the linux client from the VMware website:

The downloaded file is a bash script, execute it from a privileged user:

# bash VMware-Horizon-Client-4.3.0-4710754.x64.bundle

Install dependencies:

# apt-get install libudev-dev libffi-dev libglibmm-2.4-dev

Before finish the install, click into the “Scan” button. If is missing and you have only (usually in a modern Debian), create a symlink for bypass:

cd /usr/lib/x86_64-linux-gnu && ln -s

Probably, if you execute now the client, it doesn’t start because the following:

$ vmware-view
/usr/lib/vmware/view/bin/vmware-view: error while loading shared libraries: cannot open shared object file: No such file or directory

Solve that creating a simlink:

# cd /lib/x86_64-linux-gnu && ln -s

And run!:

$ vmware-view

Ssh error Too many authentication failures for root

8 02 2017

ssh -o PubkeyAuthentication=no root@host

Install OpenLDAP in Debian 8

21 12 2016

This guide is the best, by far, that covers the installation of a LDAP server and the configuration of the loging of a server through it.

Split Haproxy configuration in multiple files working with Systemd

9 12 2016

Splitting Haproxy configuration in multiple files it’s a bit tricky due the Systemd startup behaviour. One workaround who works ok it’s the following:

1.- Split the Haproxy configuration file in multiple files.

1.1.- One file called “00-haproxy.conf” with the basic haproxy conf (in my case global, defaults and listen stats). This must have the 00- at the begining for listed it at first place in the script.

1.2.- One file for each listen section for the different services balanced, “some_name_a.conf”. Each new balanced service will have a new file.

Note: In this case, each balanced service is inside a listen section, not using fronted and backed.

# ls /etc/haproxy/
00-haproxy.conf service1.conf service2.conf

# cat /etc/haproxy/00-haproxy.conf
listen proxy-stats
# cat /etc/haproxy/corebalv1.conf
listen xxx
bind ...
server ...
server ...

2.- Create a small script into “/usr/local/bin/haproxy-multiconf” with this content:

for file in /etc/haproxy/*.conf; do
test -f $file
CNF="$CNF -f $file"
echo "CONF='$CNF'" > /etc/haproxy/haproxy-multiconf.lst

3.- Create a new systemd unit for create the conf list before launching the main Haproxy unit.
# cat /etc/systemd/system/haproxy-multiconf.service
Description=HAProxy Load Balancer Multiconf

4.- Modify the default systemd unit file of Haproxy:
# cat haproxy.service
Description=HAProxy Load Balancer
ExecStartPre=/usr/local/sbin/haproxy -c -q $CONF
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -p /run/ $CONF
ExecReload=/bin/kill -USR2 $MAINPID

5.- Refresh systemd and run it:

systemctl daemon-reload
systemctl restart haproxy.service

Run ssh-agent at login and load keys with an alias

27 07 2016

Add the following lines to the “~/.bashrc” for start automatically the ssh-agent service in each login and create and alias for load the keys and write the passphrase:

if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
alias ssh-keys='ssh-add ~/.ssh/name_of_key_one ~/.ssh/name_of_key_two'

Reduciendo un volumen lógico ya montado y creando otro

16 01 2015

Tenemos la siguiente situación. Un sistema linux con un volumen lógico montado en ext4 de gran tamaño, el cual nos sobra mucho almacenamiento y queremos reducirlo, creando otro con el espacio liberado y manteniendo el antiguo con menos espacio.

Los pasos a seguir son los siguientes:
# 1º Reducir el volumen ya montado
# Desmontar punto de montaje, en este caso la home
$ umount /home
# Comprobar sistema de archivos, en este caso se llama lv_home
$ e2fsck -f /dev/mapper/lv_home
# Modificar el tamaño, en este caso 100G
$ resize2fs -p /dev/mapper/lv_home 100G
# Reducir el volumen, ¡importante hacerlo siempre después de reducir el sistema de archivos!
$ lvreduce -L 100G /dev/mapper/lv_home
# Comprobar el sistema de archivos
$ e2fsck -f /dev/mapper/lv_home
# Ajustar el tamaño del sistema de archivos al nuevo lv
$ resize2fs -p /dev/mapper/lv_home
# Comprobar el sistema de archivos
$ e2fsck -f /dev/mapper/lv_home
# Montar y probar
$ mount /home/
$ cd /home/
$ ls # debe entrar sin problemas

# 2º Crear el nuevo volumen con el espacio liberado
# Crear lv en VolGroup (se listan con $vgs)
$ lvcreate -l +100%FREE -n lv_datos VolGroup
# Crear sistema de archivos ext4
$ mkfs.ext4 /dev/mapper/VolGroup-lv_datos
# Crear punto de montaje y montar
$ mkdir /mnt/datos
$ echo '/dev/mapper/VolGroup-lv_datos /mnt/datos ext4 defaults 1 2' >> /etc/fstab
$ mount -a