Sunday, September 28, 2014

Start Services on Boot in Rackspace

Rackspace provides Redhat servers. Suppose we are deploying a web application on a server. The web application uses many services - http service, search service(elasticsearch), caching service, database service(mysql, mongodb), etc .

There may be cases where would need to reboot the server. In such scenarios, the above listed services, when the server reboots, might not start. This is where the utility named chkconfig helps.
chkconfig --list
The above command lists the services which can be configured to start on boot-up. The first column lists the name of the service while the rest of the columns tell at which runlevel the service is started.

Runlevels control which services are automatically started by the system when the system starts in that runlevel. Here is the link that explains run level more explicitly. On a sidenote, to make the concept of a runlevel more clear, we can specify runlevel at the time of boot in the grub file. Runlevels are really helpful, when we want to enter the terminal and edit the messed up startup scripts which prevent normal system boot. This link will be helpful to understand my point.
Coming back to chkconfig, it is really easy to include services in chkconfig and specify the runlevels at which they will be started.
chkconfig --add SERVICENANE
Using the above command, we can add the service in the runlevels specified in the init script of that service. For example, the is the init-script of elasticsearch:
## /etc/init.d/elasticsearch


#
# elasticsearch 
#
# chkconfig:   2345 80 20
# description: Starts and stops a single elasticsearch 
#              instance on this system 
#

### BEGIN INIT INFO
# Provides: Elasticsearch
# Required-Start: $network $named
# Required-Stop: $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: This service manages the elasticsearch daemon
# Description: Elasticsearch is a very scalable, schema-free and 
#              high-performance search solution supporting multi-tenancy 
#              and near realtime search.
### END INIT INFO

The might be cases where the service is not recognized by the chkconfig even though it is located in /etc/init.d. This is because the above lines (see the above code) are not added in the script. Though these lines are commented, they are used by the chkconfig to recognize it as a service that can be added at boot. For example, I used Nginx to serve http requests. The nginx init script (/etc/init.d/nginx) did not have the above code block. This is what I added at the beginning of the file after #!/bin/bash to make it chkconfig friendly.
# 
# nginx         Service that starts and stops the http server
# chkconfig: 2345 95 05
# description: HTTP server
# processname: nginx
# config: /etc/nginx/conf/nginx.conf
# pid: /opt/nginx/logs/nginx.pid
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Short-Description: start and stop nginx server
# Description: HTTP Server
## END INIT INFO


Now, if I want to add a particular service to say, runlevel 2,3,4,5 - then, this is the command that I will execute:
chkconfig --level 2345 SERVICENAME on
You can figure out more use cases for chkconfig by viewing its manual.

Sunday, January 26, 2014

An Experience to Remember

Sitting with the bunch of students, I, being one of them, felt completely lost. I was oblivious of the coming lecture. Didn’t know who the professor was. The feeling of blankness was weird, considering the fact that I got decent grades. The benches, were surprisingly designed for only one student. One student per bench. I felt comfortable. Finally the teacher arrived. It was difficult to recognize his face. I hadn’t seen him before. So he started with some jokes, to which all the students were laughing except me. I was clueless. Anyways, the teacher told that since its the first day of the week, he won’t be teaching anything, but would be asking questions and hold discussions of what happened last week. Out of nowhere, he again, cracked some funny joke and all the students burst out laughing. Everyone seemed excited at the idea that they would be asked questions. This was the first time, I felt that I was completely out of ground over here. Totally unprepared, unaware of the subject, unrecognizable face of the teacher, all these things made me a bit scared.

So the round of questions began. He was asking randomly, allowing the students to raise their hand and answer them. Sometimes, he even pointed out a particular student and asked him a specific question. I felt frightened by this. I felt that he had noticed my fear, and was eagerly waiting to give me a chance to answer a  simple question. After listening to the bunch of questions, I suddenly realized, that the subject being discussed about here was Physics! Suddenly the professor pointed at me, and asked me a really easy question. I could feel it as easy, because all the students were eagerly looking at the teacher, so that even if he makes a single expression of approval to any one of them, they would blurt out the answer. I, completely listless, stared at him. He seemed disgusted by me and turned away leaving the question to be answered by someone else. I felt relieved that I was not punished, because by the look of his face, I felt like I had done the worst crime possible.

In the meanwhile, a friend of mine, on the front bench, turned to me and started pulling some joke on the teacher. In reply , I smiled and the professor caught hold of my sight. He got a perfect opportunity to lend me a harsh punishment. Rushing towards me with an evil smile that finally he found someone that he can spurt his anger on, he took my hand, grabbed me forward and started hitting me on the back, simultaneously pushing towards the door to throw me out of the class.

First thing that came to my mind while getting hit - that this is not me. I rarely go to classes unprepared. Even if I do, I am not so dumb to have forgotten the name and face of such a terrible teacher. I would surely remember him. I was pleased with my thoughts at that moment. I never thought so much before. Then, I suddenly realized that I am not in a school anymore. I got a decent job, a good life. So why am I present in the school, as a student? After thinking for some time, it dawned on me that I was in a dream. I felt surprised that I could be conscious in my dream too. This had never happened before. I thought that instead of being awed at the events, I should better try to handle them. I was being beaten mercilessly, but the teacher seemed to have just started. Suddenly I got a really amazing thought. Why don’t I make the most of this dream, do something that I wouldn’t have even dreamt about, try to fulfill all my dark fantasies (:evil smile:).

