Friday, 24 April 2015

Interesting motd with figlet or toilet


What if you want to have interesting motd?

You can do these interesting motd using figlet.

Example:




You Just need to install [ toilet ] and try these interesting output.

sudo apt-get install toilet

Friday, 10 April 2015

ansible-playbook for docker cassandra cluster.

The following command will create a cassdb cluster using ansible.
#####
---
- hosts: all
  tasks:
  - name: coping the file to all the docker server
    template: src=cassandra.yaml.j2 dest=/tmp/cassandra.yaml
  - name: running some command
    raw: sudo docker run -i -t -d --name cassdb --net host -v /cassdata:/var/lib/cassandra cassdb /bin/bash; containerID=`sudo docker inspect -f '{{.Id}}' cassdb`; sudo cp /tmp/cassandra.yaml /var/lib/docker/aufs/mnt/$containerID/etc/cassandra/cassandra.yaml; sudo docker exec cassdb rm -rf /var/lib/cassandra/*; sudo docker exec cassdb /etc/init.d/cassandra start



#####
command would be:

ansible-playbook  docker-inventory_hosts install_cassandra_playbook.yml



########

NOTE: Following is the variable that I have added in the "cassandra.yaml.j2" file, that need to be interpolated, dynamically.

cluster_name: {{ cluster_name }}
          - seeds: {{ hostvars[groups['docker-akamai'][0]]['ansible_eth0']['ipv4']['address'] }}
listen_address: {{ ansible_default_ipv4.address }}
broadcast_rpc_address: {{ ansible_default_ipv4.address }}


### my cassdb docker image:

docker pull amitmund/cassdb:latest

#######

$ sudo docker exec cassdb nodetool status
Note: Ownership information does not include topology; for complete information, specify a keyspace
Datacenter: BLR
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens  Owns    Host ID                               Rack
UN  192.168.1.10  54.93 KB   256     37.4%   e7915e97-babf-49fd-bcdf-4434b4443fba  R1
UN  192.168.1.11  261.03 KB  256     32.7%   a0589928-f5eb-496f-8456-5018fabb75ca  R1
UN  192.168.1.12  169.35 KB  256     29.9%   219d1439-fd0d-4ea9-ae03-4d25fe0334fc  R1


Thursday, 12 February 2015

How to do port forwarding in virtual box.

How to do port forwarding in virtual box.


1. select your vm that you want for port forwarding.
NOTE: Make sure the vm is in stop mode.
2. select “settings"
3. select “Network"
4. select any free Adapter. “Lets say Adapter 2"
5. enable Enable Network Adapter 
6. In Attached to dorpdown, select NAT
7. Select Advanced
8: In Adapter Type: Select “Paravirtualized Network (virtio-net)”  [ This is important ]
9. Select “Port Forwarding"
10. In Right hand part of the “port forwarding” dialog box, select “+"
11. Provide the :
  Name: Anything you want. example for ssh, say “ssh"
  Protocol: Type of protocol [ for ssh: TCP ]
  Host IP: provide hostname from which host you want to connect to [ over here: 127.0.0.1 ]
  Host Port: On what port of that Host you want to connect to remote port [ example: 60022 ]
  Guest IP: Leave it Blank

  Guest Port: To what port you want to connect from the above host. [ for ssh, the default 22 ]

Monday, 26 January 2015

html_frame

For the example of 8 section.


<!DOCTYPE html>
<html>


<frameset cols="50%,*" rows="25%,25%,25%,25%">
  <frame src="http://url1/">
  <frame src="http://url2">
  <frame src="http://url3">
  <frame src="http://url4">

  <frame src="http://url5">
  <frame src="http://url6">
  <frame src="http://url7">
  <frame src="http://url8">

</frameset>

</html>

Thursday, 27 November 2014

reading a file using golang

Example 1:

$cat run readFile.go 

package main

import(
"io/ioutil"
)

func main() {
contents,_ := ioutil.ReadFile("readFile.go")
println(string(contents))
}




Example 2:

$ cat fileRead.go 

package main

import(
"io/ioutil"
)

func main() {
contents,_ := ioutil.ReadFile("/etc/passwd")
println(string(contents))
}

go installation and build with cross platform compilation

On this note:

1. We do the installation of go on the mac
2. Then create a simple hello world program
3. Execute and test
4. Build the code [ for this example its for mac]
5. Setup cross platform build



Installation of go [ for this example on mac ]

  • For detail information: link: http://golang.org/doc/install
  • installed from the tar.gz, but you can try from mac pkg file too.
  • created a directory "go" under "/usr/local"
  • downloaded go1.3.3.darwin-amd64-osx10.8.tar.gz from https://golang.org/dl/
  • copied the file to /usr/local folder.
  • change the ownership or give the full access to your current user for /usr/local/go folder
  • extract the your download file go1.3.3.darwin-amd64-osx10.8.tar.gz it will extract everything to your /usr/local/go folder
  • update your PATH with adding /usr/local/go/bin
  • type go and you should see the go usage output. [ it mean you have successfully install go :) ]

Create a simple hello world program


package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}

 Execute and test

$ go run hello.go

hello, world


Build the code [ for this example its for mac]

$go build -o hello-mac hello.go

The above command will create an mac executable file.

$file hello-mac
hello-mac: Mach-O 64-bit executable x86_64

now you can run the code directly to the mac os:
$ ./hello-mac
hello, world


Setting up cross build

Further detail information: Link:
http://dave.cheney.net/2013/07/09/an-introduction-to-cross-compilation-with-go-1-1

$ cd /usr/local/go/scr
./all.bash [ if you get some error, try with sudo , just incase if you don't have write access. ]


https://github.com/davecheney/golang-crosscompile

$ git clone git://github.com/davecheney/golang-crosscompile.git
$ source golang-crosscompile/crosscompile.bash
[ if you get some error, try with sudo , just incase if you don't have write access. ]

go-crosscompile-build-all
[ if you get some error, try with sudo , just incase if you don't have write access. ]



This will compile the Go runtime and standard library for each platform. You can see these packages if you look in go/pkg.

% ls -1 go/pkg
darwin_386
darwin_amd64
freebsd_386
freebsd_amd64
linux_386
linux_amd64
linux_arm
obj
tool
windows_386
windows_amd64

And in your shell you can find all the following commands:

go                         go-darwin-386              go-linux-386               go-windows-386
go-all                     go-darwin-amd64            go-linux-amd64             go-windows-amd64
go-build-all               go-freebsd-386             go-linux-arm               godoc
go-crosscompile-build      go-freebsd-amd64           go-openbsd-386             gofmt
go-crosscompile-build-all  go-freebsd-arm             go-openbsd-amd64



go-build-all hello.go [ This will build your code for all the platform :) ]

and you can see all your build file:
hello-darwin-386 hello-freebsd-arm hello-mac hello-windows-amd64
hello-darwin-amd64 hello-linux-386 hello-openbsd-386 hello.go
hello-freebsd-386 hello-linux-amd64 hello-openbsd-amd64
hello-freebsd-amd64 hello-linux-arm hello-windows-386

I have tested and found, I can able to run the code in different arch.
NOTE: for windows build file, rename them to .exe before running them.


hello-darwin-386:    Mach-O executable i386
hello-darwin-amd64:  Mach-O 64-bit executable x86_64
hello-freebsd-386:   ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), statically linked, not stripped
hello-freebsd-amd64: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, not stripped
hello-freebsd-arm:   ELF 32-bit LSB executable, ARM, version 1 (FreeBSD), statically linked, not stripped
hello-linux-386:     ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
hello-linux-amd64:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
hello-linux-arm:     ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
hello-openbsd-386:   ELF 32-bit LSB executable, Intel 80386, version 1 (OpenBSD), statically linked, for OpenBSD, not stripped
hello-openbsd-amd64: ELF 64-bit LSB executable, x86-64, version 1 (OpenBSD), statically linked, for OpenBSD, not stripped
hello-windows-386:   PE32 executable for MS Windows (console) Intel 80386 32-bit
hello-windows-amd64: PE32+ executable for MS Windows (console) Mono/.Net assembly
hello.go:            ASCII Java program text  <---- For me at mac it shows like this :)


Friday, 21 November 2014

simple Dockerfile example1

1. cat Dockerfile

FROM cassandra
ADD start.sh /start.sh # to copy the file into
CMD ["bash", "./start.sh"]
EXPOSE 9160
EXPOSE 9042
EXPOSE 7000
EXPOSE 44478
EXPOSE 7199


2. cat start.sh
#!/bin/bash
service cassandra start
while true; do sleep 60; done  # Not sure any other best way for now

3. 
docker build -t="runcassandra" .     # this will create an image named runcassandra

4.
docker run -d -P --name cass1 runcassandra

NOTE: The cassandra will be up and will listen to rest of the port. But key thing is when you use EXPOSE, these ports get use for container to container communication ***ONLY***,  as per my current understanding, and this is what I found from the documentation too.