Install Nikola in virtualenv

Nikola is a static website/blog generator written in Python. You can install it in a virtualenv. Although it supports Python 2 and Python 3 I had trouble using Nikola version 7.1 with Python 3.4. Python 2.7 (tested on Ubuntu 14.04) and Python 3.3 (tested on Mac OS X Mavericks) worked fine.

Install pre-requisites: sudo aptitude install build-essential python-dev python-pip python-virtualenv libxml2-dev libxslt-dev zlib1g-dev

I had to add a few dev libraries to get rid of some errors on Ubuntu.

Install libxml2-dev and libxslt-dev to get rid of error: “fatal error: libxml/xmlversion.h: No such file or directory”.

Install zlib1g-dev to get rid of error: “/usr/bin/ld: cannot find -lz”.

cg@host ~ $ virtualenv virt-nikola

cg@host ~ $ source virt-nikola/bin/activate

(virt-nikola)cg@host ~ $ pip install nikola

(virt-nikola)cg@host ~ $ pip install nikola[extras]

Hat tip: “/usr/bin/ld: cannot find -lz”, Ubuntu 11 : fatal error: libxml/xmlversion.h: No such file or directory

Linux Mint: “Warning: No support for locale: en_US.UTF-8” in update-initramfs

After installing Linux Mint 17 in a VM I started the Update Manager to get the latest updates, including kernel. In the details window I saw this error:

update-initramfs: Generating /boot/initrd.img-3.13.0-24-generic
Warning: No support for locale: en_US.UTF-8

Thanks to Tip: fix for update-initramfs “No support for local …” I found the cause and the solution.

Cause (quoting from the source post): “The problem is that /usr/share/initramfs-tools/hooks/root_locale is expecting to see individual locale directories in /usr/lib/locale, but locale-gen is configured to generate an archive file by default.”

Solution: Run locale-gen again (but use directories not archive file) and then update-initramfs.

sudo locale-gen --purge --no-archive

sudo update-initramfs -u -t

Fix for “undefined reference to clock_gettime”

While running the build.sh script for SIPp I ran into this error:

src/sipp-time.o: In function getmicroseconds()': /chroot/root/sipp/src/time.cpp:57: undefined reference to clock_gettime'

The fix is to add LDFLAGS=”-ltr” like so:

LDFLAGS=" -lrt " ./configure --with-openssl --with-pcap --with-sctp --with-rtpstream

LDFLAGS=" -lrt " make

More information about this error: Ubuntu Linux C++ error: undefined reference to ‘clock_gettime’ and ‘clock_settime’; Untitled; [xymon] Can not compile 4.2.3 on CentOS 5.2

SaltStack Quickstart Guide on Mac OS X

As always, refer to the official SaltStack documentation first.

To get up and running with SaltStack on Mac OS X can be a daunting task. I have found it much easier to use MacPorts to accomplish any such tasks.

Step 1: Install MacPorts on your Mac OS X. I find this to be an essential step for any developer using Mac OS X. Of course, there’s Homebrew as an alternative. I haven’t used it but you may check it out as well.

Once you have setup MacPorts successfully you are ready to begin. Of course, since MacPorts provides a variety of GCC versions I prefer it over the default gcc provided on my Mac. Install a newer GCC and link your system to it.

[user@host ~] $ sudo port install gcc48

[user@host ~] $ sudo mv /usr/bin/gcc /usr/bin/gcc.orig

[user@host ~] $ sudo ln -s /opt/local/bin/gcc-mp-4.8 /usr/bin/gcc

Install Python 2.7.

[user@host ~] $ sudo port install python27

Install Virtualenv.

[user@host ~] $ sudo port install py27-virtualenv

M2Crypto is a requirement for SaltStack and you need to install SWIG. Otherwise you may get errors[1].

[user@host ~] $ sudo port install swig

[user@host ~] $ sudo port install swig-python

Create your virtualenv.

[user@host ~] $ /opt/local/bin/virtualenv-2.7 ~/dev/virt-env/salt-virt

Activate the virtualenv.

[user@host ~] $ source ~/dev/virt-env/salt-virt/bin/activate

Install SaltStack pre-requisites.

(salt-virt)[user@host ~] $ pip install pyzmq PyYAML pycrypto msgpack-python jinja2 psutil

Install SaltStack.

(salt-virt)[user@host ~] $ pip install salt

Make sure things are working well.

(salt-virt)[user@host ~] $ python

Python 2.7.8 (default, Jul 13 2014, 17:11:32) 
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import salt
>>> ^D

To deactivate the virtualenv,

deactivate

Note: this post was created using Mac OS X 10.9 (Mavericks) with SaltStack 2014.1.7.


[1] Possible SWIG error

unable to execute 'swig': No such file or directory

error: command 'swig' failed with exit status 1

gevent Quickstart Guide

This is a simple list of steps on how to get started with installing gevent on openSUSE (tested on openSUSE 13.1 with gevent 1.0.1). We’ll use virtualenv instead of a system-wide install.

You need to have a compiler (gcc) and Python development library.

[user@host ~] $ sudo zypper install gcc python-devel

Install Python 2.7 virtualenv, since gevent 1.0.1 doesn’t appear to support Python 3.

[user@host ~] $ sudo zypper install python-virtualenv

Create virtual environment in your home directory (or anywhere else you want).

[user@host ~] $ virtualenv ~/virt

Activate the virtualenv.

[user@host ~] $ source virt/bin/activate

Install gevent.

(virt) [user@host ~] $ pip install gevent

Check it all works.

(virt) [user@host ~] $ python

Python 2.7.6 (default, Nov 21 2013, 15:55:38) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gevent import sleep
>>> sleep(2)
>>> 

When you’re done deactivate the virtualenv.

(virt) [user@host ~] $ deactivate

SSH Cookbook: Temporarily Disable Security Message on Connection to a Remote Server

First off, DO NOT do this all the time. ONLY do this when you have evaluated the risks and decided to risk a security breach anyways. I usually do this in my testing environment where I get to work with a lot of new or changing VMs.

When you connect for the first time to a server you are prompted to verify its fingerprint. It is then added to your ~/.ssh/known_hosts file so when you connect the next time and the fingerprint matches you are not prompted again. For example:

The authenticity of host '192.168.1.22 (192.168.1.22)' can't be established.
RSA key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00.
Are you sure you want to continue connecting (yes/no)?

This can be annoying when you connect to a lot of “new” SSH servers. It also doesn’t work in test environments where scripts need to continously connect to machines they have not connected to before and may not ever connect again. This can be even more annoying when the same IP is recycled between various test machines and your client machine does not connect because a known host’s fingerprint changed.

You can temporarily disable fingerprint matching at the time you are connecting:

ssh myuser@192.168.1.22 -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

You can also put this config in your ~/.ssh/config file so that you don’t need to provide these extra flags all the time:

Host myhost
    HostName 192.168.1.22
    Port 22
    User myuser
    AddressFamily inet
    CheckHostIP no
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null

Now when you connect to the server you will see a message similar to this one:

Warning: Permanently added '192.168.1.22' (RSA) to the list of known hosts.

It hasn’t actually added it to the known hosts file and that’s the beauty of it.

One last thing: DO NOT do this when connecting to machines you absolutely must trust. It’s alright to use this technique when connecting within a test lab environment, for example.