Archive for the ‘System Administration’ Category

Best Thing Today

Wednesday, March 10th, 2010


-bash-2.05b# screen -x

Suddenly the Dungeon collapses!! - You die...

Telenor Internet Ubuntu Karmic Koala

Saturday, January 30th, 2010

I got a new laptop (asus ul30a) :) and I figured I need to have internet on the go

wimax is not an option (not available) so I chose cell usb modem from Telenor
data plan is prepaid, 3 GB for two months (a new year promotion that ends tomorrow)

I thought I was getting Huawei E1550 but I ended up with Huawei E620 ;)
that modem is not on their website (listed usb modems) nor in the manual I got with the thing
the manual talks about Huawei E1550

now why do I care so much about exact models? well because modem should run on my linux box
I saw Huawei E220 was well supported and Huawei E1550 had some glitches but could be made to work

first I used usb modem in Windows so that the autorun process can install device drivers
that’s just how it works the first time

in linux, I first installed usb-modeswitch package

lsusb wrote that it was Huawei E620 with id 12d1:1001

but after searching for that ID I found references to Huawei E169 with that same id?!

on the plus side ubuntu Network Manager Applet works great with this modem
I defined a new connection, specified my country and mobile network provider and it just worked! :)

Spamassassin 2010 Bug

Saturday, January 2nd, 2010

it seems Spamassassin has a bug related to year 2010

the problematic rule is FH_DATE_PAST_20XX

just find 72_active.cf file and replace ‘/20[1-9][0-9]/’ to for example ‘/20[2-9][0-9]/’

now, the problem year is 2020 but by then your file will probably get overwritten by your distribution

you can put whatever number instead of 1, not just 2 and make it work longer

or simpler, edit your local.cf and set this rule to have zero score

score FH_DATE_PAST_20XX 0.0

once your distribution fixes this just remove local.cf entry

OpenSolaris Summer School @ Belgrade, Serbia

Tuesday, July 7th, 2009

the school is held at the Institute Of Physics, Belgrade for the month of July, two times a week

today, Uros Nedic, the guy doing the lecture, arrived a bit late but I managed to find a beautiful park behind the institute with a great view of the Danube river :)

I had a nice time today

we were learning about Sun OS processes, threads, LWM, kthreads, DTrace, Zones and ZFS

Uros was great while teaching us/giving a lecture, answered all of our questions

I learned a lot

now, here are some pictures I took with my mobile phone, sorry for the bad quality

Cpanel Issues

Wednesday, May 27th, 2009

I got this dedicated box to setup and I’ve found 2 problems right away

first, I couldn’t update cpanel to latest stable because one perl module, NetAddr::IP wouldn’t install

the problem was, a configure script had a malformed first line #! /bin/bash (notice the extra space after the ! character)

that got fixed

now, I have problems with cpanel license when I reboot, it says license is not valid

I have to run /usr/local/cpanel/cpkeyclt to get it fixed

I’ll report it to them but I could also easily just add it to rc.local ;)

don’t get me wrong, I still really like cpanel but I hate issues when dealing with a new box ;)

Dynamic DNS Iptables Firewall Script

Thursday, October 9th, 2008

I’m using my computer as a development platform and I usually let people in by editing my firewall active table

but for those with dynamic ip addresses I had to figure out a different solution

so I made a small script in PHP to check for my friends dynamic ip address by looking up his dyndns.org hostname

it checks IP then goes sleeping for 5 minutes

when it detects an ip change it updates firewall by flushing my firends chain and adding a rule to let him access my webserver

this script works in my firewall iptables setup, it could work on yours but you have to be smart and figure that out for yourself, I’m not giving any guaranteess for this, use it as GPL V3 code :)
if you want me to help you set it up, just contact me

here’s the code:

#!/usr/bin/php
<?php
/*
use this code as GPL V3 licence says
Copyright (C) 2008, Miroslav Madzarevic, All Rights Reserved
*/
$old_ip = '';

while (1) {

    sleep (300);

    $host = 'friend.dyndns.org';

    if (!preg_match('/^'.$host.' has address ((?:\d{1,3}\.){3}\d{1,3})$/',
           exec ("/usr/bin/host $host"), $matches)) {
        echo "IP problems\n";
        continue;
    }

    $ip = $matches[1];

    $ip_parts = preg_split ('/\./', $ip, -1, PREG_SPLIT_NO_EMPTY);

    if (count($ip_parts) != 4) {
        echo "wrong ip parts count\n";
        exit;
    }

    $good = array();

    foreach ($ip_parts as $ip_part) {
        $ip_part = (int) $ip_part;
        if ($ip_part < 1 or $ip_part > 254) {
            echo "wrong ip part, $ip_part\n";
            exit;
        }
        $good[] = $ip_part;
    }

    $new_ip = join('.', $good);

    if ($old_ip != $new_ip) {

        `/sbin/iptables -F friend`;

        `/sbin/iptables -A friend -s $new_ip/32 -p tcp -m tcp --dport 80 -j ACCEPT`;

        $old_ip = $new_ip;
    }
}

