Create and run container of Django

Hi Readers!

Greetings!

Hope you are reading the blog and gaining some interesting knowledge.

Today I am going to tell you to create a docker container of django and how to run it.

Though this blog is mainly targeting students, newcomers , today’s target audience is intermediate.

So lets start.

Prerequisite – you should have installed rpm based linux(red hat, fedora) and on that os, you should have docker package installed.

Step one:

Write a dockerfile for setting up django.

Create a file ‘Dockerfile’ in any folder and write following commands in to it.

FROM centos:centos7
MAINTAINER <your email id>

RUN yum -y install epel-release
RUN yum -y install python-pip python-django git sqlite; yum clean all

EXPOSE 8000

CMD [ “/bin/bash” ]

Save the file.

Step two:

Build the docker image using this Dockerfile

command:

docker build -t django:centos7anand .

(Note: we mentioned . ‘dot’ here as we are running the command from the location where Dockerfile is saved.)

run the ‘docker images’ command and you should see the newly created image

$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_django latest 2892fe55292c 45 hours ago 409MB

Step three:

docker run -d -p 8000:8000 django:centos7anand

then you should see the container running , you can check using docker ps -a command.

Step four:

Start the container using following command:

docker start <container id of the container which we have created in above step>

Step Five: Check/test whether django is successfully installed in the container

command:

docker run django:centos7anand django-admin –version

Your output should be like :

]# docker run django:centos7anand django-admin –version
1.11.27

Congratulations you have successfully containerised the django package. 🙂

Stay tuned for next interesting and helpful knowledge for this blog.

Failed to synchronize cache for repo ‘updates’

Hi Readers!

Hope you are doing good.

Today we will be discussing one problem related to linux, which is very basic but  if you are new to linux then it’s good to know it.

Problem statement:

If we try to update the package or want to add any repo and if following error message can be seen:

Failed to synchronize cache for repo ‘updates’

Solution:

First try the stuff with -verbose option so that you could see the detailed logs.

Sometimes the repo  you are trying to work are deals with ipv4 only and if you have enabled ipv6 in your system then it wont work for you.

First check whether you have enabled ipv6 or not.

Command to check –

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

if it shows ‘0’ then you have enabled it or by default its enabled.

Now you need to make it disable explicitly then you need to make changes using either numcli command or adding following lines in /etc/sysctl.conf:

 

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

Now check the output of

cat /proc/sys/net/ipv6/conf/all/disable_ipv6

It should be 1. Hence we came to conclusion than ipv6 is disabled now.

Now check again the stuff which you want to do with repo. You may should not see the error if its related to ipv6.

 

Finger command linux

Hello readers,

Greetings!

Hope you are doing great.

Today you gonna learn new command in linux which is not so common but very useful.

Th command is –

‘finger’

Finger package is not installed by default in most Linux and Ubuntu, other Debian flavored systems. We need to install as per out linux machin whether .deb or .rpm based linuxes.

In Unix, finger is a program you can use to find information about computer users. It usually lists the login name, the full name, and possibly other details about the user you are fingering. These details may include the office location and phone number (if known), login time, idle time, time mail was last read, and the user’s plan and project files. The information listed varies, and you may not be able to get any information from some sites.

In some cases, you may be able to use the finger command to verify an address or find more information for someone at another institution about whom you already have some information. The finger command is available on most Unix systems. It differs from the whois command, which you can use simply to find the email address of someone at another institution.

You can do more research on finger command with their different options.

Very few people knew this command. SO congratulations, you know it. 🙂

 

 

python repr() function

Hello Readers,

Greetings!

Hope you are doing great.

Today you will earn some knowledge about python repr() function. It will be very helpful for those people who do use python for programming, scripting etc. because this function is related to string and strings are most important part of programming skills.

So..

Problem is –

Suppose a is list of string-

a=[‘thank’,’you’,’readders’]

expected output is –

‘thank’

‘you’

‘readers’

Solution:

Some people may will try the simple code is-

>> a=[‘thank’,’you’,’readders’]
>>> for i in a:
… print i

But output will be –
thank
you
readders

which is not expected. We are expecting output such that each word will be printed in the quotes.

So here we can use the python function repr().

