Archive for the ‘problems and solutions’ Category

USB device unter Linux neu laden

January 20, 2012

Hin und wieder kommt es vor, dass man ein USB device “resetten” muss, damit z.B. eine frisch geänderte Partitionstabelle neu eingelesen wird und man anschließend eine saubere Formatierung durchführen kann.

Jetzt kann man sich zwar die Mühe machen, das Device einmal vom Port zu trennen und wieder einzustecken – doch das kann einen Scriptablauf schon gewaltig stören.

Hier die Loesung (am Beispiel von /dev/sdb als unser USB device):

hdparm -z /dev/sdb

Ich habe mir angewöhnt, diesen Befehl mit 2 sleep Kommandos zu umschließen – nicht, dass das nötig wäre, aber ich hasse nunmal race conditions und lebe nach “Better safe than sorry”:

sleep 5
hdparm -z /dev/sdb
sleep 5

How to run Django apps on a CentOS Plesk server

June 17, 2011

The reason for this tutorial is quite easy: To make this happen, I had to read about 100 pages, all with different solutions, all of them not or only partially working.

After aprox. 8 hours of trial and error, I finally had the best of all the posts compiled to a working set of instructions – so here is the HowTo:

Login as user root to the server in question.

First of all: The usage with the pre-installed mod_python is no fun at all and leads to many errors, therefore it is better to switch to mod_wsgi. If you need the mod_python, stop NOW and search for a different solution. Honestly: I tried it also with mod_python and wasted 6 of the above 8 hours, banging with my head into wall after wall.

Update: And now, that everything was compiled and done, they tell me to use Python 2.6 instead of 2.4 – so please find below the latest install guide for Python 2.6!

1. Add the EPEL repository for the correct CentOS version your server runs on:

CentOS 5:

http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

CentOS 4:

http://download.fedoraproject.org/pub/epel/4/i386/epel-release-4-10.noarch.rpm

2. disable this repository (no joke), otherwise it tries always to update stuff and will break Plesk!
Edit the file /etc/yum.repos.d/epel.repo and set everywhere “enabled=0″

3. install the following packages:

yum install gcc httpd-devel rpm-build
yum install git python26 python26-devel python26-distribute python26-libs python26-simplejson --enablerepo=epel

4. Now we create the pip (Python package installer) tool

cd /usr/src
curl -O http://python-distribute.org/distribute_setup.py
python26 distribute_setup.py
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python26 get-pip.py
yumdownloader --source mod_wsgi --enablerepo=epel
rpm -ivh mod_wsgi*rpm

5. Enable Python 2.6 support for mod_wsgi

cd /usr/src/redhat/SPECS

Edit the file mod_wsgi.spec

change:

%configure --enable-shared

to:

%configure --enable-shared --with-python=/usr/bin/python2.6

6. Compile mod_wsgi and install

rpmbuild -ba mod_wsgi.spec
rpm -Uvh /usr/src/redhat/RPMS/i386/mod_wsgi-3.2-2.i386.rpm

7. Disable mod_python in Apache
Edit /etc/httpd/conf.d/python.conf

change:

LoadModule python_module modules/mod_python.so

# Override type-map handler for /var/www/manual
<Directory "/var/www/manual/mod/mod_python">
        <Files *.html>
                SetHandler default-handler
        </Files>
</Directory>

to:

#LoadModule python_module modules/mod_python.so

# Override type-map handler for /var/www/manual
#<Directory "/var/www/manual/mod/mod_python">
#        <Files *.html>
#                SetHandler default-handler
#        </Files>
#</Directory>

8. Enable mod_wsgi
Edit /etc/httpd/conf.d/wsgi.conf

Change:

#LoadModule wsgi_module modules/mod_wsgi.so

to:

LoadModule wsgi_module modules/mod_wsgi.so

 

Now we’re ready to rumble.

The following describes the setup of the Django Fiber example project (ridethepony) to the domain “domain.nl”:

1. lets go to the subdirectory in question:

cd /var/www/vhosts/domain.nl

2. setup a vhost.conf file to redirect dynamic requests to mod_wsgi and static page requests to the common httpdocs directory
Edit conf/vhost.conf, adding the following lines:

Alias /robots.txt /var/www/vhosts/domain.nl/httpdocs/robots.txt
Alias /favicon.ico /var/www/vhosts/domain.nl/httpdocs/favicon.ico

Alias /static/ /var/www/vhosts/domain.nl/httpdocs/
Alias /media/ /var/www/vhosts/domain.nl/httpdocs/media/

WSGIScriptAlias / /var/www/vhosts/domain.nl/django.wsgi

