Adding a Secondary Gateway / Static Route in Linux

In order to create a static Route you can enter the following command :

ip route add via dev eth0


route add -net netmask gw dev eth1

Note : In order to make this permanent, you would have to create a file named routes-eth0

vi /etc/sysconfig/network-scripts/route-eth0

Append the following line to the file, if the file does not exist , create new file via

You could also have something like this :



Installing and uninstalling redmine plugins

Download the plugin and extract it into the plugins directory.

Go to the plugins directory and run :

bundle install --without development test RAILS_ENV=production

If you need to migrate the database then run the following command :

rake redmine:plugins:migrate RAILS_ENV=production

Now restart redmine :

touch /path/to/redmineDir/tmp/restart.txt

You should now be able to see the plugin list in Administration -> Plugins and configure the newly installed plugin

Uninstalling the plugins :

rake redmine:plugins:migrate NAME=plugin_name VERSION=0 RAILS_ENV=production

Remove the plugins directory and restart redmine.

Installing Redmine with Passenger and Apache on Centos 6.3

1. Install prerequisite / dependencies :

yum install subversion make gcc gcc-c++ zlib-devel ruby-devel rubygems ruby-libs apr-devel apr-util-devel httpd-devel mysql-devel mysql-server automake autoconf ImageMagick ImageMagick-devel curl-devel


2. Go to the directory where you want to download Redmine Code and check out the files using svn command :

svn co redmine

3. Install the ruby gem named bundle :

gem install bundle

4. Now go to the redmine directory and  install the redmine’s ruby dependencies using the bundler :

bundle install --without postgresql sqlite test development

Now Lets Setup the MySQL Database

Now Create the MySQL Database for the redmine and create a user with access to that database :


create database redmine character set utf8;

grant all privileges on redmine.* to ‘redmineUser’@’localhost’ identified by redminePassword;

flush privileges;


Now create the database configuration file for redmine :

cd /path/to/redmineDir/config

cp database.yml.example database.yml

vi database.yml

Now in the database.yml  file enter the database information in the production section as shown below :

  adapter: mysql
  database: redmine
  host: localhost
  username: redmineUser
  password: redminePassword
  encoding: utf8

Now populate the database using the rake command :

cd /path/to/redmineDir

rake generate_secret_token rake db:migrate RAILS_ENV="production" rake redmine:load_default_data RAILS_ENV="production"

Configure outgoing Email :

cd /path/to/redmineDir/config
cp configuration.yml.example configuration.yml

Please read the email configuration section at the end for setting up outgoing email configuration, for now we will proceed and come back to email configuration at the end.

As of now you should be able to test the redmine in standalone mode. Run the following command to run redmine in the standalone mode  :

ruby script/server webrick -e production

Note : You need to be inside your redmine dir to run above command .

Now open the following URL and you should see the redmine  in your browser :



Now let’s Install Passenger module for apache  which will allow us to browse ruby application using apache . We will install phusion passenger for this and we will need to install the gem first :

gem install passenger

Now install the apache module for passenger :



Now we create the apache configuration for redmine :

vi /etc/httpd/conf.d/redmine.conf

Now paste the following content into the redmine.conf , please adjust the configuration to suite your environment :

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.18/ext/apache2/
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.18
PassengerRuby /usr/bin/ruby
<VirtualHost *:80>
    DocumentRoot /path/to/redmineDir/public
    <Directory /path/to/redmineDir/public>
        AllowOverride all #loosen apache security
        Options -MultiViews #turn of multi views allow from all
    ErrorLog "| /usr/sbin/rotatelogs /etc/httpd/logs/redmine-error.%Y-%m-%d.log 86400"
    CustomLog "| /usr/sbin/rotatelogs /etc/httpd/logs/redmine-access.%Y-%m-%d.log 86400" "%h %l %u %t %D \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""

Make sure that these directories are writable by the web user :  (nobody user is used for rack )

chown -R apache:nobody files/ log/ tmp/ tmp/pdf/

chmod -R 770 files/ log/ tmp/ tmp/pdf/

Now Change the ownership of the directory, test the configuration and start / restart apache :

chown -R apache:root /path/to/redmineDir/

service httpd configtest

service httpd restart


Quick Tips :

Clean up all the devel packages that were installed during installation :

yum remove '*-devel' make automake autoconf

Restarting Redmine :

touch /path/to/redmineDir/tmp/restart.txt

Migrating restored data from previous  version :

First Backup the database from old Redmine install, restore into the new database, sync the files directory from old installation to new installation and then run the migrate command :

cd /path/to/redmineDir

rake db:migrate RAILS_ENV=”production”


Email Settings :

Using Gmail as outbound SMTP :

    delivery_method: :smtp
      enable_starttls_auto: true
      address: "" 
      port: '587'
      domain: "" 
      authentication: :plain
      user_name: "" 
      password: "your_password" 

