• Call: +1 (858) 429-9131

Upgrading Rocket Chat

This is a very quick post. Many organizations are using Rocket chat as the slack / IRC alternative.

One important point that is not often documented is the upgrade. We ourselves ran into issues with Node.js errors, Meteror errors etc multiple times.

Here is how we can upgrade without breaking anything.

take a backup of the installation directory

cd /home/rocket
su -l rocket
cp -rfp Rocket.chat backups/date +%F

Assuming that backups are kept in /home/rocket/backups and db backups are in /home/rocket/backups/db

cd backups/db
rm -rf /home/rocket/Rocket.chat

#get the new version

cd /home/rocket
curl -L https://rocket.chat/releases/latest/download -o rocket.chat.tgz
tar xf rocket.chat.tgz
mv bundle Rocket.chat

install dependencies

(cd /home/rocket/Rocket.chat/programs/server && npm install )

All set to start the new server, migrate the dabase etc.

cd /home/rocket/Rocket.chat
node main .js

The last step performs upgrade and maintenance of the db scheme. With most of the versions this method will work.

It is assumed that the user rocket is the user under which Rocket.chat is installed.

Further, the server is running as a service which was done with :

sudo forever-service install -s main.js -e "ROOT_URL=https://chat.agileblaze.net/ MONGO_URL=mongodb://localhost:27017/rocketchat PORT=3000" rocketchat

DevOps stories 1: working with a high traffic e-commerce portal

Looks like this is a good idea to write down first person stories of various DevOps – Cloud migration scenarios that we come across.

In this particular case we have a beast of a server with 32 processors with 8 cores each & 256 of RAM running LAMP stack, CakePHP &  X-cart shopping cart. And yes, everything is dead slow.

Cleaning up the X-cart cache

By default (?), the cache is at /var/www/html/cache or [DOCTUMENT_ROOT]/cache. If there are too many files, you will not be able to delete the files. The following commands can help.

touch /root/agileblaze/cache-file-list.txt #empty file
find . -name '.js' | grep -vFf /root/agileblaze/cache-file-list.txt | xargs /bin/rm -f
find . -name 'sql.
' | grep -vFf /root/agileblaze/cache-file-list.txt | xargs /bin/rm -f
find . -name 'rf*.php' | grep -vFf /root/agileblaze/cache-file-list.txt | xargs /bin/rm -f

The permanant fix for this X-cart behaviour is to change the following row in the config.php file from:

define('USE_SQL_DATA_CACHE', true);
define('USE_SQL_DATA_CACHE', false);


There are tons of issues like a db that is not upgraded, joins without indexes etc. We decided to make use of the RAM & have MySQL MYISAM temporary files in there for faster access. Don’t forget to create the required directory and add the necessary entries /etc/fstab to persist the changes over reboots.

/etc/my.cnf is changed as follows

tmpdir = /var/mysqltmp # changed from /var/lib/mysql/tmp

Now that we have some room to look into other matters, things should be easier.

We also had the non-so-friendly max connections error. We increased in the max connections from the default.

max_connections = 300 #Sat Apr 30 03:35:25 CDT 2016

Slow Queries

If the slow query log is enabled, mysqldumpslow can be a very handy command

[root@714219-db1 mysql]# mysqldumpslow -a -s r -t 10 /var/log/mysql/slow.log

Reading mysql slow query log from /var/log/mysql/slow.log Count: 376687 Time=1.63s (613441s) Lock=0.00s (36s) Rows=203657.1 (76714970948), 2users@localhost SELECT productid, COUNT(remote_ip) AS total, AVG(vote_value) AS rating FROM xcart_product_votes GROUP BY productid

Controlling the RAM usage


The RAM usage on GNU/Linux based systems can be sometimes quite weird. The immediate path taken is to play around with sysctl and tweak swappiness & may be run drop_cache.


change swappiness to say, 10 & do a cache + buffer cleanup. But these may not be very handy but the /proc/sys/vm/vfs_cache_pressure changes seems to help further. (we have it around 512)

