open thought and learning

Archive for July 2008

My mod_python 101

leave a comment »

After having built mod_python.so and doing a LoadModule modules/mod_python.so I expected everything to work fine, assuming I did a SetHandler python-program and a PythonHandler helloworld within an Apache virtualhost.

I could get Hello World! on the page then, with this following snippet:

$cat helloworld.py
from mod_python import apache
def handler(req):
req.content_type = “text/plain”
req.write(”Hello World!”)
return apache.OK

That’s when the problems began.

1. I couldn’t put in another .py file in the same directory that could run successfully – 404 returned
2. All HTML files returned a 404 as well
3. There was nothing on the error logs

After much reading around, here’s the final configuration that worked:

LoadModule modules/mod_python.so
PythonDebug On
AddHandler python-program .py
PythonHandler mod_python.publisher
PythonPath "['/appl/python2.5/lib/','/appl/webdocs/','/appl/python2.5/bin/python/','/appl/python2.5/lib/python2.5/site-packages/mod_python/','/appl/python2.5/lib/python2.5/site-packages/'] + sys.path"

And the URL that worked was http://myhost/helloworld.py/handler

Apparently, mod_python (also) has three kinds of default handlers – cgi, publisher and PSP.

cgihandler – to work with existing CGI scripts by creating a false environment
psp – Python Server Pages, just like JSP
publisher – The preferred way to handle python pages, using page/method

publisher is recommended for newer applications, and as you move forward and your application increases in complexity and entry points, you can make your own handlers.

Like I said, 101 and basics, but what the heck, I get to write something here. Itchy fingers.

More later.


Written by mohitsuley

July 31, 2008 at 1:28 am

Posted in code, linux

Tagged with ,

Automator on Google Code

leave a comment »

Finally, I have a home for Automator on Google Code at sysadmin-automator. I will start uploading existing scripts tomorrow.

Written by mohitsuley

July 27, 2008 at 3:56 am

Posted in linux, sysadmin

Tagged with ,

Sysadmin Day

leave a comment »

I never knew sysadmins had a day all for themselves. The legendary BOFH now get to have all the fun and the appreciation as well. Cheers to us!

Written by mohitsuley

July 25, 2008 at 5:33 pm

Posted in sysadmin

Tagged with ,


leave a comment »

I have finally been able to create a project on sourceforge for that pet project of mine – Automator.

It all started with my irritation at having to execute the same commands over a number of servers, most of the times during the day. Unfortunately, webmin was not much of an option – I don’t prefer it too much because of it’s highly invasive nature. Moreover, I should have the ability to run a script over a group of servers that I know belong to an application or a tier. For that matter, if today, I wanted to sync all my linux servers from a specific NTP server *manually*, I should ideally execute a command whose pseudocode might look like:

execute on all servers that have OS as linux

So, beginning with this concept, I realized this was not much of a technical feat. It actually was the cumbersome task of ‘documenting’ what each server constituted right from the very beginning and then using this information during my day-to-day tasks.

Let’s say there’s an application called WORDPRESS which has three tiers – DB, WEB and APP and also has three separate set of servers each for DEVelopment, STAGE and PRODuction (that’s how big companies work, you know). To add to it, there are servers across the world, but this particular application actually is in a data-center in NYC. Now, using this information (and much more that can be collected automatically from each server, like, OS, architecture), I should be able to know what servers to work on.

In a nutshell, this is what automator might work like:

mohit@test$auto-command -g WORDPRESS-PROD-WEB -c ntpdate ntp.timeserver.com

This will run ntpdate on all WordPress production web servers. Neat! But how do you bell the cat? The only way I have been able to figure out is during initial handover of the box. Every organization that manages more than a hundred servers has a process in place which has a team ‘audit’ the server and run scripts in order to configure default services before it is handed over to the customer. This is when we can run our own ‘automator service registration’. All you do is connect to the remote server, push your script, run it remotely and then grab some data automatically and of course manually (like environment, name of application etc) and store it in a MySQL database.

I have this working using a system of bash shell scripts. But with time, modifications and the sheer number of servers that I manage, I am moving this over to Python/MySQL. But yes, I’d like to keep it simple – just as a command line interface with a very basic framework that other SAs can use to build their own scripts when they include the package.

Let’s see how far this idea goes.

Written by mohitsuley

July 24, 2008 at 5:36 am

Posted in linux, sysadmin

Tagged with , ,

Blogging from the iPhone

leave a comment »

Thanks to the RSS feed from medialets , I found out the WordPress app for the iPhone finally made it to the store.

And it works well too. I’ll take this as my inaugural post on vyatta.



Written by mohitsuley

July 22, 2008 at 5:15 pm

Posted in misc

Tagged with

Hello world!

with one comment

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Written by mohitsuley

July 21, 2008 at 2:45 am

Posted in misc