I don’t know how did it came there.but I suddenly grabbed the iron pipe and hit the teacher on his head. I took care  not to hit him too hard that he start bleeding but intense enough that he start screaming. Next, I ran from there as fast as I could with the pipe in hand. My class was on the third floor, and I wanted to reach the ground. I wanted to find some nice teachers on the way, if possible, and thank them for everything that they did for me. There were two three names that came to my mind. So hoping to find them while running, I reached the play ground. Sadly I wasn't able to find anyone. I didn't know why I was in a hurry, trying to do everything as fast as possible. Reaching the ground, I suddenly found my classmate whose presence really irked me. He was someone who pretended he knew everything but was a dumb ass in reality. I felt a surge of anger and excitement, and ran towards him with the pipe. On seeing me, he ran too. I stopped midway trying to catch my breath. I had never run so much before. He, standing a few paces away from me, was giggling at me. I felt angry again and resumed running. 

On the way, my sight caught hold of a beautiful computer science teacher who was talking to someone. She wore a glittering black and white dress, her head covered in a black dupatta. She was insanely cute, with her fair skin in perfect contrast with what she was wearing. I was her favorite student as I used to get really good marks in her subject. Then I thought suddenly, that this probably might be the only dream, in which I am perfectly aware of who I am. What should I possibly do. to make this dream the perfect dream ever? Finding my answer, I stopped running, forgot about that irking boy, dropped the pipe and started moving towards her. I was careful, that she doesn’t recognize someone rushing towards her. Finally, standing beside her, before she could see me, I tried to grab her, with a surprisingly strong force. She fell into my arms, and before I or she, could think of something, I kissed her. I felt my lips touching hers delicately and it felt like the most wonderful thing ever happening to me. I wouldn’t let go of her lips. I took care not to push myself too much to make her feel uncomfortable. I wanted her to have a memorable experience too. She resisted initially but gave away in few moments.

Accomplished almost everything that I had thought of, I opened my eyes to the dim reality.

Monday, January 13, 2014

A night traveling via Train

It’s been long since I have traveled in sleeper class.The platform near sleeper class is crowded. and the quality of the crowd is really depraved. It also depends on the quality of the train - if it is Rajdhani, everything looks good, but other lower level trains, all is pathetic. In terms of cleanliness in the compartment too,  Sleeper class comes below everything (not considering the General Compartment here). The coach vibrates a lot compared to an AC one, less no of lights,  no separate lights for reading,  no charging port. I brought a novel thinking that I would read,  but the intense vibrations,  the commotion created by the people,  the rhythmic but loud noise of  the running train,  all of this made it impossible for me do anything other than lying around I couldn't even listen to songs.

I don't know why one would like to travel in a train. I don’t find any valid reason except the fact that you get to see the variety of people over here. Variety in terms of caste, religion, language,  age,  sex,  the so called eccentric personalities (esp. the people who act as loudspeakers) There is one thing though which i like -  those are the children.  they seem to me the funniest beings capable of entertaining everyone around them without realising it. I am talking about the kids in the age group of 2-10. Kids, if too small, cry a lot,  and they are a nuisance when their parents are unable to make them not cry.  Apart from that,  one thing that I think I like in trains is -   sitting near the window in the daylight gazing at the unending greenery,  shining tracks in parallel,  the occasional sight of dogs or farmers with their animal companions on the field,  small huts in the midst of vast stretches of open fields, etc. But all of these tend to get boring after some time.  and monotonous.
This time, I had a couple sitting opposite to me,  hand in hand,  watching a movie on a laptop.  the girl seemed to be from Rajkot.  Rajkot people have a unique accent.  One can pick them out easily,  She was extremely talkative, but the rhythmic rajkoti accent of hers made her voice bearable,   Her lover seemed to be doing a pretty nice job of listening.  Also,  they were at the receiving end of eye popping glance of the elderly people sitting at the other end.  People in this country have a difficulty minding their own business.

On a side note, I , sometimes, wonder why so many couples are the followers of public display of affection.  What makes them curl hand in hand,  leading to them being the cynosure of all eyes.  why be the center of attention for no good reason?  Why not control your emotions or hormones or whatever it is, to the point where it actually makes sense to display it.

The worst part, my berth was the end of the coach. And it is winter time. I had two jackets on plus a blanket. The worst part was, the door of the train could not be latched. Due to this, the opened door in the middle of the chilly night on the running train, gave me intense chills. Unfortunately, I brought a thin blanket with me, thinking that having wore two jackets already, I won’t need anything else. The Result - I couldn’t sleep properly as I woke up frequently being on the receiving end the stream of chilly air from the opened door.


Overall, the experience was new and eccentric. But I ain’t sure whether I will try taking the Sleeper class the next time I am travelling via train.