Configure monitoring in Linux for a MegaRaid controller

In Linux, monitoring for a MegaRaid controller can be done using MegaCLI tools.

Some prerequisites for it are required, let’s install them.

For Debian like systems:

apt install mailutils postfix libncurses5 alien vim unzip wget

For CentOS like systems:

yum install mailx postfix ncurses-devel vim unzip wget

Then let’s download MegaCLI sources, extract, install it and clean-up.

For Debian like systems:

cd /opt
cd Linux
alien MegaCli-8.07.14-1.noarch.rpm
dpkg -i megacli_8.07.14-2_all.deb
cd ..
rm -rf 8.07.14_MegaCLI.txt DOS/ FreeBSD/ Linux/ Solaris/ Windows/

For CentOS like systems:

cd /opt
cd Linux
rpm -i MegaCli-8.07.14-1.noarch.rpm
cd ..
rm -rf 8.07.14_MegaCLI.txt DOS/ FreeBSD/ Linux/ Solaris/ Windows/

Create a link for easier access:

ln -s /opt/MegaRAID/MegaCli/MegaCli64 /bin/megacli

Check the actual status for disks:

/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert"

Normally it will indicate “Drive has flagged a S.M.A.R.T alert : No” for each disk.

Create the script for monitoring:

vim /opt/

Put the content:

