Wednesday, January 13, 2016

BASH Script to Get the Child Process IDs recursively.

#!/bin/bash
function return_child_pid
{
   pd=$1
   count=0
   for p in `ps -ef | awk '$3=="'"$pd"'" {print $2}'`;
   do
      count=$(($count+1))
      return_child_pid $p
   done
   if [ $count == 0 ]; then
     echo $1
     return $1
   fi
}

return_child_pid $1

Wednesday, August 12, 2015

Web Interface to Subversion log

1. Install pysvn, BeautifulSoup, httplib2 python modules, also install php, php support packages for apache2/httpd

2. Create directory with read,write permissions for apache2/httpd user "/usr/local/share/WebSVNLog/"

3. Place the files in apache2/httpd default folder for example "/var/www/html"

4. Place the SVN path and access credentials(user_name,path) in svn_log.py and svn_branches.py files 

5. Run the svn_branches.py, will create/update svn_branches.json file in   "/usr/local/share/WebSVNLog/" directory

6. Access the WebSVNLog from the browser http://127.0.0.1/Web_Log.php

Note: This is tested in linux OS, needs configuration changes in to enable in other OS. Also this scripts can be placed in SVN server or any other machine which has access to the Subversion server.

Source code accessible from WebSVNLog

Monday, December 8, 2014

Docker Machine [VirtualBox] Steps

1. Install Virtualbox in the Hostmachine
2. Download the "linux"  binary from the URL

   Rename the linux named binary as machine & chmod u+x machine
3. Create a virtualbox VM from the command
./machine create -d virtualbox dev
4.start  the Virtualbox  and observe the newly created vm in the virtualbox list.
5. Power on the created VM
6. Once the created VM is up, play with the docker commands
 docker run busybox echo helloworld

Friday, November 28, 2014

Dockerfile for the Django application, MySQL as database


Below steps to prepare docker image with the Django with helloworld application installed/setup, MySQL as a database


1. Save the Below dockerfile contents to the directory.

2. Build the image as sudo docker build -t django_hw_img .
(there is a . at the end).

On successful image creation, docker image will created. it will be listed in the list from the command sudo docker images

3. Run the image as 
sudo docker run -i -t -p 80:80 django_hw_img:latest /bin/bash

4. On container shell start the apache2 service service apache2 start

5.Access the application from the http://<your_host_ip_address>/helloworld/

+===================Dockerfile======================+
#################################################
# Dockerfile to build Python-Django WSGI Application Containers
# Based on Ubuntu:latest
#################################################

# Set the base image to Ubuntu
FROM ubuntu

# File Author / Maintainer
MAINTAINER surya.janardhan@gmail.com

# Update the sources list
RUN apt-get update

# Install basic applications
RUN apt-get install -y git build-essential libapache2-mod-wsgi apache2

# Install Python and Basic Python Tools
RUN apt-get install -y python python-pip

# Get pip to download and install requirements:
RUN pip install django

#install MySQL in noninteractive way
RUN export DEBIAN_FRONTEND=noninteractive
RUN apt-get -q -y install mysql-server python-mysqldb

#create the working dir and set the working directory
CMD mkdir /usr/local/share/apps
WORKDIR /usr/local/share/apps

#clone the tutorials from the github.com
RUN git clone https://github.com/Jadatravu/Tutorials /usr/local/share/apps/tutorials

# set the permissions to the app directory
CMD cd /usr/local/share/apps && chown -R www-data:www-data tutorials
WORKDIR  /usr/local/share/apps/tutorials/django_tutorials/helloworld/

# set the database for the helloworld database django_tut
RUN echo "CREATE DATABASE django_tut;" > /usr/local/share/apps/create_database.txt && service mysql start  && mysql -u root < /usr/local/share/apps/create_database.txt &&  python manage.py migrate

