Piotras' blog: Archive
2008-04-01 - 2008-04-30
Basics of midgard_dbus
Posted on 2008-04-08 10:55:41 UTC.
midgard_dbus API is very simple, but my approach was to make it just simple as possible. Basically we have two major methods of midgard_dbus:
- constructor, which registers object at path
- send, which asynchronously send message to object at given path
New initialized object doesn't do anything special. It just waits for any call to him and then emits "notified" signal, which you can connect callback to.
I tested simple code with midgard-php and midgard-python.
midgard_python "service":
import dbus.mainloop.glib
import _midgard as midgard
def mbus_callback(object, arg):
print "Hi! I am midgard_dbus from midgard-python. I got message:"
print object.get_message()
mbus = midgard.dbus("/midgard_article")
mbus.connect("notified", mbus_callback, "foo")
mainloop = gobject.MainLoop()
mainloop.run()
midgard-php "client":
$message = "Greetings from midgard-php!(" . mgd_version() . ") PHP ver." . phpversion();
midgard_dbus::send("/midgard_article", $message);
I started php script which immidietialy ended, and on midgard-python service's terminal I got this message:
Hi! I am midgard_dbus from midgard-python. I got message:
Greetings from midgard-php! (2.0alpha0) PHP ver.5.2.5-3
Probably the code will be soon ported to 1-9 branch, so I will be able to test midgard_dbus in Apache environment. But for now, basic idea looks fine and works fine. We just notify objects at path with particular message, and local proccess does the rest with connected callbacks.
MidCOM3 without apache module
Posted on 2008-04-11 14:15:07 UTC.
This is really HOT!
It's proof of concept to work with Midgard without its Apache module. And the concept is cool :) Especially with this lovely MidCOM3 screenshot.

Midgard with Lighttpd
Posted on 2008-04-22 08:05:55 UTC.
Please. Read the whole this simple howto. It's adressed for developers who would like to have Midgard and Midgard2 available as web services on the same machine. Of course, you may still install or compile Apache 1.3 as the second web server.
First of all you need to install and configure Lighttpd web serwer. On debian I installed it using apt-get:
apt-get install lighttpd
Do not forget to stop Apache before installing lighttpd. If you do not, dpkg will return with failure status as lighttpd tries to bind to port 80 by default when package is installed.
Also, you need to have php5 compiled with fast-cgi support. Again, on debian install it quickly:
apt-get instal php5-cgi
Edit cgi's php.ini file (/etc/php5/cgi/php.ini), and add midgard support:
extension=midgard2.so
midgard.configuration="midgard"
midgard.http="on"
Then configure your new web server. I found these two sites very helpful to configue lighttpd server:
Later on, you need to install Midgard2 from trunk, which is going to be released as alpha2 soon.
In my case, I configured lighttpd with these options:
server.port = 81
Just to have both, Apache and lighttpd available. You may of course use different port if you like.
Enable required modules, mod_rewrite and mod_fastcgi:
server.modules = (
"mod_access",
"mod_alias",
"mod_accesslog",
"mod_compress",
"mod_rewrite",
"mod_fastcgi",
)
Configure fastcgi:
fastcgi.server = (
".php" => (
"localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php5-cgi"
)
)
)
Configure virtual host:
$HTTP["host"] == "myhost" {
server.port = 81
server.document-root = "/var/lib/midgard/vhosts/myhost/8080"
url.rewrite-once = ( "^(.*)\.*" => "midgard-root.php" )
}
I use virtual host on 8080 port with Apache, so I wanted to re use its DocumentRoot. You will change it of course, depending on your needs.
midgard-root.php file should be copied or symlinked from midcom's git repository. I do not have to remind that midcom itself should be installed and ready to use.
Do something you should never do in real life. It seems that lighttpd drops root privileges too quickly and php module is loaded with configured user and group privileges. At least I couldn't manage to open root's configuration files from system configuration directory( which is easily done with Apache ). To establish database connection(s) you must have all secret configuratoin readable for the whole world.
chmod 644 /etc/midgard-2.0/conf.d/*
After this, restart lighttpd:
/etc/init.d/lighttpd restart
And open http://myhost:81 with your favourite browser. If all went fine, you should have midcom's web page without style. Reason is that we do not make midcom-static exception in our hosts' rewrite condition.