dmy

Adding A Plesk Event Handler

written by admin 17 days ago. Last update at 2010-02-25 17:46:31. Categories plesk. Tags .

Plesk allows you to have a customized event handler. This is a rather useful feature cause it allows you to customize the way Plesk behaves. Take the meanwhile famous vhost_ssl.conf bug. Although documented in the manual, Plesk will not recognize an additional configuration file for an SSL/TLS port in a subdomain. Solutions have been proposed to manually change vhost.conf. That’s a forbidden fruit however, cause all it needs is a websrvmng --reconfigure-all to eliminate your changes. But as mentioned, just install a event handler which is triggered when a subdomain is created or updated. Such an event handler can be just a plain shell script.

However, when I tried to install such an event handler beast via Plesk | Server | Event Handler | Add New Event Handler I ended up in an error message like Error: Some fields are empty or contain an improper value for which add did not have any explanation. Much, very much later, I discovered that I had copied the path of my script to be executed via copy-n-paste into that Plesk command field. That copy contained whitespace at the end of the command, i.e. something like

/path/to/handler.sh\n

which is enough to make Please grumpy. What’s more, it’s all about whitespace (blanks, tabs, newline etc) at the end of a command while whitespace within the command is accept without any rumble:

echo > /dev/null

That works fine.

Summary:

When entering an event handler command, make sure that there is no whitespace at the end of the command.

dmy

Announcement – Flaka 1.01 Released

written by admin 18 days ago. Last update at 2010-02-25 17:46:31. Categories Projects, flaka.

February 24th, 2010The Flaka project is pleased to announce the
release of Flaka 1.01, the first release of Flaka.

Flaka is an extension for Ant. A main project goal of Flaka is the
simplification of writing a build script.

Flaka provides:
1. an expression language (Java Unified Expression Language)
2. well known programming elements (for, when, switch, choose, ..)
3. exception handling
4. additional types, tasks and macros

A small teaser script to demonstrate some of those features:

<project xmlns:c="antlib:it.haefelinger.flaka" name="Flaka" >
  <c:logo>
    Hello #{ project.name ? project.name : ''}!
  </c:logo>
  <c:for var=" f " in=" ''.tofile.list ">
    <c:when test=" f.isfile ">
      <c:echo>
        ;; report basename and modification time
        file #{f.name} last modified: #{ f.mtime }
      </c:echo>
    </c:when>
  </c:for>
</project>

Flaka’s Google Project Page is
http://code.google.com/p/flaka

Manual
http://flaka.googlecode.com/files/flaka.pdf
(* Part I of this manual contains a broad overview of
features Flaka has been charged with *)

Jar (ready to be used – no additional dependencies required)
http://flaka.googlecode.com/files/ant-flaka-1.01.jar

Development Package (rebuild from scratch)
http://flaka.googlecode.com/files/flaka-1.01.zip

Issues should be reported to:
http://code.google.com/p/flaka/issues/list

More information on Flaka at
http://code.google.com/p/flaka ; and
http://workbench.haefelinger.it/flaka

Regards,
Wolfgang Häfelinger

dmy

MacPorts, MySQL, PHP5 and that socket thing ..

written by admin 29 days ago. Last update at 2010-02-25 17:46:31. Categories macosx, macports. Tags , , .

I’m using MacPorts to have a variety of Open-Source software on my computer. Amongst them MySQL and Apache’s web server with PHP. In addition I’m also running Wordpress, a popular blog software, and Mediawiki, the software behind Wikipedia. Both applications are written in PHP and can be configured to use MySQL as database.

I install those two web applications myself rather than using MacPorts to do so. The installation is basically nothing more than unzipping the distribution package and to modify the configuration files to make sure they connect to my MySQL database on my localhost. However, while installing Wordpress went smooth, I run into database connection failures when installing Mediawiki. It took me some time to figure out what is going on here.

If you have weird connection problems using PHP and MySQL then try one or both of the following solutions:

  • Solution: Use 127.0.0.1 instead of localhost as host of your MySQL database server. This has a rather surprising effect, see below.
  • Solution: Change your PHP’s configuration file, which is /opt/local/etc/php5/php.ini, to contain the following two lines:
    1. Tell PHP about the Unix domain socket to use
         mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
      
    2. In addtion make sure that PHP’s save mode is off (notice that this feature has been deprecated and removed in PHP 6), otherwise your previous modification will be gracefully ignored:
          safe_mode = Off
      

    Notice that in addition you need to restart your Apache web server so that your changes are taken into account. You can do that with apachectl restart.