# Configure apache configuration for the helloworld application
RUN  echo "WSGIScriptAlias / /usr/local/share/apps/tutorials/django_tutorials/helloworld/helloworld/wsgi.py" >> /etc/apache2/apache2.conf &&  echo "WSGIPythonPath /usr/local/share/apps/tutorials/django_tutorials/helloworld/" >> /etc/apache2/apache2.conf &&  echo "<Directory /usr/local/share/apps/tutorials/django_tutorials/helloworld/>" >> /etc/apache2/apache2.conf &&  echo "<Files wsgi.py>" >> /etc/apache2/apache2.conf &&  echo "Order deny,allow" >> /etc/apache2/apache2.conf &&  echo "Require all granted" >> /etc/apache2/apache2.conf &&  echo "Satisfy Any" >> /etc/apache2/apache2.conf &&  echo "</Files>" >> /etc/apache2/apache2.conf &&  echo "</Directory>" >> /etc/apache2/apache2.conf

#expose the port
EXPOSE 80
+===================Dockerfile======================+

Wednesday, January 29, 2014

Django Static files tutorial
1. Create a Django project and app, Edit settings.py for database settings
2. Place the static files "files1.txt", "files2.txt" in the directory for example "/home/notroot/django_tut/staticfiles/sfiles"
3. create the directory files in the path for example "/home/notroot/django_tut/staticfiles/"
4. edit section  STATICFILES_DIRS in settings.py file with the value
"/home/notroot/django_tut/staticfiles/sfiles"
5. edit section in STATIC_ROOT in settings.py file with the value "/home/notroot/django_tut/staticfiles/files"
6. set the value for the variable in settings.py STATIC_URL = '/static/'
7. write a template in the template dir for example index.html
{% load staticfiles %}
  <a href="{% static 'files1.txt' %}">link1</a>
  <a href="{% static 'files2.txt' %}">link2</a>
8. update the TEMPLATE_DIRS option in the settings.py.
9. Add a view in the views.py and update urls.py file
10. In the project root folder run the command "python manage.py collectstatic"
out put would be

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

0 static files copied, 73 unmodified.
11. run the server, access the url from the browser

http://127.0.0.1:8000/staticfiles/
  
12 Download the tutorial from the github
Note: This is compatible with django 1.5.4

Sunday, December 15, 2013

Django Logging Tutorial
1.Update LOGGING section in settings.py with logger,handler,formatter fields
  Logger which specifies the handler, in this case it is file
 'loggers': {
        'logapp':{
            'handlers': ['file'],
            'level': 'DEBUG',
        },
    }
  File handler specifies the filename "logapp.log", also specifies theformatter in this case it is simple.
  'handlers': {
        'file':{
            'level':'DEBUG',
            'class':'logging.FileHandler',
            'filename':'logapp.log',
            'formatter':'simple'
        },
    }
  Formatter specifies the formatter in this case it is 'simple'.
 'formatters':{
        'simple':{
           'format':'%(levelname)s %(message)s'
        }
    },
2. import logging modules and add the logger message lines whereever it is required to have log message.

    logger.debug("This is debug message")
    logger.error("This is error message")

3. log messages will be printed in the log file in this case "logapp.log"
   http://127.0.0.1:8000/logproject/

4.Source Code can be downloaded from the github
https://github.com/Jadatravu/Tutorials/tree/master/django_tutorials/logproject

Note: This tutorial is compatible with django 1.5.4, python 2.7.4

Tuesday, December 3, 2013

Django Helloworld tutorial
1. Install django from pip or apt-get/yum 2. Install mysql, python-mysqldb pacakge from apt-get/yum 3. Create database in mysql using steps mentioned in the url creating-database 4. Creating mysql user and granting database permissions to the created user using the steps mentioned in the url adding-users 5. Edit helloworld/settings.py for database settings [ Database(mysql), Database name, Database user, Database user password] 6. Run server in the helloworld directory python manage.py runserver
7. Open the url http:/127.0.0.1:8000/helloworld


8.Source Code can be downloaded from the github
https://github.com/Jadatravu/Tutorials/tree/master/django_tutorials/helloworld
Note: This tutorial is compatible with django 1.5.4, python 2.7.4