?>

fastcgi mod_fcgid

Wednesday, October 1st, 2008

I’ve been playing a little on my cPanel hosting trying to get maximum speed while also enforcing security at running php scripts

I first started with security running mod_suphp and while it worked fine it lacked the speed of the DSO php (mod_php)

so I read a thing or two about fastcgi and enabled it

I’m pleasantly surprised by the speed of the hosting

each user got its own persistent php application running requests (actually it’s limited to 500 php requests per php5 process by MaxRequestsPerProcess 500 directive)

I’m keeping an eye about the memory consumption but I hope I’ll be able to keep running with this setup

and while I got php running as the actuall cPanel user, apache is still running as nobody for other requests… hmmm… I’m using apache 2.2 with MPM Prefork… maybe I should try a different MPM?

C++ Hibernate Daemon

Wednesday, April 30th, 2008

I use Fluxbox window manager on Ubuntu Linux where I don’t have all the bells and whistles of GNOME or KDE.

so I thought I’d make myself a daemon program that will automatically put my computer to hibernate when my laptop battery is almost empty

usually I take care that my battery doesn’t get to the red zone but this is for those few cases I forget

I wrote this small programm in C++

why c++

well because I don’t programm in c++ and I found it interesting to do so :)

main.cpp looks like this

so, you see the locations of the info and state file for the laptop battery, the percent at which we go to hibernation (I’ve set it to 12%), and the sleep interval before checking the battery state again (10 seconds)

I use my own hibernate script but you could use something like /usr/sbin/hibernate

you can change all of these

in the main function you can se that:

  • we work only as a root user
  • we daemonize (detach from the terminal and run in background)
  • instantiate a worker class object
  • and do our work :)

and what is our work? check out this picture

worker.cpp

well we get the battery total capacity and current capacity and then we calculate the percent

if the percent is less that what I want (12%) then I want my laptop to go to hibernaton

but I also made a security check (that you can remove if you like)

that makes sure my laptop doesn’t go twice into hibernation in succession

why did I do that?

well because I parse data from some files I have no influence over

and those files can change their format anytime

so this is just a precaution

I have a simple makefile that compiles this code, copies it to /usr/local/bin/medved (medved in my language means a bear and bears hibernate ;) ) and adds an entry to /etc/rc.local so that it starts next time you reboot your box automatically

you can also start it by hand and see how it works before the reboot

and that’s it, now I have a daemon that puts my laptop to hibernation before my battery runs dry

I’ve published the source code under GPL licence version 3

you can get source code here

NFS

Tuesday, January 8th, 2008

It’s so easy to setup NFS server. I needed NFS so I could export my OGG files to my dbox.

I’m runing Ubuntu.

Here are the commands

root@warlock:/etc# apt-get install portmap nfs-kernel-server

After that, I had to edit my /etc/exports file

root@warlock:/etc# cat /etc/exports
/exports dbox(ro,sync)

And now, whenever I change the contents of /etc/exports I need to do exportfs -ra

Zabbix

Monday, December 31st, 2007

Zabbix is a network monitoring solution. I used to play with Nagios but I find Zabbix a better product. Simpler to install, easier to use, better web interface.

Zabbix works in a client/server mode. Client is called an agent ;) so on each box you want monitored you install the agent. The server gets installed either with mysql or with postgresql database support. I opted for mysql. The install was done on my laptop Ubuntu. I had some problems early on since my server didn’t see my client.
This was because of the server or client settings that I changed. Since installing both products I noticed a lot of forks/threads in the process list and I wanted to cut down the number of those by editing a config file.
Don’t do that, Zabbix doesn’t like that ;)

Now I got 25 Zabbix instances in my process list

root@warlock:/tmp# ps aux|grep zabbix|grep -v grep|wc -l
25

Anyway, Zabbix looks nice. I can monitor everything related to how my box functions. I had to clone 2 eth0 rules (incoming and outgoing) and make it work for my wireless network. I just changed eth0 to ath0 both times after cloning.

I have to figure out how to send daily reports to my email :)