How to find zombie processes on linux

My NAGIOS monitor alerted me that of my dedicated server has 10 Zombie processes, how to find Zombie processes via command line on Linux especially CentOS?

 ps aux | awk '{ print $8 " " $2 }' | grep -w Z 

So it returns state (Z = Zombie) and the process id (PID)

root@sirius [~]#  ps aux | awk '{ print $8 " " $2 }' | grep -w Z
Z 4399
Z 4435
Z 4868
Z 5143
Z 5400
Z 5834
Z 7584
Z 11943
Z 16286
Z 24365

Technically, you cannot kill a zombie process since its already dead but the entry in the process table is not removed because the parent will access the result via the PID in the process table.

Routing a root domain / zone apex / naked domain to Amazon S3

Even though the sound of hosting a static website entirely out of Amazon s3, it has a catch. You can only host subdomains there (including www.example.com, cdn.example.com, images.example.com etc assuming your primary domain name is example.com) but not “apex domain” like example.com

I had an idea of redirecting the example.com traffic to one of my VPSes and then redirecting via .htaccess or PHP to www.example.com at which point www is already hosted on s3

Just to double check, I posted the question online and got a reply from D. Svanlund who pointed me out to an awesome time-saver service still in beta called ARecord.net. They are right when they say Zone Apex issue on Cloud.

How to find specific files and send alerts

Maintaining a shared hosting server is a full time job but tools and proper checks and balances can help make this burden lot less. I manage a shared hosting server for one of my friends and numerous times the scripts that people have installed over on their websites have vulnerabilities and hackers exploit it to upload stuff that mass-email or do other nasty stuff. Luckily, most of these exploits have common patterns like files names or other signatures that make them traceable (most of the time the so called hackers are just kiddy scripts)

Create a file and put this in it

#!/bin/bash
find /home -name 'paypal.com*' | mail -s '[Woodcrest] Phishing Alert!' me@mydomain.com
find /home -name 'rout.php' | mail -s '[Woodcrest] Phishing Alert - Mail Bomber!' me@mydomain.com

This is a small script that finds specific named scripts in the /home directory (mostly cPanel servers). You can put this in the crontab to do a scan every x hours or so.

Have any questions or comments? feel free to post them below!

package-cleanup: command not found

I tried to do package-cleanup and found this

root@ns1 [~]# package-cleanup --problems
-bash: package-cleanup: command not found

If I was on Ubuntu, I would have done “apt-get install package-cleanup” but it does not work that way on CentOS, its actually available in yum-utils package, install it by typing

yum install yum-utils

Enjoy!!

How to disable SELinux

SELINUX is a security feature on CentOS but some software such as SolusVM will require that SELINUX be disabled

Installation log : /tmp/install.log

 Add this slave to your SolusVM master using the following details:

 ID Key .......... : ABC
 ID Password ..... : XYZ

IMPORTANT!! You need to setup a network bridge before you can use KVM on this server.
 Please see the following link: http://wiki.solusvm.com/index.php/KVM_Network_Bridge_Setup

 Please set SELINUX=disabled in /etc/selinux/config before rebooting.


Thankyou for choosing SolusVM.

The solution?

1) Edit /etc/selinux/config using your favourite editor

[root@kvm ~]# nano /etc/selinux/config

and set SELINUX=disabled

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

2) and don’t forget to reboot your system

CentOS minimal template’s issue with crontab

On my CentOS 5.x 64bit XEN PV template (XEN PV is a virtualization type, this means I am talking about a VPS) doing ‘crontab -e’ gave me the following error

[root@vpsadmin ~]# crontab -e
no crontab for root - using an empty one
/bin/sh: /bin/vi: No such file or directory
crontab: "/bin/vi" exited with status 127

To correct this issue, do the following

[root@vpsadmin ~]# touch ~/.bashrc
[root@vpsadmin ~]# export VISUAL=nano
[root@vpsadmin ~]# source ~/.bashrc

So, now if you do ‘crontab -e’ it will work as it should

[root@vpsadmin ~]# crontab -e
no crontab for root - using an empty one
crontab: no changes made to crontab

Ubuntu – Unable to load dynamic library ‘/usr/lib/php5/20090626+lfs/sqlite.so’

The other day, I was getting this weird error

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/sqlite.so' - /usr/lib/php5/20090626+lfs/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0

Fix it by doing this

root@beta:~# rm -fr /etc/php5/conf.d/sqlite.ini

Because this extension does not exist, you can verify it by running this, you will see that there is already sqlite3.ini file there

root@beta:~# ls -lh /usr/lib/php5/20090626+lfs/ | grep sqlite

vzfree utility to check memory usage in OpenVZ VPS

From the official blog post

Gee. It has been a while since I’ve last written here, and it will be a while again for my next post as I will be on holidays from next Monday (visiting families in Hong Kong and Taiwan). Let me share one small utility program that I wrote quite a while ago.

We all know that the Linux command free(1) is pretty useless inside an OpenVZ VE, even those with meminfo virtualised. So I basically wrote this little util to grab the data from the dreadful user_beancounters and format them into something useful. It’s written in C and only depends on libc so it’s pretty light weight. It also does a little bit of analysis instead of just dumping the data, which I will explain later on.

Continue reading