Friday, February 17, 2012

Allow remote connections to MySQL server

To enable remote access for MySQL server:

$ sudo vim /etc/mysql/my.cnf
### edit my.cnf
### set bind address and comment out or remove skip-networking (if exists)

[mysqld]
...
bind-address=SERVER-EXTERNAL-IP
# skip-networking

$ /etc/init.d/mysql restart

Now it works.

Friday, February 10, 2012

{less} mix function error

Documentation tells mix function takes only two parameters, @color1 and @color2. Actually there is a mistake. The correct function definition is

mix(@color1, @color2, value)

, where value denotes how much of @color1 should appear in the result color.

Tuesday, February 7, 2012

Trap Ctrl C in Bash

#!/bin/bash

# call trapped in case Ctrl+C pressed
trap trapped INT

function trapped() {
    echo "CTRL-C pressed"
}

while true; do
    sleep 1
    echo -n "."
done

Friday, February 3, 2012

Setup Apache2's mod_wsgi on Ubuntu

If you get this when restarting Apache2 on Ubuntu
Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
it means you don't have mod_wsgi module installed.

These commands install and enable it.
sudo apt-get install libapache2-mod-wsgi
sudo a2enmod mod-wsgi
sudo /etc/init.d/apache2 restart

Perl warning about locale in Ubuntu

If you get this warning
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

it can be fixed with
locale-gen en_US.UTF-8
dpkg-reconfigure locales

Get Graphite run for a Django project

This post is intended first of all to memorize my experience of getting the Graphite system work.

Wednesday, February 1, 2012

Install RabbitMQ

install server itself (using port)

MacOs X:
sudo port install rabbitmq-server

Ubuntu:
sudo apt-get install rabbitmq-server

create user, vhost and set some permissions:
rabbitmqctl add_user username password
rabbitmqctl add_vhost /vhost
rabbitmqctl set_permissions -p /vhost username ".*" ".*" ".*"

done.

OSError: [Errno 38] Function not implemented

Server: Ubuntu 11.04

Run celeryd with info log level

$ ./manage.py celeryd -l info
[2012-02-01 01:16:45,779: ERROR/MainProcess] Unrecoverable error: OSError(38, 'Function not implemented')
Traceback (most recent call last):
  File "/var/www/th4x/.env/lib/python2.7/site-packages/celery/worker/__init__.py", line 268, in start
    component.start()
  File "/var/www/th4x/.env/lib/python2.7/site-packages/celery/concurrency/base.py", line 72, in start
    self.on_start()
  File "/var/www/th4x/.env/lib/python2.7/site-packages/celery/concurrency/processes/__init__.py", line 43, in on_start
    self._pool = self.Pool(processes=self.limit, **self.options)
  File "/var/www/th4x/.env/lib/python2.7/site-packages/celery/concurrency/processes/pool.py", line 520, in __init__
    self._setup_queues()
  File "/var/www/th4x/.env/lib/python2.7/site-packages/celery/concurrency/processes/pool.py", line 695, in _setup_queues
    self._inqueue = SimpleQueue()
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 354, in __init__
    self._rlock = Lock()
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 147, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1)
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 38] Function not implemented
[2012-02-01 01:16:45,780: INFO/MainProcess] process shutting down

Python's _multithreading requires /dev/shm to work. In Ubuntu /dev/shm points to /run/shm by default. Rename (or delete, I doubt it is necessary anymore) existing /dev/shm.

Create /dev/shm directory
$ sudo -i  # get root
$ mkdir /dev/shm

Add to /etc/fstab mounting of /dev/shm command
tmpfs /dev/shm    tmpfs   defaults,noexec,nosuid     0     0

Mount all unmounted filesystems from /etc/fstab.
$ mount -a
There should be no errors.

Run again
$ ./manage.py celeryd -l info

It starts normally.