Further minimum free memory size is a parameter which can help preventing OOM errors. A sample value is shown below.

sysctl -w vm.min_free_kbytes=2621440


sysctl -w vm.vfs_cache_pressure=1024
sysctl -w vm.swappiness=10


Keep an eye on Caches and Buffers

This is often something people miss.   The difference between free command and the total process usage can give us the Cache + buffer usage.  slabtop is a very handy command to get exact details.

slabtop --delay=10 -s c

Can give a neat summary.

Screenshot from 2016-05-11 20-28-07


Another very useful tool is dstat

dstat -lrvn 10 output is shown below. This can give colourful details of cache usage.

the memory, CPU, network, IO columns above gives useful information.


How to read dstat : On a fully warmed-up system, memory should be around 95% in-use, with most of it in the cache column. CPUs should be in use with no more than 1-2% of iowait and 2-15% system time.


How to setup automatic updates:

Sometimes it is quite good to have automatic updates in place. For Ubuntu, automatic updates can be done following these instructions.



Urban Airship Push Notification Integration

Push Notification is one of best way to interact with app users. Every mobile developer knows the importance of push notification in mobile apps. Push Notification provides near real-time updation of informations such as news,score updates,messages etc., to users. iOS provides APNS (Apple Push Notification Service) to send push notification data to applications installed on Apple devices. There are many third party push notification services are available  like Parse,Urban airship, Carnival,Push woof etc. The benefits of using third party Push Notification service are,

  • – Reduce Your code.
  • – Save Your  time and effort.
  • – Manage the notifications easily.

This section will explain some simple steps to be followed to send push notification to iOS platform via Urban airship dashboard. The steps are given below.

  • 1. Registration and login
  • 2. Create Your first app in Urban airship
  • 3. Set up your xcode project.
  • 4. Send your first Push Notification

Registration and login

You need to create an account in Urban Airship using an email id and password. There are many pricing plans available. Select a pricing plan or select a free starter account. Click here to view the available account plans. After the successful registration, click manage your apps from Urban Airship dashboard to get started.

Create Your first app in Urban Airship

After the registration is completed, add your first app. You need to specify the following details to create an app.

App Name

The name of your app.

App Icon

Upload an app icon.

Production status

You must select whether your app is in development mode or production mode. When you are setting up development and production apps, you have to configure them for push services. See the APNS Setup documentation for detailed instructions.

Select Platform that will use Urban Airship

Select your platform here. The available platforms are iOS, Android, Windows, Blackberry etc.

After selecting the iOS app platform, save your app.

app fields

Set up your xcode project

You have created an app in previous section. Then you need to set up the xcode project. First, create an xcode project for push notification. Then you have to follow some steps to set up your project. The steps are  explained below.

  • Download Urban airship SDK

Download the latest version of  libUAirship from Urban Airship. Unzip the SDK and add the libUAirship static library and headers into your project. Click here to download the latest version of Urban Airship SDK.


  • Manage Build Settings

In the project’s build settings set “Enable Modules” field to “Yes” and “Link Frameworks Automatically ” to “Yes”.

  • Add Urban Airship SDK

The SDK can be included using the Urban Airship static library(iOS 7+) and Urban Airship Embedded framework(iOS 8+). The static library and embedded framework have different setup procedures.

      Including Urban Airship SDK using Embedded framework(iOS 8+)

-Include Airshipkit

Add  Airshipkit.XcodeProj into your app project in xcode.

-Link against embedded framework

adding framework

Add the Airshipkit.framework file to the Embedded binaries section in the general tab for your project to link against the embedded framework.

Including static library (iOS 7+)

– Search paths

Screen Shot 2016-04-20 at 1.00.23 PM

Ensure that your project’s header search paths under build settings include the Airship directory.

– Linker Flags

