What is Software delivery ?

Implementing CI/CD is part of Devops . Here CD is continouse Delivery .

It include steps we need to do to make code available to customer.

Which means running that code on production servers , making that code resilient .

Which means no bugs , no security issues , No outages and no traffic spikes .

Python script to check if file is locked also display last modified time

To lock file for testing use this command 

The below command will lock /home/ubuntu/fileloc

flock -x -w 5 /home/ubuntu/fileloc echo "4" >  /home/ubuntu/fileloc && sleep 5

import os, time
import datetime as dt

def is_locked(filepath):
    locked = None
    file_object = None
    if os.path.exists(filepath):
            print "Trying to open %s." % filepath
            buffer_size = 8
            # Opening file in append mode and read the first 8 characters.
            file_object = open(filepath, 'a', buffer_size)
            if file_object:
                print "%s is not locked." % filepath
                locked = False
        except IOError, message:
            print "File is locked (unable to open in append mode). %s." % \
            locked = True
            if file_object:
                print "%s closed." % filepath
        print "%s not found." % filepath
    return locked

def wait_for_files(filepaths):

    for filepath in filepaths:
       if is_locked(filepath):
            print "%s is currently in use." % \
            st = os.stat(filepath)    
            mtime = dt.datetime.fromtimestamp(st.st_mtime)
            print('%s modified %s'%(filepath, mtime))


# Test
if __name__ == '__main__':
    files = [r"/home/ubuntu/filelock"]
    print wait_for_files(files)

python test.py

Install and configure postges-xl

Other than official documentation i did not find much help . It took one hour for me to setup . As i thought its straight forward setup . Download source , compile it and install it . But there is more to it 

Below are steps i followed :

Download a stable branch 

git clone --depth=1  -b XL9_5_STABLE git://git.postgresql.org/git/postgres-xl.git

cd postgres-xl/



cd contrib/pgxc_ctl


cd postgres-xl/ ; make install

cd contrib/pgxc_ctl ; make install 

Now installation is done 

Add below in /etc/profile

export LD_LIBRARY_PATH=/usr/local/pgsql/lib
export PGDATA=/usr/local/pgsql/data
export PATH=$PATH:/usr/local/pgsql/bin

Then add postgres user 
and set /user/local/pgsql as its home directory

chown postgres:postgres -R /user/local/pgsql 

Now we need to setup postgres-XL . Since it is distributed database we need atleast two nodes . In general every component sits on its own node and also have stand by nodes .

For this tutorial purpose i am using two nodes node1 and node2

Major components of Postgres-XL

Global Transaction Monitor (GTM) : The Global Transaction Monitor ensures cluster-wide transaction consistency. GTM is responsible for issuing transaction ids and snapshots as part of its Multi-version Concurrency Control.

Coordinator : The Coordinator manages the user sessions and interacts with GTM and the data nodes.

Data Node : The Data Node is where the actual data is stored.
I have tried installing everything on  node1 for demo purpose but default port of coordinator and data node are same also the share same /tmp directory structure.

So we might  need to change port number then temp directories etc

      Below is the error for reference purpose

      postgres@Node1:~$ postgres --datanode -D       /usr/local/pgsql/dbdata -h -p 5432 -c gtm_host=node1 -c gtm_port=6666 &
[3] 35190
postgres@Node1:~$ LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for ""
FATAL:  could not create any TCP/IP sockets
[3]+  Exit 1                  postgres --datanode -D /usr/local/pgsql/dbdata -h -p 5432 -c gtm_host=node1 -c gtm_port=6666
postgres@Node1:~$ postgres --datanode -D /usr/local/pgsql/dbdata -h -p 5433 -c gtm_host=node1 -c gtm_port=6666 &
[3] 35196
postgres@Node1:~$ LOG:  database system was shut down at 2017-08-01 16:29:12 UTC
FATAL:  lock file "/tmp/.s.PGPOOL.6667.lock" already exists
HINT:  Is another postmaster (PID 35113) using socket file "/tmp/.s.PGPOOL.6667"?
LOG:  pool manager process (PID 35199) exited with exit code 1
LOG:  terminating any other active server processes
LOG:  startup process (PID 35198) exited with exit code 2
LOG:  aborting startup due to startup process failure

