Setup WordPress Subversion in Mac

Well, it has been sometimes since i updated this blog actually. In fact, it has been terribly long that i updated some of my plugins (2 years to be exact). I've been busy with setting up Yii framework couponic site and modifying the system as much as possible till i lost track of time. Since i get the time to breath today, i might as well update my plugins. However, i've already forgotten how to do it. Moreover, i am currently using a Macbook air which really gives me zero idea how to connect to my wordpress plugin subversion repository. But i managed to do it anyway and just thought of writing it down a quick tutorial.

For anyone who forgotten how to connect to the repo, here is how you do it. Firstly, you will need a subversion client a.k.a svn client. For windows, you have tortisesvn where you can find the tutorial i wrote two years ago. For Mac, i use versionapps (only 30 days trial :(). Download it and start installing. Once, it is installed, fire up your version apps.  You will be asked for the following few items

The username and password would be your wordpress plugin details. For the location url, just visit your WordPress plugin and click on the tab "Admin". Within there, there is a link call "SVN Repo" as shown below,

You should see the link as shown below,

copy it and pass it into the sub repo and you are done.

Now, just checkout your repo and start doing work! xD

Setup Dell Openmanage on Centos 5.5 with Nagios check_openmanage plugin

Another tutorial that i wish to keep in mind before i need to do research again whenever i setup a new server.Basically for all dell server, you will most likely will like to setup Dell Openmanage software in your Linux server. The reason is pretty simple, Dell openmanage allows you to monitor almost every hardware in your server which can really benefit you a lot whenever some hardware fails.

Anyway, here we go. Firstly, we will need to setup openmanage into my centos 5.5 server. The shortages road to prevent pain is just to key in the following command.

wget -q -O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash
yum install srvadmin-all -y

P.S: if you see Missing Dependency: perl(LWP::UserAgent) error, please try to go into your /etc/yum.conf to see whether any repo is disabled!

The above command will install dell openmanage for you in centos 5.5. Next you will pretty much need to start dell openmanage service before nagios can do any checking on it. Fire up the following command to start or stop dell openmanage service.

/opt/dell/srvadmin/sbin/srvadmin-services.sh start
/opt/dell/srvadmin/sbin/srvadmin-services.sh stop

There are also other commands such as enable|disable|help|start|stop|restart|status. Once your Dell Openmanage is successfully installed and started. We will have to install one of nagios check_openmanage plugin. Here are the steps to install check_openmanage.

wget "http://folk.uio.no/trondham/software/files/nagios-plugins-check-openmanage-3.7.2-1.el5.x86_64.rpm"
rpm -ivh nagios-plugins-check-openmanage-3.7.2-1.el5.x86_64.rpm

then go to your server nrpe.cfg folder located at /usr/local/nagios/etc/nrpe.cfg and add the command below

command[check_dell_storage]=/usr/lib64/nagios/plugins/check_openmanage --only storage
command[check_dell_fans]=/usr/lib64/nagios/plugins/check_openmanage --only fans
command[check_dell_memory]=/usr/lib64/nagios/plugins/check_openmanage --only memory
command[check_dell_power]=/usr/lib64/nagios/plugins/check_openmanage --only power
command[check_dell_temp]=/usr/lib64/nagios/plugins/check_openmanage --only temp
command[check_dell_cpu]=/usr/lib64/nagios/plugins/check_openmanage --only cpu
command[check_dell_voltage]=/usr/lib64/nagios/plugins/check_openmanage --only voltage
command[check_dell_batteries]=/usr/lib64/nagios/plugins/check_openmanage --only batteries
command[check_dell_amperage]=/usr/lib64/nagios/plugins/check_openmanage --only amperage
command[check_dell_intrusion]=/usr/lib64/nagios/plugins/check_openmanage --only intrusion
command[check_dell_sdcard]=/usr/lib64/nagios/plugins/check_openmanage --only sdcard
command[check_dell_esmhealth]=/usr/lib64/nagios/plugins/check_openmanage --only esmhealth
command[check_dell_esmlog]=/usr/lib64/nagios/plugins/check_openmanage --only esmlog
command[check_dell_alertlog]=/usr/lib64/nagios/plugins/check_openmanage --only alertlog
command[check_dell_critical]=/usr/lib64/nagios/plugins/check_openmanage --only critical
command[check_dell_warning]=/usr/lib64/nagios/plugins/check_openmanage --only warning

Then your monitor server should be able to pick up the instruction and start monitoring your dell hardware 🙂

How to resend username and password to user in WordPress using retrieve_password function

Well, there are no such method where you can resend your existing user a reset password from your side. they must actually click on the "lost password" link and fill up the form in order to retrieve the activation email to reset their password. The method was retrieve_password() which is located in wp-login.php. Hence, you won't be able to use this method and even if you can, you will need to post it over from a form in order to utilized this method. The most easiest way to reuse this method is to recreate it by removing certain condition so that it makes life easier for you.

In my case, my system already has the user email addresses. Hence, all i need to do was to remove the checking for email address and start sending verification from the user whether they wish to reset their password.

/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password($user_email) {
	global $wpdb, $current_site;

	$errors = new WP_Error();

	// redefining user_login ensures we return the right case in the email
	$user_login = $user_email;

	do_action('retreive_password', $user_login);  // Misspelled and deprecated
	do_action('retrieve_password', $user_login);



	$key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login));
	if ( empty($key) ) {
		// Generate something random for a key...
		$key = wp_generate_password(20, false);
		do_action('retrieve_password_key', $user_login, $key);
		// Now insert the new md5 key into the db
		$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
	}
	$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
	$message .= network_site_url() . "\r\n\r\n";
	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
	$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";

	if ( is_multisite() )
		$blogname = $GLOBALS['current_site']->site_name;
	else
		// The blogname option is escaped with esc_html on the way into the database in sanitize_option
		// we want to reverse this for the plain text arena of emails.
		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

	$title = sprintf( __('[%s] Password Reset'), $blogname );

	$title = apply_filters('retrieve_password_title', $title);
	$message = apply_filters('retrieve_password_message', $message, $key);

	if ( $message && !wp_mail($user_email, $title, $message) )
		wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') );

	return true;
}