Add –objC –lz –lsqlite3 linker flag to prevent “Selector Not Recognized” runtime exceptions and to include linkage to libz and libsqlite3. The linker flag –force_load<path to library>/ libUAirship<version.a> may be used in instances where using the –objC linker flag is undesirable.

Screen Shot 2016-04-20 at 1.01.21 PM

– Link against the static library

In the libraries section in the Build Phases, add the libUAirship.a file to the link binary to link against the static library.

link binary

– Add the Urban Airship resource bundle

Add the UrbanAirshipResources.Bundle file to the Copy Bundle Resources section in the Build Phases tab for your target.

  • Enable Background Notification

You can enable Background notification by enabling Remote notifications of Background mode under the target’s capabilities section.


  • Create AirshipConfig.plist

To manage your production and development application profiles, the Urban Airship SDK uses a .plist configuration file named AirshipConfig.plist. You can create two application within your Urban Airship account:one for development and one for production. Create  an AirshipConfig.plist and set the following values in your .plist file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
<plist version="1.0">
  <string>Your Development App Key</string>
  <string>Your Development App Secret</string>
  <string>Your Production App Key</string>
  <string>Your Production App Secret</string>
  • Import the required header files

Import the AirshipKit header files to your application delegate.

Import AirshipKit (Swift)

#import<AirshipKit/ AirshipKit.h>

You must import the individual headers if your application uses the static library.

#import “UAirship.h”

#import “Uaconfig.h”

#import “UAPush.h”
  • Starting Urban Airship Services

Inside your application delegate’s application:didFinishLaunchingWithOptions:method,initialize a shared Uairship instance by calling Uairship takeoff.This will bootstrap the Airship SDK.


         [Uairship takeOff:config];
  • Retrieving your channel ID

The channel ID is a unique identifier used to target pushes to a specific devices using the Urban Airship API.You can always get the channel ID using the following code.


            NSString *Channelid=[Uairship push].channelID;
            NSLog(@”My channelID:%@”, Channelid);


            Let Channelid=Uairship.push().ChannelId
            print(”My channelID:%@”, Channelid)

ChannelID initially comes back as NULL on your apps first run.It will be created and persisted during registration.

  • Enabling User Notifications

By default User notifications are disabled.To enable notification write the following code. Set the user notification types on [Uairship push]. Sounds, alerts and badges are the default types. The library will register to receive notification after the user push notifications are enabled.

[UAirship push].userNotifictionTypes=(UIUserNotificationtypeAlert| UIUserNotificationtypeBadge|UIUserNotificationtypeSound)

[Uairship push].userpushNotificationEnabled=YES;

After all this steps your project’s AppDelegate.m file looks like  below


#import <AirshipKit/AirshipKit.h>

#import “AppDelegate.h”

@interface AppDelegate ()


@implementation AppDelegate



         [Uairship takeOff:config];

         //Set the icon badge to zero

         [[Uairship push]resetBadge];

         [UAirship push].userNotifictionTypes=(UIUserNotificationtypeAlert|   


         [Uairship push].userpushNotificationEnabled=YES;


Send your first push Notification

  • Adding Test Devices

You need to add a list of test devices in Urban airship console before sending your first notification. To setting up test devices, select Audience. You can see a text box for entering  list of device identifiers. You can enter up to 100 device identifier here. After entering the device identifiers save the list.

add audience

To send your first push notification,navigate to Messages Overview ,located under the Messages tab,and click + Messages. You can see a Message box here and type your notification message here. Before sending the notification you have to select the audience and delivery options. The audience are,

All Devices

Single Device


segments are groups of audience that you can create using combinations of location,tags and lists.

Test Devices

Test devices are predefined devices created by an account administrator.

selecting audience

Select an audience from the list. Then navigate to the delivery section and you can see two options here.


Deliver the message immediately.


Deliver the messages according to the scheduled time


If all has been set up correctly,click Confirm and Send Now.

send 1st

You  have sent your first push notification!!!

We use Zeroshell and its awesome :-)