[3]+  Exit 1                  postgres --datanode -D /usr/local/pgsql/dbdata -h -p 5433 -c gtm_host=node1 -c gtm_port=6666

Now this two node setup 
Node1 will have  Global Transaction monitor + Coordinator
Node2 will be the Data node .
We need to download and install from source on both the servers then 
One Node1 
Init GTM
Create a directory in /usr/local/pgsql called gtm

postgres@Node1:~/data$ initgtm -D  /usr/local/pgsql/gtm -Z gtm
The files belonging to this GTM system will be owned by user "postgres".
This user must also own the server process.

fixing permissions on existing directory /usr/local/pgsql/gtm ... ok
creating configuration files ... ok
creating control file ... ok

You can now start the GTM server using:

    gtm -D /usr/local/pgsql/gtm
    gtm_ctl -Z gtm -D /usr/local/pgsql/gtm -l logfile start
Then start GTM service 
gtm -D /usr/local/pgsql/gtm -h -n node1 -p 6666 &

Now coordinator service 
Create a directory pgdata or coordinator and run below 

postgres@Node1:~$ initdb -D /usr/local/pgsql/pgdata --nodename=node1
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/pgsql/pgdata ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/pgdata/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
creating cluster information ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok
freezing database template0 ... ok
freezing database template1 ... ok
freezing database postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

You can now start the database server of the Postgres-XL coordinator using:

    postgres --coordinator -D /usr/local/pgsql/pgdata
    pg_ctl start -D /usr/local/pgsql/pgdata -Z coordinator -l logfile

 You can now start the database server of the Postgres-XL datanode using:

    postgres --datanode -D /usr/local/pgsql/pgdata
    pg_ctl start -D /usr/local/pgsql/pgdata -Z datanode -l logfile

Now start the service 

 postgres --coordinator -D /usr/local/pgsql/pgdata -h -p 5432 -c gtm_host=node1 -c gtm_port=6666 &
Now on node2  after you compile from source and followed steps till adding content in /etc/profile and adding of postgres user is done
Create a data folder and initialize as above
initdb -D /usr/local/pgsql/data --nodename=node2
Then start service 
postgres --datanode -D /usr/local/pgsql/data -h -p 5432 -c gtm_host=node1 -c gtm_port=6666 &

Now you can run psql and connect

postgres@Node2:~$ psql
psql (PGXL 9.5r1.5, based on PG 9.5.6 (Postgres-XL 9.5r1.5))
Type "help" for help.


nagios https proxy monitoring plugin or Bash website monitoring script


if [ $# -eq 0 ]
    echo "No arguments supplied"

if [ $# -eq 1  ]

output=`curl  -x -L $1 -m 10 -o /dev/null || echo "Website_down"`

if [ "$output" == "Website_down" ] ; then

echo "Website is down CRITICAL  "
exit 2


echo "Website_up $1  OK"
exit 0


Adding client certificate file using chef data bags

Below is just an example 

logstash_cert_secret = Chef::EncryptedDataBagItem.load_secret("/etc/chef/secrets/logstash_client_key")
logstash_certs = Chef::EncryptedDataBagItem.load("certs", "logstash_client", logstash_cert_secret)

directory "/etc/pki/tls/certs/" do
  action :create
  mode "0755"
  owner "root"
  group "root"

file "/etc/pki/tls/certs/logstash_client.crt" do
  action :create
  mode "0644"
  owner "root"
  group "root"
  content logstash_certs["crt"].join("")


Search and replace in all files in a current directory

grep -rl 'pc961' ./|xargs sed -i 's/pc961/pc/g'

Ansible define a basic windows hosts




Three basic Git commands

1) git add -A

git add -A is equivalent to  git add .; git add -u.

git add .  ( This will add all files but does not remove files )
git add -u ( This will add only changes but will not add any new files created )

So we use

git add -A ( this will take care of both the commands )

2) git commit -m “Commit changes text ex: I have added new function xyz to the file

3) git push origin  

example of branch name : develop

Another 3 frequently used commands include :

git pull
git status 
git merge origin/Branchname