Archive

Seenly’s Move

A Seenly PortraitWith 31000 snapshots uploaded, Seenly reached the limits of the 1.5GB of webspace provided by the previous webhost. A move to a new host was inevitable. After some looking around, I decided I’d try 1-eurohost. For readers from PlanetUgent, that’s fellow blogger Stein van Stichel’s company (Dutch link).

Since Seenly inherently has some quirky requirements, I first had to make sure they were running the correct version of PHP. Every PHP before 5.2 contains a bug that truncates uploaded binary data at the first null byte (apparantly PHP was parsing it using a C string function). Seenly sends JPEG data as binary data, so this would mean images would never be complete. Stein informed me with a quick mail that they were running 5.2.1, and I was happy.

Great, go ahead, order the damn thing. Turns out they’re running a lot more security “upgrades” than my previous host, such as base_opendir and mod_security. Base_opendir made my subdomains useless: I couldn’t create a file in files.seenly.com from a php-script running at www.seenly.com. I had to redirect all my subdomains, and modify a lot of files but it was doable. Still, maybe this is needlessly strict?

Mod_security dismissed the multipart/form-data upload I generate in Flash. This was a problem, since doing a multipart/form-data in Actionscript is still a bit of black magic, and fixing it might not even be possible. Luckily a friend gave me the idea that I might be able to disable mod_security in a .htaccess. A quick SetSecFilter Off did the job, and everything is now purring happily along.

Moving to 1-eurohost I first had some doubts, since my previous host has been very good to me. Imagine my surprise when I noticed Seenly’s speed has doubled now, even though I’m paying less. The only disadvantage is that they don’t have shell access, which would have been handy when I wanted to upload 124000 files. Uploading just a tar file, and then untarring it on the server, would have been so much easier. More on how I managed that feat in a next entry.

Poor Man’s Cron Trigger

This is a handy trick I use when I want to execute something as root when some event triggers, but without any interaction between the event and the start of the action. It’s quite unsafe and dirty, but it gets the job done.

When the event happens, make it create a file:

touch /tmp/this-event-happened

Now add the following cronjob as root (or whatever user you want):

* * * * * /bin/rm /tmp/this-event-happened 2>/dev/null && /bin/bash\
/execute/this.sh

First come the stars, which tell cronjob to execute this command every minute. Then we try to remove the /tmp/this-event-happened file. rm will exit with an error-code when the file doesn’t exist, and in that case the script won’t be executed, because we’re chaining it using “&&”, the AND operator. In a shell, and most modern programming languages, if the first parameter of an AND operator is false, it won’t even evaluate the second parameter, because the total result will definetly be false anyway.

If the file does exist, the shell will evaluate the second parameter as well, and thus execute the script. Meanwhile the file will be removed, so everything is set up for the next trigger.

As you can see, very simple. It has some problems though. For example, any user can create files in /tmp, so it’s not very safe. You could create a directory somewhere that’s only accessible to the user that is allowed to generate the event, and put the trigger-file there. Another disadvantage: if the script takes longer than a minute to run, and the event is triggered again, the script will run twice at the same time. So take care when using this!

A Job

De Therminal, Annotations

If you think I’m behind on my blogging, you’re right. There are about 9 drafts in the pipeline, but I just don’t have as much time as I used to to finish them.

Apart from the regular time-consumers that appear in the middle of a semester like tasks and projects for the university, I also have a job now. Since Monday March 10 I’m the new ICT-dude at the DSA (Dienst StudentenActiviteiten, the link between all the student organizations and the University of Ghent), replacing Dieter Adriaenssens, who got a job at the VUB.

I’m now in charge of keeping the DSA servers running, and troubleshooting some 20 client PC’s in De Therminal, which is the student house of our university. My job consists of some php programming, a lot of sysadminning, and regular hardware maintenance.

My office is a concrete cave underneath the Schelde. It’s filled with buzzing 19″ rackmount servers, discarded PC’s, and boxes full of cables. The IT-cave is the only room in the whole building with air conditioning, and I also have my very own fake-leather CEO-style chair.

Awesome? Very.

Could not create rewrite_log_lock

If you’ve rolled your own kernel and you’re getting this error when starting Apache:

[crit] (38)Function not implemented: mod_rewrite:
 could not create rewrite_log_lock
Configuration Failed

It’s probably because you’ve cut a vital library - System V IPC. Enable it under General Setup - System V IPC, and recompile.

Software Security

If you’re interested in code injections using buffer overflows in C/C++ and other software-related security holes, I can recommend the talk by Yves Younan next wednesday. It’s organized by Zeus and starts at 20h00 in the Sterre, S9, room A2.

For more info and an abstract, check the Zeus website.

Software Security poster

LaTeX Introduction

LaTeX
Zeus WPI is waking up from hibernation-mode. Tomorrow, Monday 11 February, Gaspard Lequeux will explain LaTeX for the total newbie. So if you’re in Gent and would like to spice up your reports, don’t hesitate to drop by.

For more info on LaTeX, read Gaspard’s course (Dutch), or check out Peter’s latex.ugent.be (also Dutch).

Ubuntu Tip: Hostnames

Ubuntu Hostname
Since Ubuntu runs Avahi by default, every regular Ubuntu PC broadcasts its hostname. As a result you can use “host.local” as the hostname to connect to, where host is the name of the box running Ubuntu. It will automagically find it, even if you don’t know the IP address.

Handy for SSH, webservers, shared disks, or even just a simple ping.

Fatal error: Allowed memory size exhausted

Fatal error: Allowed memory size of 8388608 bytes exhausted

Ever got that error? It’s PHP telling you you’ve gone overboard on memory usage, and then dying (…pussy). When you’re running Wordpress, you might have encountered this error when trying to activate some plug-in. Wordpress isn’t exactly the thinnest script on the block. I got this error when trying out the stats plug-in Wassup.

To solve it, we need to tell PHP that scripts can use more than the default amount of memory of 8MB. This is usually set in the php.ini file, but on shared hosts you won’t be able to access it. So we have to resort to .htaccess files, which are equally great, but your host might have disabled changing this setting, in which case this fix won’t work.

Wordpress Fix

Here’s to solve it if you’re using Wordpress. For everything else, scroll down!

Go to Site Admin, Select Manage and then Files. Select .htaccess (for rewrite rules), it should be in the list to the right under Common. If not, scroll down and enter .htaccess in Other Files and press Edit file.

Now you should see something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Just add the following line to it…

php_value memory_limit 16M

…and press Update File. There, now it should work!

General Solution

Browse to a parent directory of your script (any parent, even root, will do). Create a file named “.htaccess“. That’s including the first dot. In that file, enter the following line. If the file already exists, just edit it, and append it.

php_value memory_limit 16M

Now try again.

Still not working?

If it still gives you the error, but now with a different amount of bytes exhausted, the fix is working but you need to set the memory limit even higher. Try increasing 16M to 32M, and so on. Don’t go too high, though! It might just be that your script has a bug that eats up all available memory, in which case you need to check out the code instead of increase the memory limit.
If the error stays the same, your host will probably have disabled the ability to change this setting, and you’re out of luck :( .

IRC Quote (1)

Here’s a small puzzle:

There’s a file with an unknown number of lines. From that file, I want to read and display 1 line. The line needs to be picked completely at random, so that every line has an equal chance to be selected.

What’s the fastest algorithm you can come up with?

Apparantly it’s my birthday

Happy Birthday From Forums

Luckily one can always rely on the default happy birthday notifications from the internet to warn you about it.