>> for i in a:
… print repr(i)

And output is-
‘thank’
‘you’
‘readders’

Thats what we are expecting.

repr() function can be use many scenarios but this is one of the scenario which is common.

Hope you will use it 🙂

 

 

check the process is active using ‘pstack’

Hello Readers,

Happy new years!!

I know it’s been long since last post but I like the way you follow my blog. Thanks a lot. You are the people who encourage me to write/help new comers/learners and spread the solutions of the some basic but important problems.

So, people today I am going to talk about pstack.

If you new to linux or operating system or new to the word of ‘pstack’, congratulations because you are going to earn more knowledge about it.

So at very high level, pstack is basically a command which we can use on linux machine to know whether the any process is hung or it’s working.

So, lets go in to deep.

The pstack command will print a hexadecimal dump of the process stack, thus providing important information about a suspect process on the affected system.

pstack attaches to the active process named by the pid on the command line, and prints out an execution stack trace. If ELF symbols exist in the binary (usually the case unless you have run strip(1)), then symbolic addresses are printed as well.

If the process is part of a thread group, then pstack will print out a stack trace for each of the threads in the group.

Lets talk about installation:

Its very easy.

Following is the command to execute.

yum install pstack -y or apt-get install pstack -y

Once it get installed you can check the installation by typing ‘pstack’ command.

You can check the sub commands using pstack –help.

The basic syntax is pstack [process id]

example – pstack 8798

It will print the stacktrace.

Like – #pstack 1094
1094:   /usr/lib/sendmail -bd -q15m
fefc6004 pollsys  (ffbfd080, 3, ffbfd128, 0)
fef66f20 pselect  (ffbfd080, feff2530, feff2530, 40, ffbfd128, 0) + 1c8
fef67298 select   (8, ffbfdb18, 0, 0, ffbfdb10, 109400) + a0
0002852c getrequests (121744, 7, 7, 11c388, 11c2f8, 3) + 690
00048a94 main     (0, 13f800, 64, 10f800, 121c00, e8c00) + 5b68
0001f6e0 _start   (0, 0, 0, 0, 0, 0) + 108

Seeing this output you can grab the necessary information from the output.

Now question is how to confirm the process is hung or its no longer active.

Answer is –

Just take pstack of process in file and take the same after some interval of time and compare the files. If there is difference in files then process is active.

example : pstack 8979 >  a.txt

after x minutes pstack 8979 > b.txt

To check is there any difference in two files , run a command ‘diff a.txt b.txt’

Thank you people, stay tuned for more important useful knowledge.

 

If you know SCP, do you know SMV command

Hi Readers,

Greetings!! I hope you are doing great.

Today, I am going to tell you about the command which will work like mv but over the different servers/machines where Linux is installed.

If you want to copy any files from one machine to another machine then you should use scp command, that you must be known. If not, read about it. It’s very useful and easy.

Now, if you have the question like- We can copy files from any machines to another machine using scp command but what if we want to move files from machine to machine.

Here is the answer dear, you can use ‘rsync’ command.

If you don’t have a package then you can install on Linux.

Hint: you can use subcommand like ‘delete’, you can see so many options as per your requirement.

# rsync –help | grep delete
–del an alias for –delete-during
–delete delete extraneous files from destination dirs
–delete-before receiver deletes before transfer, not during
–delete-during receiver deletes during the transfer
–delete-delay find deletions during, delete after
–delete-after receiver deletes after transfer, not during
–delete-excluded also delete excluded files from destination dirs
–delete-missing-args delete missing source args from destination
–ignore-errors delete even if there are I/O errors
–max-delete=NUM don’t delete more than NUM files

You can also use subcommand – ‘remove’, here are the options for remove subcommand for rsync-

# rsync –help | grep –remove
grep: unrecognized option ‘–remove’
Usage: grep [OPTION]… PATTERN [FILE]…
Try ‘grep –help’ for more information.
[root@undercloud-0 openstack_cert]# rsync –help | grep remove
–remove-source-files sender removes synchronized files (non-dirs)

Thanks all for reading. There is no command like smv 🙂

I hope, this will add new things in your knowledge.

Stay tuned for more knowledgable blogs like this.

 

asyncio – the best way to write single-threaded concurrent code