set -ex
RESP=$(/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert")
SUBJ="RAID status on"
echo "$RESP" | mail -a "From:" -s "$SUBJ"

Make the script executable:

chmod 700 /opt/

Add a cronjob to execute the script periodically:

crontab -e

First time when you edit the crontab it will ask to choose an editor, choose 2 and hit Enter:

Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/mcedit
4. /usr/bin/vim.tiny

Choose 1-4 [1]: 2

For me it was enough to get an update daily (at 12:04 AM):

4 0 * * * /bin/sh /opt/

But it can be easily updated to notify only in case of issues:

set -ex
RESP=$(/bin/megacli -PDList -aALL |grep "Drive has flagged a S.M.A.R.T alert")
SUBJ="RAID status alert"
if [[ "$RESP" == *"Yes"* ]]; then
echo "$RESP" | mail -a "From:" -s "$SUBJ"

Set the crontab to run it every minute:

* * * * * /bin/sh /opt/

Granting user permissions for a PostgreSQL database

If you need to manage databases and permissions for a PostgreSQL server, you can use a WEB, a Desktop or a command line client. I used pgAdmin for WEB and Desktop access.

A PostgreSQL database have an owner. I got an error setting permissions for other users being connected as different user (with root privileges), if you get too – try to grand permissions as database owner!

A databases can contains multiple schemes, each of them contains tables.


Setting connection permissions

First of all you have to grant CONNECTION permissions to the database:


Then you have to grant permissions per schemas and tables.

Grant permissions only for existing tables in a schema

  1. Grant USAGE permissions per schema:
    GRANT USAGE ON SCHEMA public TO xxx;
  2. Grant SELECT permissions per table:
    GRANT SELECT ON mytable TO xxx;

Grant default permissions for all tables


How to properly migrate a WordPress site


WordPress store URLs of the pages, articles, media and all other content in database as absolute paths.

This mean that you need to update URLs when the site address changes, the simple database copy may lead to errors or increased load time, because of increased number of load requests.

For a proper migration, you have to copy the files to the new location and migrate the database. To copy the files you can use the hosting panel File Manager (if available), FTP or SSH. For the database migration – check the instructions bellow.


This article cover the following situations:

  • Migration to a new domain;
  • Migration of the site form some dev location to a production one;
  • Switching the site from HTTP to HTTPS;
  • Switching the site from www to non-www, or from non-www to www;
  • Sometime it may be required for migration from one hosting environment to another, even if the domain is not changed (but the location path changes).

Database migration

You can find a lot of instructions on the internet that will say that it is just enough to change two URLs in options table in database, hardcode new site URL in wp-config.php or make some redirections via .htaccess file.

It is not!

The only one good solution is to update all the links in the database and in site files (if you use somewhere absolute URLs).

Also, you can’t just replace the URLs in the database, because some components store the URLs as PHP serialized strings and that will broke the site.

Before migration, make a complete site backup (database and files), disable any security and caching options of the site, clear any existing temporary or cache files.

The most efficient and easy for migration is to use a special plugin for migration. There are a lot of them. The one I recommend is WP Migrate DB. It allows you to define the migration scenario, then exports the database with applied changes.


  1. Install and activate the plugin, go to Tools, Migrate DB.
  2. Configure the “Find” and “Replace” rules (Enumerate all the combinations you have in the database, replace all of them with a single valid new domain URL).
  3. Click on “Export”, save the updated database.
  4. Go to Database management tool (ie: PHPMyAdmin), delete all the tables related for WordPress (be aware if you have some tables not related to WordPress in the same database!).
  5. Import the migrated database.
  6. Check the WordPress theme for any absolute URLs that require update.


WordPress is a great CMS, simple to use and administrate, but a migration should be done correctly to avoid problems.

If you have some questions – don’t hesitate to ask me. If you don’t have time to spent on that – hire me as freelancer!
Last update: 2017/01/30

Watchdog and start scripts for Rocket.Chat application

I installed recently Rocket.Chat on a server. The next day I checked it – the service was not running. So I wrote a small script that checks if the application port 3000 is in use and run another script if not.

The scrip is quite simple. The core utility nc is used to check the port availability and set the value for the parameter PORTCHECK depending on the state. Next it uses an if statement to just echo a message if the port is in use, otherwise it run the Rocket.Chat starting script.

Here is the code on that script /opt/
PORTCHECK=$(nc -z -w 3 localhost 3000; echo $?)
DATESTAMP=$(date +”%Y-%m-%d-%T”)
if [ “$PORTCHECK” = 0 ]; then
echo “RocketChat server is already running”
echo “$DATESTAMP App is running.” >> /var/log/watchdog.log
echo “RocketChat server is not running. Will try to start it.”
echo “$DATESTAMP RocketChat is not running, restart it.” >> /var/log/watchdog.log
/bin/sh /opt/

You should add a cronjob that will check each minute is the server is running. Enter crontab -e to open cron jobs list, add at the end:
* * * * * /bin/sh /opt/

Here is the script to start Rocket.Chat /opt/
export PORT=3000
export ROOT_URL=
export MONGO_URL=mongodb://localhost:27017/rocketchat
cd /opt/rocket/
nohup /usr/local/bin/node main.js > /var/log/rocketchat.log 2>&1 &

Recover access to Jenkins

Have you lost the password for Jenkins? Or maybe you changed some security settings and now you can’t log in?

You need to recover access. This is quite simple. The strategy will be to disable security for Jenkins, login and reset user’s password (you can also create a new user), re-enable security.

By default in Linux, Jenkins is installed into location /var/lib/jenkins. you will need to edit the configuration file here: config.xml and change <useSecurity>true</useSecurity> to <useSecurity>false</useSecurity> then restart Jenkins service: service jenkins restart
Open Jenkins WEB console, go to People, click on the username, Configure, set the new password and save changes.

You now have access to Jenkins!

PS: I presume you have SSH access to server. It worked for me with Ubuntu 14.04/Debian 8.5 and Jenkins 2.7.2

Change WHM/cPanel server IP address

If you migrated or clonned a WHM/cPanel server, changed or just added another IP address, you need to update the IP address(es).

If you need to add the new IP address by configuring it at system level, use the tool Add a New IP Address. You don’t need this if you already changed the IP at system level or you use NAT.

Next, go to Server Configuration, Basic WebHost Manager® Setup and put the new main IP in:
The IPv4 address (only one address) to use to set up shared IPv4 virtual hosts

You need to change make WHM know that here was changes in the list of IP addresses. For that, use the option Rebuild the IP Address Pool.

Then go to Resellers, Manage Reseller’s Shared IP and if you have a reseller – change the main shared IP for each.

After that you will be able to set the new IP for a single (Change a Site’s IP Address) or multiple accounts (Change Multiple Sites’ IP Addresses).

To check that the operations you just did was applied, use the option Edit DNS Zone.

This should be enough.