Sunday, May 20, 2007

How to remove the mails from exim mail queue based on certain keywords ( cPanel specific )

How to remove the mails from exim mail queue based on certain keywords, especially in a cPanel. Below command will help in that and is for cPanel server. Matter of seconds for a seasoned admin, but posting so that I can copy and paste in future.

find /var/spool/exim/input -type f | xargs grep -l 'search_keywords' | xargs rm -frv

Wednesday, May 02, 2007

mod_rewrite and REQUEST_URI

Yesterday I did a forum move , a SMF forum. We had to move the forum URL from http://www.domain.com/forum to http://www.domain.com along with moving the servers, but still not losing the links spidered by Google. So things had to be achieved by mod_rewrite and the below rewrite rule helped.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/forum/(.*)$ [NC]
RewriteRule ^forum/(.*)$ /$1 [R=301,L]

What this will do is redirect

http://www.domain.com/forum/index.php?PHPSESSID=0aj813j131434061699fb61eef295f
to
http://www.domain.com/index.php?PHPSESSID=0aj813j131434061699fb61eef295f

Praise the mod_rewrite authors !!!

Tuesday, May 01, 2007

Forcing the files to be downloaded

Many of us have had to face the issue of making an txt file or .php file downloaded instead of the webserver parsing it and the browser displaying it. A simple entry as below in .htaccess and sometimes in your virtualhost section of httpd.conf can get this done.


Header add Content-Disposition "Attachment"

Sunday, April 29, 2007

semget: No space left on device

2 long months of no technical blogging..I have seen and gone through many issues , but hardly remembered about this blog :-(

Situation:

Restarting httpd works for port 80, but fails for 443 (SSL port). I confirmed it with a telnet localhost 443, which returned me connection refused error. Apache error log along with informational messages, was returning me,

semget: No space left on device

Solution :

To understand that is all because of semaphores getting build up and not being cleared properly. So we need to forcefully remove them.

Stop httpd. and issue the following command,

ipcs | grep nobody | awk '{print $2}' > clear.txt
for i in `cat clear.txt`; do { ipcrm -s $i; }; done;


And finally restart httpd. Please note that in the above command I used nobody to grep in ipcs, but in your case it can be apache or www or even www-data. But you know the drill!!!

Tuesday, February 13, 2007

cPanel and XWindows

XWindows dont work once cPanel is installed. Reasons are many why they disabled XWindows on the easy one script installation of cPanel, primary reason being security.

However I needed Xwindows to be running on a cPanel installed machine. Here is what I did.

  1. Edited /etc/rc.local and commented the line /scripts/securetmp
  2. /etc/init.d/xfs start
  3. chkconfig --add xfs
  4. chkconfig --level 2345 xfs on
Rebooted the machine and when came up, mysql service didn't start. Easy guess was /tmp permissions. I checked the permissions and it was 755, changed to 2777 permissions
5. chmod 2777 /tmp
6. Login screen came in and I logged in :-)

lol. That was easy isn't it ? May not be. Sometimes you need to edit the file /etc/X11/xorg.conf as well and search & comment the lines "FontPath "unix/:7100" . Rare cases. But that is a chance.

If you are reading this blog and even after trying these you are not able to get the XWindows working after these work arounds, please comment. I also played around a few more settings before I could get it work. May be I can remember on seeing the error.

Monday, February 12, 2007

Saga of Kernel upgradation - No dep file found

Oh yeah..It was a 1 hour journey to fix the issue. Lovely because I could fix it :-P Day seems bright as well, because I fixed the XWindows in a cPanel installed machine as well, that will explained in the next blog.

Kernel upgradation was of 2.6.19.2 with grsec patch, after the grsec expand_stack vulnerability. Vulnerability was of high severity considering the purpose of grsec patch. So this time, I went for a rpm build. First build was successful, but I missed the elsa patch. Now ELSA , Enhance Linux System Accounting is included in the kernel itself. So built kernel rpm the second time and this time it was oops!!! :-D I love kernel panic oops. Fun begins here..

I realized I went for Uvh instead of ivh. This is the second time I go for Uvh and having kernel panics. Uvh removed all grub entries and old kernels from /boot directory. Gone.

Went to rescue mode, but when I tried to install the kernel it failed with post-scriptlet and pre-scriplet rpm script execution. So rpm installation on rescue mode failed (On a cPanel installed machine, I never was able to do it)

So extracted the rpms using the command rpm2cpio kernel.rpm | cpio -idv . Result was two dirs, boot and lib in my `pwd` .

Copied the files in boot and lib to appropriate directories. I now realize that initrd image is missing. Have to build it.

Normal mkinitrd /boot/initird-2.6.17.img 2.6.17 was erroring out No dep file found for kernel 2.6.17 Fun again. Let's create the dep file now. depmod is the command which will help you here. Command (after a few trial and error) which actually worked was

depmod -ae -F /boot/System.map-2.6.17 /lib/modules/2.6.17
and that worked.
And finally ran the mkinitrd, which did it's job calm and quiet. Kernel booted up in the older kernel and I am happy :-)