01 Feb

MySQL slow queries log rotation

By default MySQL server doesn’t rotate slow queries log. Probably the simplest way to get rid of slow log which takes gigabytes is to use logrotate. Here’s an example:

[root@marge ~]# cat /etc/logrotate.d/mysql-slow
/var/log/mysqld-slow.log {
weekly
missingok
rotate 1
nocompress
copytruncate
notifempty
create 644 mysql mysql
}
[root@marge ~]#

If you need more than one rotated log adjust rotate values.

01 Feb

trac deployment under nginx on Centos 6

Here’s is an example of how to deploy trac under nginx. I assume that you already have trac installed.

server {
    listen 192.168.1.1:80;
    server_name trac.example.com www.trac.example.com default;

    location /chrome/common/ {
         alias /usr/lib/python2.6/site-packages/trac/htdocs/;
         expires 1M;
         add_header Cache-Control private;
         gzip_static on;
         gzip_disable Firefox/([0-2]\.|3\.0);
         gzip_disable Chrome/2;
         gzip_disable Safari;
    }
    location / {
        auth_basic            "Authorized area";
        auth_basic_user_file  /home/trac/.passwords;

        proxy_pass  http://127.0.0.1:8000;
        proxy_set_header REMOTE_USER $remote_user;
    }
}

trac is being launched this way:

/usr/bin/python /usr/sbin/tracd --daemonize --pidfile=/tmp/tracd.pid --port=8000 --protocol=http --single-env /home/trac -b 127.0.0.1 --basic-auth==/home/trac,/home/trac/.passwords,example.com

To get the authorization working you should also have this parameter in your trac.ini file:

obey_remote_user_header = true
01 Feb

How to modify a variable inside of function

Code example

class z():
    def __init__(self):
        self.z = ['foo']
        print 'before', self.z

    def zoo(self, doo):
        doo[0] = 'ya'

class b():
    def __init__(self):
        self.z = 'foo'
        print 'before', self.z

    def zoo(self, doo):
        doo = 'ya'

A = z()
A.zoo(A.z)
print 'after', A.z

print

B = b()
B.zoo(B.z)
print 'after', B.z

Output

[dandelion@bart ~]$ python z.py
before ['foo']
after ['ya']

before foo
after foo
[dandelion@bart ~]$

Explanation

It’s simple. In Python ‘string’ is immutable object, while [list] is mutable one.