Many of the Free Softwares (GPLed) IMHO (author’s personal opinion) struggles with marketing or reaching to mass audiences. The effort by Zeroshell to reach more audiences by the peculiar “viralware” model is appreciated.


We use Zeroshell Firewall on quite a few of our networks and are happy with it.


Viralware is a word I just coined ?!

Mosh aka mobile-shell


Stumbled upon Mobile shell (Mosh) which allows persistent connection over intermittent connections, VPN – WiFi – networking roaming etc. Its quite useful especially when we have tons of nodes across multiple cloud providers & resulting attempts of their attention grabbing. Automating few things in a CRM made us  end up setting up a Postfix mail server after something like more than a decade, got frustrated over the nearly non-existent internet provided by Asianet DSL & all credit of this goes to them.


TL;DR Here is a quick guide to get Mosh working on Mac & GNU/Linux flavours.


Mosh uses UDP. Yes, you heard it right.

By default it uses 60000 to 61000 for establishing connections. We would need to open up some of these ports, say a subset of this in the fire wall mechanism that we use to get access to the servers.

There is a client & a server

I missed out this part ! Well, we need to install Mosh on the client and the server. (ie apt-get install mosh or yum install mosh on the servers too BOFH.)

On Amazon / AWS / EC2 cloud,

Open up few UDP ports in the security groups. We opened up 10 ports.

On DigitalOcean or any other provider open the ports in your firewall.

Client side installation:

On Mac,  we ran into issues with libprotobuf

> mosh migrate2cloud.com
dyld: Library not loaded: /usr/local/lib/libprotobuf.7.dylib
  Referenced from: /usr/local/bin/mosh-client
  Reason: image not found
Died at /usr/local/bin/mosh line 201. 

The solution is to upgrade Brew (well why shouldn’t one use brew ?)

brew update ; brew upgrade ;  brew remove libprotobuf ; brew install libprotobuf

will do the magic. If not,  we can try

         brew remove mosh ; brew install mosh

as well. If its doesn’t work, RTFM & the FAQ 🙂

Another issue we ran into was the locale & UTF-8 encoding. We fixed it by installing the locale in the client and server and exporting the following environment variable to the bash profile.

# for mosh
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export MM_CHARSET=utf8
export LC_COLLATE=”en_US.UTF-8″
export LC_TIME=”en_US.UTF-8″
export LC_NUMERIC=”en_US.UTF-8″
export LC_MONETARY=”en_US.UTF-8″
export LC_MESSAGES=”en_US.UTF-8″

You load the environment variables by doing the following in bash.

. ~/.bash_profile   # don’t miss the dot at the beginning

Firewalls, Tunnelling, NAT

It may not work just yet as you may have to deal with NAT traversal and other nasty things. Creating an SSH tunnel can solve these issues.

mosh –ssh=”ssh -4 -R 2222:localhost:22 -i /Users/migrate2cloud/keys/ssh-key”  root@server.com

Reattaching a detached Mosh:mobile-shell is not possible. But we can run screen inside mobile shell.

do pkill mosh-server instead … or pgrep mosh-server -> kill etc

PS: if you use CIRU.org, things may be different for you.

That’s it. DigitalOcean guys have come up with a  nice write up here which is very helpful. There is also an Android client and iOS client in the making. On GNU/Linux I use KDE Konsole & on Mac iTerm : these are 2 good tools that are very useful IMHO.

Install Magento2 in Nginx Server Using Command Line



Installing magento2 in Ubuntu 14.04 with Nginx web server.



Version 5.5.X or more

Required PHP extensions:








gd2, ImageMagick 6.3.7 (or later) or both



2.Mysql 5.6.X


 Create basic nginx configuration file for magento2.

# vim /etc/nginx/sites-available/magantositename

Add the following configuration files in nginx,