The above method take in an email address and send out the email to the user to request a reset of password. You can change the message to your liking but you will need to know the user password in order to use this method. Hope it helps.

Nagios Monitoring Server + Nagios Monitored Servers + MySQL Setup

Strictly speaking, this is not an article i wrote myself. I am here simply combine this up for my conveniences and for people who visited this blog [ there are just too many article flying around for me to search each time 🙁 ]. I am using Centos 5.5

Easy way to install Nagios

Apparently there is a simple way via yum

yum install epel-release
yum install nagios nagios-devel nagios-plugins* gd gd-devel httpd php gcc glibc glibc-common

Above will install all nagios required plugins and the only thing you will need to do is to install apache to get it up.

Installing Nagios on the Monitoring server

Please refer to the quick installation guide at http://nagios.sourceforge.net/docs/3_0/quickstart-fedora.html

Nagios Monitoring Server

Downlad and Install NRPE Plugin

# mkdir -p /opt/Nagios/Nagios_NRPE

# cd /opt/Nagios/Nagios_NRPE

Save file to directory /opt/Nagios

http://www.nagios.org/download/download.php

As of this writing NRPE 2.12 (Stable)

Extract the Files:

# tar -xzf nrpe-2.12.tar.gz

# cd nrpe-2.12

Compile and Configure NRPE

# ./configure

# make all

# make install-plugin

Test Connection to NRPE daemon on Remote Server

Lets now make sure that the NRPE on our Nagios server can talk to the NRPE daemon on the remote server we want to monitor. Replace “” with the remote servers IP address. Please take note that must be a remote IP address that you wish to monitor. At this point of time, you may not have any such server. Hence, you can skip this if you wish to.

# /usr/local/nagios/libexec/check_nrpe -H
NRPE v2.12

Create NRPE Command Definition

A command definition needs to be created in order for the check_nrpe plugin to be used by nagios.

# vi /usr/local/nagios/etc/objects/commands.cfg

Add the following:

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

Create Linux Object template

In order to be able to add the remote linux machine to Nagios we need to create an object template file adn add some object definitions.

Create new linux-box-remote object template file:

# vi /usr/local/nagios/etc/objects/linux-box-remote.cfg

Add the following and replace the values “host_name” “alias” “address” with the values that match your setup:

** The “host_name” you set for the “define_host” section must match the “host_name” in the “define_service” section **

define host{
          name                  linux-box-remote             ; Name of this template
          use                   generic-host          ; Inherit default values
          check_period          24x7
          check_interval        5
          retry_interval        1
          max_check_attempts    10
          check_command         check-host-alive
          notification_period   24x7
          notification_interval 30
          notification_options  d,r
          contact_groups        admins
          register              0          ; DONT REGISTER THIS - ITS A TEMPLATE
          }

define host{
          use       linux-box-remote     ; Inherit default values from a template
          host_name Centos5    ; The name we're giving to this server
          alias     Centos5 ; A longer name for the server
          address   192.168.0.5   ; IP address of the server
          }

define service{
          use                 generic-service
          host_name           Centos5
          service_description CPU Load
          check_command       check_nrpe!check_load
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Current Users
          check_command       check_nrpe!check_users
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description /dev/hda1 Free Space
          check_command       check_nrpe!check_hda1
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Total Processes
          check_command       check_nrpe!check_total_procs
          }
define service{
          use                 generic-service
          host_name           Centos5
          service_description Zombie Processes
          check_command       check_nrpe!check_zombie_procs
          }