Hi Readers,

Greetings!!

Today I am going to tell you about ‘asyncio’ which is library in python and mainly use to write  single-threaded concurrent code.

asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc

Main thing here is why should we go for asyncio instead of threading –

answer is – When you use asyncio, you decide when a piece of code take back control using await. On the other hand, by using threads, Python scheduler is responsible to handle this and a piece of code may lose control anytime. Hence, you have to use some locking mecanism to prevent anything bad to occur to shared memory.

Hope you will read more about it. 🙂

Keep reading for more knowledge like – coroutines and use of asyncio in coroutines.

Quick example –

Monitoring tool – ‘New Relic’

Hi Readers,

Greetings!!

Hope you are doing good.

Today I am going to write about the famous and very useful monitoring tool in the IT industry which is ‘New Relic’.

So, before that let me tell you short description and need of monitoring tool and what exactly monitoring tool is, if you are new in ‘devops’ field.

Monitoring tools are the tools/programs/software to monitor performance of any system.

It mainly use for the constantly/ continuously monitor the performance of computer systems/ servers/ servers over data centers/ on cloud to analyse whether systems are working as we are expecting. We can measure/monitor performance of networking, working/failing components is system is distributed and integrated, successful deployment, data copy speed, API request response speed, availability, reliability etc.

New Relic is a performance management tool and eventually solution which helps  developers, devops people, qa people, support people, system engineers to measure/diagnose and fix application performance problems in real time.

Like many other monitoring tools it provides an interface where we can see graphical representation of the things which we are monitoring.

Whats the difference between new relic and other monitoring tools?

To know the answer of this question, stay tuned to this blog, will come back to you soon. 🙂

Congratulations readers, today you earned some good knowledge about monitoring tool – new relic.

 

 

Always think about the improvement

Hi Readers,

You might have read my blogs till now related to technical things or musical things.

Today I am going to write about some philosophical things, which not only help you in your career but also throughout your life.

All of us want to improve, grow now a days(if you are not thinking like this, please start thinking like this)

The following is the statement which you should always keep in mind.

Statement is ‘There is always a scope of improvement, first you need to accept it, you should have self belief and good planning ‘

Let me explain the statement for you.

We should always think like there are some things in which I am lagging, so that you have to first accept it.

Once you accept the things, you should self belief so that you can convince yourself that you can do these things better.

Last but important thing here is you know your weaknesses, you accepted that, you have self belief and confidence to make change as per you desire, now you should have good plans ready including backup plans like plans A, B, C because many times we are not aware that the plan which we are following may fail in future.

So, always think about your improvement, don’t think in legacy way, don’t go with flow.

Keep focused, have proper plans, have backup plans ready, always be confident. Try to think out out the box in good way.

Thanks readers, all the very best.

 

 

 

 

 

My musical shows and lectures about philosophy and litrature

Hi Reader,

You might have read my blogs about the technical things in computer science. Thanks for it. I hope they were, they are helpful for you.

Today I am going to tell you about the shows I have been doing related to music and the lectures/talks I have been presenting.

I learned the Indian classical music and I performs classical singing performances with Harmonium and Tabla

I have been doing these show/presenting talks since my childhood.

I will explain you what exactly I does perform in singing shows and talks.

I does perform a show including Indian classical vocal, where I does  perform different ‘raags’ of Indian classical music. Also I does include bhavgeet, natyageet, bhaktigeet, abhang, thumari in my musical performances.

The does this kind of shows for 1 hour or it may vary from 30 minutes to 1 hour.

I also does separate shows for Indian old movie songs. It contains the song on which the great Indian legend worked like Mohmad Rafi, Kishor Kumar, Hemant Kumar, S.D Burman.

About the lecture/talks I does present:

I have been learning about Indian cultural, spiritual philosophy. literature by Indian sents likes sent Dnyaneshwatr, Namdeo, Eknath, Ramdas,Tukaram etc.

My lectures mainly contains the messages from sent literature to develope ultimate human personality.

Kindly reach out to me at

email: anandprakash44@gmail.com

contact no: +91 9921376482

020 24535120

To schedule my shows/ musical performances.

 

 

Good source of knowledge and problem solver for software engineers.