<Directory /var/www/vhosts/domain.nl>
    Order allow,deny
    Allow from all
</Directory>

3. download the application, unpack and rename

git clone git://github.com/ridethepony/django-fiber-example.git
mv django-fiber-example pony

4. prepare the application

chmod 0777 pony
cd pony
pip install -r requirements.txt
cp settings.example.py settings.py

5. Edit settings.py

Change:

'NAME': 'fiber_example',                # Or path to database file if using sqlite3.

to:

'NAME': '/var/www/vhosts/domain.nl/pony/fiber_example',                # Or path to database file if using sqlite3.

6. Edit settings_default.py

Change:

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

to:

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
    '/var/www/vhosts/domain.nl/pony/pages/templates',
)

7. Create the default database and import the content

python26 manage.py syncdb
python26 manage.py loaddata ./fixtures/example_initial_data.json
chmod 0666 fiber_example

8. copy the static css files into the static directories

python26 manage.py collectstatic --link
cp -a pages/static/* ../httpdocs/.

9. create the base WSGI file

cd ..

create file django.wsgi with the following content:

import os
import sys

path = '/var/www/vhosts/domain.nl/pony'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

10. activate the Apache and vhost changes:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-all
service httpd restart

11. Enjoy the result at http://domain.nl

Yum Install CentOS-5 (Upgrade from CentOS 4 to CentOS 5)

July 1, 2010

Don’t follow any how-to without having your brain in alarm mode.

I found a nice tutorial (http://www.tocpcs.com/yum-install-centos-5-upgrade-from-centos-44-to-centos-5/) from 2007 for the upgrade from CentOS4 to CentOS5  using yum only – which I tried to use and did NOT follow to the end – otherwise my server, standing in a datacenter 150 km away, would have been wiped out.

First of all: This is not for the unexperienced and I don’t take any responsibilities for your data!

So here is the tutorial for the fearless, double checked and proven:

1. First things first: Tell the system that your core is CentOS 5 (which is not right yet, but that way you will get the right packages):

rpm -Uvh http://ftp.tudelft.nl/centos.org/5/os/i386/CentOS/centos-release-5-5.el5.centos.i386.rpm http://ftp.tudelft.nl/centos.org/5/os/i386/CentOS/centos-release-notes-5.5-0.i386.rpm

2. clean up yum’s cache

yum clean all

2a. check that all 3rd party yum repositories (atomic, rpmforge…) are disabled!!! Otherwise you will never ever solve the dependencies

3. remove packages, that might be in the way during the upgrade:

rpm -e --nodeps hal

4. clean up your kernels (yes, there might be more than one)

uname -a (find out, which kernel is your operational kernel)

rpm -qa | grep kernel (find all installed kernels)

rpm -e ... (for all kernels but your operational kernel)

rpm -e --justdb --nodeps (for the active kernel)

5. Now it’s time for the first try

yum upgrade

6. …yes, and now you have to wait until your system sorts out your problems. In the end you will get a list of problematic packages. For me it was python-elemnttree which is scary, because it belongs to yum. Remove all packages where you are sure you can miss them (and re-install later):

rpm -e --justdb --nodeps python-elementtree

…and VFlib2, which I really don’t need, so I removed it with all dependencies:

rpm -e VFlib2 ghostscript ghostscript-fonts hpijs system-config-printer hal-cups-utils

7. …and off we go:

yum upgrade

8. Now, it takes time – and in the end my yum was broken :-)   So here is the fix:

rpm -Uvh --force http://ftp.tudelft.nl/centos.org/5/os/i386/CentOS/python-sqlite-1.1.7-1.2.1.i386.rpm
yum clean all

9. and that’s it. check your grub configuration and reboot, you’re now the proud owner of CentOS5

10. like to clean up a bit more?

rpm -qa | grep el4

11. all those packages can either be removed or – when you got them from a sneaky RPM mirror with newer versions – downgraded.

just for the record: I found the following on my system:

rhnlib-2.1.2-11.el4
dmraid-1.0.0.rc14-9_RHEL4_U7.el4
mysql-libs-5.0.68-1.el4_6
ash-0.3.8-20.el4_7.1
php-pear-1.4.11-1.el4s1.1
perl-DBD-MySQL-4.006-1.el4.centos
up2date-4.7.1-17.el4.centos
perl-DBI-1.604-1.el4s1
php-pecl-zip-1.8.0-1.el4.centos

…and this is, what I did:

rpm -e up2date rhnlib mysql-libs php-pecl-zip ash
yum downgrade perl-DBI perl-DBD-MySQL php-pear dmraid

finally I brought the RPM-database into a consistent state. Not needed, but sometimes helpful

rm -f /var/lib/rpm/__*
rpm --rebuilddb

And that’s definetly it!

enjoy, it worked for me 4 times on different servers!

The Day After

April 16, 2010

Nun ist es endlich so weit, mein Stress hat vorerst ein Ende. Nach meinem letzten Post habe ich nochmal 4 Monate Vollgas gegeben und dann gestern abend den Gang rausgenommen. Jetzt heißts den Umzug vorzubereiten und dann geht es im Mai an meiner neuen Arbeitsstelle in den Niederlanden weiter.

Nach langem Ausschlafen heute setzte ich mich dann im frühen Nachmittag ins Auto um einzukaufen, machte mein Radio an – und hörte von Westernhagen “Freiheit”. Wenn das kein Zeichen ist!!!!

Arbeitsstress hinter mir, Umzugsstress vor mir. ok. kein SO guter Tausch. Aber ich tanke jetzt bereits wieder Energie für die nächsten Monate und Jahre.

Ich freu mich drauf! ™

undo – oder Geld vs. Arbeitsspaß

December 20, 2009

Wann immer ich im Fernsehen oder Radio etwas über burn out-Syndrom oder Aussteiger erfuhr, dachte ich mir immer, das könne mir nicht passieren. Ich mache schließlich eine Arbeit, die mir einen höllischen Spaß macht und daher ist aller Stress positiv. Das stimmte auch soweit – dann kam aber spontan und eher unerwartet die Chance auf die große Karriere. Und ich rannte blindlinks dem Geld hinterher in einen Job, von dem ich eigentlich nicht viel verstand.

Ein ganzes Jahr dauerte es, bis der Stress von positiv in negativ umschlug und meine Gesundheit zunehmend den Bach runter sauste. Und mit einem Mal fühlte ich mich ausgebrannt, müde und dachte sogar über schlimmere Sachen als spontanes Aussteigen nach.

Zeit für den großen “undo”-Knopf. “Karriere” in die Tonne gekloppt, zurück zu dem Job, der zwar schlechter bezahlt wird aber dafür exakt das ist, was ich kann und will. Die Kündigung ist geschrieben, der neue Arbeitsvertrag so gut wie unterschrieben. Und – schwupps – gehts mit meiner Gesundheit wieder aufwärts und ich fühle mich zunehmend besser.

Merke: Ein Job der Spaß macht ist weit mehr wert als Kohle. Musste ich auch erst lernen, dass so’n blöder Spruch wie “Geld allein macht auch nicht glücklich” ziemlich viel Sinn macht.

Somit steht der Plan fürs neue Jahr: Viel arbeiten – gerne. Aber die Arbeit muss auch Spaß machen. (Und ich will mir nicht vorschreiben lassen, wie ich mit Kollegen und Freunden umzugehen habe).

Endlich einmal Neujahrsvorsätze, die ich halten kann :-)

In diesem Sinn: Schöne Festtage und einen guten Rutsch.

MySQL InnoDB reparieren für Fortgeschrittene

August 22, 2009

Es war wieder einmal so weit – ich hatte etwas zerstört und war auf der Suche nach einer Lösung im Netz. Und das Netz konnte mir nicht helfen….

Aber fangen wir doch einfach von vorne an.

Das Warum und das Wie lassen wir jetzt mal beiseite. In jedem Fall stand ich vor einigen Tagen mit einem laufenden Datenbankserver da, der auf der einen Seite keine Downtime haben darf, auf der anderen Seite aber eine wichtige Datenbank mit InnoDB Tabellen enthielt, deren “tablespace id” nicht mehr stimmt.

Kleiner Ausflug in die MySQL Theorie. Wenn man InnoDB nutzt hat man generell zwei Möglichkeiten:
1. Alle Tabellendaten werden in die Zentralle Datei ibdata geschrieben. Diese bläht sich dadurch gigantisch auf und wird für schnelle Aktionen teilweise unhandlebar.
2. Man entscheidet sich für die Option “innodb_file_per_table”, wodurch die Daten in separaten Dateien je Tabelle geschrieben werden und nur die Keys etc. in der Datei ibdata verbleiben. Die Dateien stellen den Tablespace der Tabelle dar und sind über die Tablespace id mit den Daten (Keys etc.) in der Datei ibdata verknüpft.

Durch unglückliche manuelle Operationen inklusive Backup und Restore stimmen mit einem mal diese ids nicht mehr überein oder es gibt sogar zwei Tabellen mit der selben id. In der Regel ist das System an dieser Stelle fubar – fucked up beyond all repair. So sagen selbst die größten MySQL Gurus. An einer Lösung wird in Versionen größer 5.1 gearbeitet. Ende der Fahnenstange.

Nun gut, ich habe es verbockt und gebe mich daher nicht geschlagen. Wenn mir Google und die Welt nicht helfen will, suche ich halt selbst nach Lösungen.

Hier nun die Lösung, die Funktioniert:

- Setze eine frische, leere MySQL Installation auf einer separaten Maschine auf

- erstelle eine Dummy-Datenbank

- lese aus dem error-log der kaputten DB die Tablespace id der ersten zu reparierenden Tabelle aus (in meinem Fall 589) => n

- erstelle in der Dummy-Datenbank n-1 InnoDB Tabellen, in meinem Fall 588

- lege eine zweite Datenbank mit dem gleichen Namen an, in dem Deine kaputte Tabelle liegt.

- Erstelle dort mit Create Table die exakte Struktur der kaputten Tabelle

- führe ein “ALTER TABLE tabellenname DROP TABLESPACE” in dieser Datenbank aus

- kopiere die als kaputt markierte .ibd Datei in diese neue Datenbank – achte auf die Benutzerrechte!

- führe ein “ALTER TABLE tabellenname IMPORT TABLESPACE” aus

- führe ein “OPTIMIZE TABLE tabellenname” aus

- nutze mysqldump um die Tabelle zu sichern

- um weitere Tabellen zu reparieren, fange ganz von vorne an! Und das ist wichtig, denn für den nächsten Anlauf muss wieder die MySQL ganz jungfräulich sein, sonst habt ihr auch in der neuen Installation wieder die tablespace ids zerstört. Also: MySQL stoppen, die ibdata, die ib_logfiles, das gesamte Verzeichnis der Dummy-Datenbank und die neu angelegte Datenbank physikalisch löschen! MySQL neu starten und los gehts für Tabelle 2

- versucht NIE, die Reihenfolge der Schritte zu ändern oder mehrere Tabellen gleichzeitig zu reparieren. Das herauszufinden kostete mich Stunden!

Anschließend die Backup-Tabellen einspielen und alles sollte gut sein!

Viel Glück!

…dann ging der Fernseher aus… (Teil 2)

June 29, 2009

ja, ja, es klingt wie ein billiges Remake, aber letzten Samstag knallte es, es roch nach Ampère – und wieder war der Fernseher aus.

Also: Alle Stecker ziehen, Sicherung wieder rein und Stück für Stück die Stecker wieder einstecken, bis es wieder knallt. Und – tadaaa – diesmal war es mein Computer. Mein geliebter P4 1.7 GHz hatte sein digitales Leben einfach so ausgehaucht. Das war jetzt das dritte Netzteil dieses Jahr, diesmal ein starkes 420 Watt Netzteil. Ich hege langsam die Befürchtung, dass da irgendwas im Rechner selbst meine Netzteile grillt.

Schau’n ‘mer mal, ob ich dieses Jahr noch mal nen Monat erlebe, in dem nichts kaputt geht…

P.S.: Die Waschmaschine macht beim Schleudern auch schon ziemlich heftige Geräusche….

localization of WordPress

October 25, 2008

Which tool will be the most supported one to blog? Must be the right choice then, or not? Welcome to configuration hell….

First shot: Installation of localized (DE) version of WordPress 2.6.3. Everything works out – and stays in english. All .mo files checked, no errors found. Not, that I think visitors of mine are not able to read some words in english – the combination of german posts and english menues simply looks odd. What to do if things don’t work out? Correct: Ask Google…

Second try: Found a nice plugin which allows me to post in multiple languages and switch between them. Woooohoooo – nice one. So: Restart from scratch with the english version, install plugin, test – duh! Now I can switch the posts between different languages, but the menues stay in english. Not to talk about the admin area….

Testing around (randomly, sigh!) I found out, that restarting my Apache I get an – uhm, let’s say “funny” result: Right after the restart, Apache delivers everything exactly, as I expected the system to do – but only once after each restart. Right after, everything falls back to english?! WTF???? Same thing happens, when I edit wp-includes/gettext.php, or even change only this file’s (and ONLY THIS file’s) timestamp with touch.

If I call the index.php directly from shell with PHP CLI, everything works fine.

8 hours of googling, ranting (and a bit of sleeping, yeah) later, I finally hunted the problem down: NuSphere’s PhpExpress! As soon as this accelerator is active, it tries to “optimize” the gettext calls of WordPress by switching it to the PHP internal gettext – which looks up the wrong directories in search for the .mo files.

Case closed. “Only” thing missing now, is the fine tuning of the localized texts…