Activate the linux-box-remote.cfg template:

# vi /usr/local/nagios/etc/nagios.cfg

And add:

# Definitions for monitoring remote Linux machine
cfg_file=/usr/local/nagios/etc/objects/linux-box-remote.cfg

Next you will need to add nrpe onto your command list.

[root@ns ~]# vi /etc/nagios/objects/commands.cfg

# add at the bottom
define command{
command_namecheck_nrpe
command_line$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

this will allow you to use the command check_nrpe.

Verify Nagios Configuration Files:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0

Restart Nagios:

# service nagios restart

Check Nagios Monitoring server that the remote linux box was added and is being monitored !

Nagios Monitored Server

This is the setting for ALL of your monitored servers (Server that you want to be monitor by the central monitoring server)

Firstly, install the required package.

yum install gcc glibc glibc-common gd gd-devel openssl-devel make

Setup the users

Just setup nagios as a user to execute all nagios instruction later

useradd nagios
passwd nagios

add your own password.

Download and Install Nagios Plugins

go to your src folder and download all the required nagios stuff which is nagios plugin and nrpe. Both plugin and nrpe is located at http://www.nagios.org/download/download.php. find the link and wget it like i show below.
here's the link of the two nagios required plugins

  • http://www.nagios.org/download/plugins/
  • http://exchange.nagios.org/directory/Addons/Monitoring-Agents/NRPE-%252D-Nagios-Remote-Plugin-Executor/details
cd /usr/local/src/
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

Once download is completed, tar both files

tar xzf nagios-plugins-1.4.15.tar.gz
tar xzf nrpe-2.12.tar.gz

Compile and Configure Nagios Plugins

We will need to install the openssl library before installing them

yum install -y openssl-devel

Once you install and tar both files, its time to install them.

cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
chown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexec

Now, we will need to install xinetd to ensure it is secure.

yum install -y xinetd

Next, we will need to configure xinetd to allow certain port and nrpe.

Install NRPE Daemon

Time to install NRPE Daemon!

cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd

We will need to confiure xinetd now.

Post NRPE Configuration

Edit Xinetd NRPE entry:

Add Nagios Monitoring server to the "only_from" directive

vi /etc/xinetd.d/nrpe

find only_from directive and add your nagios monitoring server ip address so that the monitoring server can access your monitored server.

only_from = 127.0.0.1

Edit services file entry:

Add entry for nrpe daemon

vi /etc/services

add nrpe into the list.

nrpe      5666/tcp    # NRPE

lastly restart the service and make it start on boot time.

chkconfig xinetd on
service xinetd restart

Open Firewall port for NRPE

Next, we will need to open up the firewall

vi /etc/sysconfig/iptables

add 5666 to your whitelist

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5666 -j ACCEPT

Its time to test!

Test NRPE Daemon Install

Check NRPE daemon is running and listening on port 5666:

netstat -at |grep nrpe

Output should be:

tcp    0    0 *:nrpe    *.*    LISTEN

Check NRPE daemon is functioning:

/usr/local/nagios/libexec/check_nrpe -H localhost

Output should be NRPE version:

NRPE v2.12

Monitoring MySQL Server With Nagios

Nagios Ping /bin/ping Unknown status problem

This is simply a permission problem caused by the script /bin/ping. Hence, all you need to do is the following,

chmod u+s /bin/ping

After a while, nagios should be able to ping your server ip.

TroubleShooting

NRPE ./configure error:

checking for SSL headers… configure: error: Cannot find ssl headers

Solution:

You need to install the openssl-devel package

# yum -y install openssl-devel

CHECK_NRPE: Error – Could not complete SSL handshake

Solution:

This is most likely not a probem with SSL but rather with Xinetd access restrictions.

Check the following files:

/etc/xinetd.d/nrpe

/etc/hosts.allow

/etc/hosts.deny

no acceptable c compiler found in $PATH

When I gave the ./configure command i got this error saying: no acceptable c compiler found in $PATH and then it stops.

After a quick google search I found a topic saying that i needed to install gcc so i entered:

yum install gcc glibc glibc-common gd gd-devel

Hope it helps, you if need any web hosting solutions or have any question, feel free to pm me 🙂

Move cpanel mysql to other directory safely

This is also for my personal need in the future whenever i setup a cpanel server for my TWOPIZ HOSTING. There is a way to move mysql to other directory other than the one defined by cpanel. Firstly, you will need to backup everything on /var/lib/mysql folder. Once you have done that, you will have to follow the below instruction.


cd /var/lib
service chkservd stop
service mysql stop
mv mysql /home
ln -s /home/mysql mysql
service mysql start
service chkservd start

The backup apps will still work normally as the mysql folder still exist on /var/lib just that now it is pointing to the /home directory where the size is the largest.