Monday, August 22, 2016

My first exercise with Backbone.js

Files below itself says what it does, Hope it's not that difficult  :)
Also read following for more information 
https://addyosmani.com/backbone-fundamentals/#what-is-backbone.js
http://www.tutorialspoint.com/backbonejs/backbonejs_environment_setup.htm

Wednesday, August 10, 2016

Install Postgres on Ubuntu

1. Install

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

2 Start the postgres

sudo /etc/init.d/postgresql start
If does not start correctly try the solution at  this link
https://www.digitalocean.com/community/questions/language-problem-on-ubuntu-14-04

3. Login as postgres user
sudo -i -u postgres
This postgres is the default user that postgres adds to linux sytem when it is installing

4. Create a postgres role
createuser --interactive
This is an interactive mode to create a the postgres role/user, It will ask you two questions: the name of the role and whether it should be a superuser. Lets answer "dbuser1" and "y" for the two questions

5. Create a database
Here we have to create the database with the same name we have given for role (in above step 3.)
createdb dbuser1

6. Create a system user with the same name
Logout from postgres user
exit
Then create a user
sudo adduser dbuser1
This is reuired becase the way that Postgres is set up by default (authenticating roles that are requested by matching system accounts) also comes with the assumption that a matching database will exist for the role to connect to.

7. You may sometimes need to add the new user for the sudoer list 
sudo usermod -a -G sudo dbuser1

8. Now login as the newly created user (here we have linux username, postgres role name and db all having same name)
sudo su - dbuser

9. Give psql command, this will take you to the psql command line interface
psql

10. Give \conninfo command to check the connection information

Play arround
\list or \l: list all databases
\dt: list all tables in the current database
To switch databases:
\connect database_name
Create a db from a dbscript
\i path\of the\dbsrcipt.sql
Check the tables (show tables)
\dt


Allow remote connections
psql -U postgres -h 192.168.102.1
psql: could not connect to server: Connection refused
        Is the server running on host "192.168.102.1" and accepting
        TCP/IP connections on port 5432?

To enable other computers to connect to your PostgreSQL server, edit the file /etc/postgresql/9.1/main/postgresql.conf
Locate the line #listen_addresses = 'localhost' and change it to:
listen_addresses = '*'


To allow the access to database, Edit the file /etc/postgresql/9.1/main/pg_hba.conf to use MD5 authentication with the postgres user:
# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             192.168.0.0/24          md5


Above config says it allows access from all databases for all users whome are connecting from 192.168.0.0/24. And the authentication method is encrypted password 


sudo /etc/init.d/postgresql start

Monday, August 01, 2016

There is no rocket science in Puppet :)


 My 1st puppet module to download Java


class wso2base::download_java {
  $oracle_repo = 'http://download.oracle.com/otn-pub/java/jdk/7u75-b13/'
  $oracle_header = '"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie"'
  $java_package = 'jdk-7u75-linux-x64.tar.gz'
  $java_dir     = '/opt/java/'

  file { '/opt/java/': ensure => directory, recurse => true }

  exec {
    "${name}_download_java":
      path    => ["/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
      cwd     => "/opt/java/",
      unless  => "test -f ${java_dir}${java_package}",
      command => "wget --no-cookies --no-check-certificate --header ${oracle_header} ${oracle_repo}/${java_package}";

    "${name}_extract_java":
      path    => ["/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
      cwd     => "/opt/java/",
      command => "tar xvfz ${java_package}",
      require => Exec["${name}_download_java"];

  }

}