server {

listen 80;

 root /var/www/magento2; #Use you mangeto2 location

index index.php index.html index.htm;

 server_name yuor_magento.siteurl;

#location / {

#try_files $uri $uri/ /index.php?q=$uri&$args;


   location /setup {

       try_files $uri $uri/ @setuphandler;


# Rewrite Setup’s Internal Requests

   location @setuphandler {

       rewrite /setup /setup/index.php;


    location / {

       index index.php index.html;

       try_files $uri $uri/ @handler;


    # Rewrite Internal Requests

    location @handler {

       rewrite / /index.php;


     location /pub/static {

         try_files $uri $uri/ @static;


     location @static {

          rewrite ^/pub/static/(.*)$ /pub/static.php?resource=$1? last;


 error_page 404 /404.html;

 error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/www;


#pass the PHP scripts to f stcgi socket

location ~ \.php$ {

               try_files $uri =404;

               fastcgi_pass unix:/var/run/php5-fpm.sock;

               fastcgi_index index.php;

               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

               include fastcgi_params;

               fastcgi_read_timeout 900s;

#Magento 2 Developer Mode

               fastcgi_param MAGE_MODE “developer”;






create a symlink in /etc/nginx/sites-enable/magantositename

 # ln -s /etc/nginx/sites-available/magantositename /etc/nginx/sites-enable/magantositename


Restart PHP handler php5-fpm and nginx

 #  service php5-fpm restart

 # service nginx restart 

Create database and database user for magento2

login to mysql using root user and password:

#  mysql -u root -p

## mysql> CREATE DATABASE <magentodbname>;

## mysql>  GRANT ALL ON <magentodbname>.* FROM magentodb@localhost IDENTIFIED BY <magentodbpasswd>;


Steps to install Magento2

 Change the directory where to download and install Magento2.

 # cd /var/www/

 Download the magento2 zip file from github

 # wget https://github.com/magento/magento2/archive/develop.zip

 # unzip develop.zip

# mv magento2-develop magento2

 Change the ownership to your webserver user name. Typically it is www-data

 # chown -R www-data:www-data magento2

 # cd magento2

Change the permissions as follows,

 # find . -type d -exec chmod 700 {} \;

# find . -type f -exec chmod 600 {} \;

make the file magento file executable  in the directory bin

# chmod +x bin/magento

Install magento using command line,

# ./bin/magento setup:install –base-url “http://your_site_url/” –db-name “magentodbname” –db-user “magentodb” –db-password “magentodbpasswd” –admin-firstname “yourname” –admin-lastname “yourlastname” –admin-email “your_email” –admin-user “magenoadmi” –admin-password “magentoadminpasswd” –language “en_US” –currency “USD” –timezone “America/Chicago” –use-sample-data –use-rewrites=1


Here you will get your Language, Currency and Time zone using the following magento command.


# ./bim/magento info:language:list


# ./bim/magento info:currency:list

Time Zone:

# ./bim/php magento info:timezone:list

 Once the installation is completed you will get the SUCCESS message at the end of installation.

You can access the magento admin interface using the random  generated URL while installing Magento2.

You can check the URL using magento command line.

# ./bin/magento info:adminuri

 You will get the admin URI as,

Admin URI: /admin_8mdvzn

You can  change the the Admin URI in <your Magento install dir>/app/etc/env.php.

Then you can access admin page as http://yuor_site_url/admin_8mdvzn/




You can access the magento2 home page at the installed URL as http://yuor_site_url.

It will look as below,



Your PHP installation appears to be missing the MySQL extension which is required by WordPress

We have came across the following error quite a few times.


Your PHP installation appears to be missing the MySQL extension which is required by WordPress

Though it may sound tricky, the error can be quickly fixed by installing missing PHP libraries. This often happens because of the upgrades.

In PHP 7.x we can fix using the following

sudo apt-get install php-mysql

Older PHP versions can be fixed by the following

sudo apt-get install php5-mysqlnd-ms

Don’t forget to restart Apache / Nginx or the relevant web server to load the libraries / modules.