Background Information

Neither Mediawiki nor Wordpress (nor most other PHP based web application accessing MySQL) implement the gory details how to connect to a database. Usually they just delegate this to mysql_connect();, a API function provided by PHP.

PHP in turn uses the functionality of a (shared) library provided by MySQL, i.e. the MySQL driver. MySQL allows you to connect to the database via two routes:

  1. via Internet sockets (TCP/IP); and via
  2. UNIX domain sockets

So, how does one choose between this two routes? The answer is rather surprising. MySQL decided to give localhost a new meaning. If you specify localhost, then the UNIX domain socket route is chosen. If you say 127.0.0.1 instead, then you connect via an Internet socket. While this is probably the most natural thing for those MySQL folks, it’s a rather confusing fact for all other humans. It is rather carved deep in our brain for years now that 127.0.0.1 and localhost is the same thing.

After I have changed both Mediawiki and Wordpress to use localhost I had for the first time a situation where both web applications behaved in the very same way. They both did not work. Then, when I changed to 127.0.0.1, both worked fine. Btw, notice that localhost is the default hostname used by Mediawiki while 127.0.0.1 is the default host suggested by Wordpress.

Using 127.0.0.1 is usually fine, however I do want to use the UNIX socket and I was wondering what went wrong.

The problem is that MacPorts MySQL port patches the original MySQL sources to use socket /opt/local/var/run/mysql5/mysqld.sock instead /tmp/mysql.sock. This change is not particular well documented. One would assume that this kind of change goes into an appropriate my.conf configuration file. That’s actually not the case. Even worse, MacPorts MySQL port does not even ship with such a configuration file.

Changing the default socket location is one thing, not telling us and the PHP5 maintainer this is another sin. So, while MySQL happily uses that weird socket location, PHP5 still expects /tmp/mysql.sock. In other words, PHP and MySQL are not working out of the box when using MacPorts. At least not when relying on Unix domain sockets. It does work when using Internet domain sockets cause that default port, being 3306, has not changed. Btw, the MacPorts maintainer of PHP and MySQL is one and the same person. Sounds familiar? Yes, I also have been thinking about Dr. Jekyll and Mr. Hyde. No serious. I assume that there is a serious reason why this does not work out of the box as we all wish. I just don’t get it.

dmy

Plesk

written by admin 31 days ago. Last update at 2010-02-25 17:46:31. Categories apache httpd, plesk. Tags , .

Plesk is kind of freaky creature. Working with it can be a frustrating experience. Not when working with the graphical web interface. Used in that way, it’s easy to create/modify/remove sub-domains and other important tasks. However, the guys from Paralles do not expect apache to server something else than static pages. How else can it be explained, that touching a vhost.conf file is something that is described in appendix A, Advanced Features, in the Plesk manual?

So just assume that you have create a new subdomain and you want to make your CSS files available via /css instead of going via some hardwired domain URL. So all you want to have is an alias like

Alias /css "/path/to/my/css/folder"

Ok, but where to enter? When you look at the folder structure and files created by Plesk it is by no means clear what to do. But hey, what are manuals good for anyway? What you discover is that Plesk created a folder like

  /path/to/domain/subdomains/subdomain/conf

for your subdomain. The folder is empty. It would be really great if Plesk would in addition create a README file in that folder. That file would then state something like this:

To configure your subdomain, add herein a file name vhost.conf. Put any Apache configurations in this file you like but be aware that this file is being included in a virtual host definition.

Once you have have added vhost.conf, please reconfigure this subdomain so that your file is taken into account. You do this by

 $ /usr/local/psa/admin/sbin/websrvmng --reconfigure-all

You need to do this only once, because this command does nothing more than insert a Include statement in /path/to/domain/conf/http.include. But refrain from do it manually because websrvmng will rewrite that file from scratch on the next run.

Oh, and btw notice that regardless of what our manual says you can only have a vhost.conf in a subdomain’s conf folder. Any vhost_ssl.conf therein is not taken into account.

Good luck and have a nice day.

Unfortunately, that README file is missing. Unfortunately.

dmy

git-svn article

written by admin 37 days ago. Last update at 2010-02-25 17:46:31. Categories git. Tags , , , .

Working with git-svn without upstream (= subversion) branches is kind of no-brainer. It starts to be a different story when branches are involved. I wrote a rather small article about some experiences and experiments taken with git-svn. Please download this article for reading by following the link(s): PDF. HTML.

dmy

XeTeX: “Failed to convert input string to UTF16″