Using your own SMTP with authentication :

    delivery_method: :smtp
      port: 25
      authentication: :login
      password: redmine

Your own SMTP without authentication :

    delivery_method: :smtp
      port: 25
      authentication: :none

Using Local Sendmail :

    delivery_method: :sendmail


Common Issues and Resolutions :

Error while sending mail notificaiton  “ hostname was not match with the server certificate”

Add this line to the email settings :

openssl_verify_mode: none
  • mysql2 is not part of the bundle. Add it to Gemfile

If you get the above error, that means, mysql2 adapter has not been included in your Gem file , open the gem file in your redmine root directory and add it to the list :

gem 'rails', '3.2.8'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"

Make it look like :

gem 'rails', '3.2.8'
gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0"
gem "coderay", "~> 1.0.6"
gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby]
gem "builder", "3.0.0"
gem "mysql2", "~> 0.3.11"

Now run the bundle installer again with the following command :

bundle install --without postgresql sqlite test development

Now verify that the mysql2 adapter has been installed :

 bundle show mysql2

Now you should be good.. continue with the other steps from where you got this issue.


Clearing Redmine Cache

rake tmp:cache:clear RAILS_ENV=production
rake tmp:sessions:clear RAILS_ENV=production

Port Forwarding with Iptables

You can use port forwarding in iptables, to forward a port to private ip , here is how you can do that :

iptables -t nat -I PREROUTING -p tcp -d <listenip> --dport 22 -j DNAT --to <ipToForwardTo>:22
iptables -I FORWARD -p tcp -d <ipToForwardTo> --dport 22 -j ACCEPT

Setting Default permissions on installed packages

If you mess up the permissions on installed packages some how , you can set default permissions by issuing the following command :

for p in $(rpm -qa); do rpm –setugids $p; rpm –setperms $p; done

Function to write a message to a text file

Sometimes , we need to write some logging information to a text file in php. The following function takes  filename and message as the parameter and logs whatever you pass to the file with date and time.

function logToFile($fileName, $logMessage)
    $logDirectory = “/path/to/log/dir”;     
    $fileHandler = fopen($logDir . '/' . $fileName , "a");
    $logText = date("Y-m-d h:i:s") . "---" . $logMessage . "\r\n";
    fwrite($fileHandler, $logText);

PAM Login Notification Centos

Edit the file :  /etc/pam.d/sshd

vi /etc/pam.d/sshd

Add this line to the above file :

session optional     /path/to/

Now Create the Script that will send the notification :

vi /path/to/script

Paste The Following content, and adjust the admin email address :

[ "$PAM_TYPE" == "open_session" ] || exit 0
        echo "User: $PAM_USER"
        echo "Remote Host: $PAM_RHOST"
        echo "Service: $PAM_SERVICE"
        echo "TTY: $PAM_TTY"
        echo "Date: `date`"
        echo "Server: `hostname -s`"
        } | mail -s "`hostname -s` $PAM_SERVICE login: $PAM_USER" $adminEmail

Redhat Package Manager Tips & Tricks

View a List of packages installed by Date :

rpm -qa --qf '%{INSTALLTIME} (%{INSTALLTIME:date}): %{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort -n

Using Database to store VoiceMail with Asterisk

In order to use database as the storage for voicemails in asterisk, you would need to compile asterisk with odbc storage support.

Dependencies :  unixODBC

yum install unixODBC


Run make menuselect when making asterisk and make sure you
select odbc_storage under voicemail build options.

Edit voicemail.conf to have these two lines :

vi /etc/asterisk/voicemail.conf

Note : The database name (from /etc/asterisk/res_odbc.conf) is in the “odbcstorage” variable in the general section.

Create Database to store Voicemails

CREATE TABLE voicemessages (
id bigint generated always as identity NOT NULL,
dbdate timestamp not null default current timestamp,
dir varchar(80) default '',
msgnum bigint NOT NULL default 0,
context varchar(80) default '',
macrocontext varchar(80) default '',
callerid varchar(40) default '',
origtime varchar(40) default '',
duration varchar(20) default '',
mailboxuser varchar(80) default '',
mailboxcontext varchar(80) default '',
recording blob,

create index idx_voicemsgs on voicemessages(dir,msgnum);

Connecting To MySQL Using Perl

#!/usr/bin/perl use strict; use DBI; $host = "dbhost"; $database = "dbname"; $port = dbport; $tablename = "tablename"; $user = "dbuser"; $pw = "dbpassword"; $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port",$user, $pw) or die "Unable to Connect to MySQL Server: $DBI::errstr\n"; $sql = "Sql Query Here"; $sth = $dbh->prepare($sql); $sth->execute or die "An Error Occurred: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { print "@row\n"; }