written by admin 37 days ago. Last update at 2010-02-25 17:46:31. Categories tex. Tags , .

XeTeX allows me to hack away directly in Unicode. But what’s even more cool is that I can just use the fonts installed on my system without diving into some of TeX most darkest corners. However, when I compiled a larger document with xelatex, I faced some strange warnings like

This is XeTeX, Version 3.1415926-2.2-0.9995.2 (TeX Live 2009)
entering extended mode
[..]
** WARNING ** Failed to convert input string to UTF16...

and I had no explanation where this might come from. After a divide-and-conquer debugging session, it turned out that my input was just fine. It was rather a setting that caused this warning:

\hypersetup{
     ..
     unicode=true          %  causes UTF-16 warning
}

After having removed that line, all UTF-16 warnings are gone.

dmy

iSync Plugin

written by admin 41 days ago. Last update at 2010-02-25 17:46:31. Categories macosx.

Uploaded an iSync plugin for the Nokia 2720 (fold) mobile phone. When plugged in, it will become easy to synchronize addresses, events etc. between the mobile phone and your Mac. Just enable Bluetooth on your Mac and on your phone and make sure that they are paired. Then, start-up iSync and add a device. It should find automatically your mobile. Otherwise it will report that your mobile is not supported. Once the device is added, just press the big round button to start syncing.

iSync screenshot with device Nokia 2720 added.

iSync screenshot with device Nokia 2720 added.

The easiest way to install this plugin is by using the nokia-2720a-2.dmg installer package. When being used, the plugin will be installed in folder /Library/PhonePlugins/. To support other installation locations, other package formats have been uploaded as well. To support a private installation, create folder ~/Library/PhonePlugins then download an untar package nokia-2720a-2.phoneplugin.tgz within this folder. Eventually restart iSync and try adding your device again.

dmy

About Reseting CSS Properties

written by admin 105 days ago. Last update at 2010-02-25 17:46:31. Categories webdesign. Tags , .

Designing a layout using HTML/CSS is not a job for the faint hearted. Quit often there is a clash with built-in properties which are not consistent defined in all browsers. This led to the approach of using a style-sheet which resets CSS properties. The style-sheet populated by Eric Meyer, a rather well known CSS styling guru, is for example given here.

Eventually I would like to say that it did not work out for me. All too often I found myself trying to set the default values I have just discarded in my reset.css style-sheet. Ignoring inconsistencies for the moment, the I would like to state that usually all default properties are rather wisely chosen and contain exactly what you want when writing an article, a posting whatever.

Inconsistencies start to matter when designing a website. Then browser inconsistencies can have disastrous effects (like two divs are not side-by-side floated cause they don’t fit in the given width by perhaps just one pixel). However it’s just a small part of the website which needs precision rendering and not the whole website.

So, instead of setting the padding of all divs to be

div { padding: 1px 0; }  /* avoid margin collapsing */

I propose to reset only where it matters:

#header, [..], #footer, #header div, [..], #footer div, #content-main {
  padding: 1px 0; /* avoid margin collapsing */
}

Please notice that divs are reset in all grid elements except within #content-main (supposed to hold your page its informational content). Therein, default values are just fine.

dmy

Forward By Word!

written by admin 165 days ago. Last update at 2010-02-25 17:46:31. Categories admin, bash. Tags , , .

I have to confess that I’m a notorious user of the command line. I do use the command line also on my MacBook Laptop where one of the first actions after having logged in is to open the so called terminal application (Terminal.app, kind of hidden in the Utilities folder). This terminal application is really a step forward compared to xterm or rxvt and is also looking marvelous good.

The hidden gotcha is speed. Where would speed matter you may asking? Well, after having typed in and executed some command, the next command is most often just a minor variation of the previous one. Instead of retyping almost everything again, I let readline’s previous-history function repeat the last (or an earlier) command, move the cursor char-by-char to the desired position where I dare to change something, do the change and eventually execute the command by pushing the RETURN key.

At this point I would like to add a not on the notion used in this small survey about to denote a particular key. Obviously if I mean the key “a” then it’s the small tile on your keyboard with that engraved letter “a”. “A” is bit more complicated cause it is a combination of two “tiles”, namely the “SHIFT” tile and the “a” tile. What you need to do to get the “A” is to hold down tile SHIFT, followed by “a” without releasing SHIFT. So how does the SHIFT key looks like on your keyboard? I have no clue. On my keyboard it’s a tile with a upword-pointing non-filled arrow character. Other keyboard keys of particular importance are the (carriage) RETURN key (originally to move the typewrite’s write position to the line’s beginning), the CONTROL key, the ESCAPE key and usually four navigation keys (usually right and left, up and down).

There must be some convention how to write down a sequence of keystrokes. The one readline uses and which is also being used in this survey is the following: \C means the control key and \e is the escape key. \M is the meta key. I don’t have one on my keyboard, so \e is taking over automatically. Furthermore there are the left and right navigation keys which I’m denoting with <- and ->. Notice that readline does not have a notation for this keys. Instead such a key is represented a key sequence starting with the escape key (\e).

This all works fine except that moving the cursor char-by-char is awfully slow, even in those days with a small super computer right in front of me. It would be really great if I could move forward/backward word-by-word as well. This is of course possible using readline. The function names to do so are forward-word and backword-word.

All fine and well except the default key bindings used for forward/backward word. The standard key binding is \M-f and \M-b. The idea is good. Use \C-f to move forward a char and just switch to the meta key to move forward a word instead. My problem is that I have to press key \e once, then release that key and the press the f key to get the desired effect. That’s much slower than pressing the \C key followed the f key while still holding the \C key. In fact is so much slower that I almost never used the forward move feature. But as I said, forward by char is anoyingly slow.

What I want to do is to assing forward-word with \C--> and backward-word with \C-<-, i.e. I would like to invoke forward-word by holding down the \C key followed by pressing the right arrow (and left arrow for moving backward). This would suite me quite well cause the standard action when pressing the right and left arrow is moving forward or backward a char and this are the keys I’m actually using when moving the cursor (for completness: the up and down arrow move forward and backward in the history).

At this point I had to dig into the documentation to be able to continue:

  1. How to configure readline?
  2. How force bash to re-read the configuration?
  3. How can I see the active bindings?
  4. How can I see the escape characters generated by a key?

The first question is easy. Add or change a (hidden) file named .inputrc right in your home folder. This file is taken into consideration if existing. You can change that setting an environment variable named INPUTRC if you are not happy with the name or the location. In any case, readline will also read the system wide configuration file /etc/inputrc if existing.

Having changed .inputrc, how do I make my terminal application (which runs bash as interactive shell) aware of any changes? You can start a new terminal application (tab or window) or you can type \C-x \C-r in your current one as cheap alternative.

Ok by now, but how can I check the current bindings? When running the bash, use bash’s builtin command bind. For example, you may want to run

% bind -P

to get a relation between readline functions and keys bound to that function. Or you may use bind -p to get a key : function mapping for each function (the output of bind -p would be a valid .inputrc file; it also shows unbound functions – quite useful actually).

Jolly good by now. Except that I have no clue what kind of character sequence is generated by pressing down the right or left arrow key or even what might be generated by additionally holding down the control key (\C). Here another useful readline function, named quoted-insert, comes to rescue. By default, this function gets invoked by \C-v and what it does is, that it inserts the next character you type right there at the cursor’s position.

So you are curious what might be generated by \C followed by holding down the right arrow (->) key? Go ahead and type \C-v \C--> in your terminal and the result on my terminal looks like

$ ^[[5C

Great, now we are almost there. The very last hurdle to overcome is to understand that ^[ is actually the escape key. You can verify this easily using the quoted-insert method explained previously. So what’s left is to add something like this to your local .inputrc and make readline reload that file:

# Make CONTROL - (left arrow) move cursor backward
# one word resp. forward one word
"\e[5D": backward-word
"\e[5C": forward-word

Happy hacking.

dmy

IRB and the missing idiom

written by admin 172 days ago. Last update at 2010-02-25 17:46:31. Categories devel, ruby.

I have recently turned my eye on using Ruby for small and not so small programms. Honestly, Ruby is really exciting and should probably also been listed as one of those things that brings the wow! back on your computer (the other being Apple and Google). Then there’s this book about Ruby, the so called Pick-Axe, wetting my appetite.

The Pick-Axe writes also about irb, the interactive ruby interpreter. So what you can do with irb is to fire it up and hack away some ruby code to give it a try. When you eventually shutdown irb your typed code is gone of course. The book shows lots of such examples.

That’s all fine and good except that using irb this way is bit unrealistic. Actually what I really want to do is to load my ruby project in irb and call methods, create objects, inspect variables etc — without running my project of course. But this is exactly what happens when doing something like

% irb -r 'foobar.rb'

So how to tell irb not to execute my ruby code? Unfortunatly the Pick-Axe is rather silent on this. Here’s how to do it:

if __FILE__ == $0
  # executed if not in irb
  ..
end
Older Posts »