Friday, June 10, 2016

haproxy on Centos 7 with SELinux

Setting up haproxy and varnish with reference to the configuration from these sites: http://sharadchhetri.com/2014/12/20/how-to-install-varnish-4-version-on-centos-7-rhel-7/ https://www.upcloud.com/support/haproxy-load-balancer-centos/ And finally can access plone on the server. But when I check the haproxy status, only client1 can be accessed. All other clients were down with general socket error, permission denied. Googling a bit I finally found out it was due to SELinux. Refer to this page: http://stackoverflow.com/questions/26420729/haproxy-health-check-permission-denied With the solution from that page, I installed policycoreutils-python and tried to run the command given:
semanage port --add --type http_port_t --proto tcp 8081
But that command failed with the error that the port was already defined. When I looked it up using:
semanage port -l | grep 8081
It belonged to some other type (transproxy_port_t). When I tried to delete the type using:
semanage port -d -t transproxy_port_t -p tcp 8081
Got the error that it belongs in the policy and cannot be deleted. After much frustation and further googling finally found out I can modify the port
semanage port -m -t http_port_t -p tcp 8081
And finally haproxy was able to use the other clients. Finally.....

Thursday, June 9, 2016

Installing Centos 7 on HP G7 Server

When I first initially tried it, the installer cannot detect any local hard disk to install to. After much googling found out that it was because a certain driver for the Smart Array Controller is no longer available on Centos 7. To allow for use of the new driver on old hardware, you need to enable the option. Once the DVD has booted and on the first menu screen, highlight the first option and then press tab which would bring you to a command line where you can add additional parameters to boot. Add the following parameters:
hpsa.hpsa_allow_any=1 hpsa.hpsa_simple_mode=1
And then press enter to boot. You should now be able to install as you wish. After installation, on the first boot, make sure at the menu, press 'e' to edit the parameters and add them again. Then once booted, go to /boot/grub2/grub.cfg to permanently add the parameters to the menu. Refer to http://serverfault.com/questions/611182/centos-7-x64-and-hp-proliant-dl360-g5-scsi-controller-compatibility and it's comments for the explaination.

Monday, October 19, 2015

Code base to jump start flask-classy system

This post is just to announce my sharing of a source code base which can be used to jump start development using the python micro framework flask and it's excellent extension flask-classy. Do note that this code base uses the Ace Admin bootstrap theme. Please purchase the license for your use from wrapbootstrap or remove it from your source code referencing it.

To begin, you need to clone the repository using mercurial:
hg clone https://bitbucket.org/abdza/flask-classy-base-system examplesystem

Then you need to create the virtualenv for your system:
virtualenv --python=/usr/bin/python2 examplesystem

Do note that my example here is running on arch linux which uses python3 as the default python version. I suggest the above command to use python2 in your virtualenv because it makes things easier to migrate to systems using python2 (eg ubuntu, centos and others).

The you need to go into the directory and activate the virtualenv:
cd examplesystem
source bin/activate

Then you need to install all the required python modules into your virtualenv:
pip install -r requirements.txt

Once all that is done you need to configure your database access by editing the file app/config.py
Update the SQLALCHEMY_DATABASE_URI line with your own database setting:
SQLALCHEMY_DATABASE_URI = 'postgresql://<username>:<password>@localhost/<database>'

So for this example I changed it to:
SQLALCHEMY_DATABASE_URI = 'postgresql://exampleuser:examplepass@localhost/exampledb

You'd probably want to update the SECRET_KEY, APP_NAME and COMPANY_NAME too.

Then you need to create the appropriate postgres database, role, grant and allow the user to login.
sudo -u postgres psql
postgres=# create database exampledb;
postgres=# create role exampleuser with password 'examplepass';
postgres=# grant all on database exampledb to exampleuser;
postgres=# alter user exampleuser login;
Then you can test the user and database connection:
postgres=# \c - exampleuser
postgres=> \c exampledb
If there is no error, then you can continue to the next step after you quit postgres:
exampledb=> \q
You then need to init the database by running:
./run.py db init
./run.py db migrate
./run.py db upgrade
That should get your database updated with all your models (which currently is only User)
You can try running it now:
./run.py
Then in your web browser go to the address below and register your new user:
http://localhost:5000/user/register

After all of that, you should probably edit your .hg/hgrc file and point the default path to your own repository.

Once everything is set, you can begin your development. Add a new model by adding a file in the app/models directory. For example lets add the file app/models/Post.py:
from app import db

class Post(db.Model):
 id = db.Column(db.Integer,primary_key=True)
 name = db.Column(db.String)
 content = db.Column(db.Text)

Then you need to tell your app about the existence of this model by adding the following line to app/models/__init__.py:
from Post import Post
Once you have added your model files, you can generate the view associated with that model:
./run.py genview

You can then see the generated view files at app/views/PostView.py

Before you can view the view in your web browser, make sure your database get updated first with your newly added model:
./run.py db migrate
./run.py db upgrade
Then you can view the view page by pointing your web browser to:
http://localhost:5000/post

You can then start editing the view for your model and your processes. For example we can add the Post field in your form by changing the ItemForm class in your app/views/PostView.py:
class ItemForm(Form):
 name = StringField('Name',validators=[DataRequired()])
 post = TextAreaField('Post')
That's all for the introduction to this code base. Hope it is useful for you to jump start your development using flask and flask-classy.

Wednesday, June 3, 2015

Hard Link In Rsync

I've been struggling for a few days trying to backup a folder using rsync. The folder is huge but there should be enough space on the destination server. But everytime I did a backup it never finish because the hard disk is full. It seems like the destination folder became bigger than the source folder after using rsync. After much googling, I found out that it might be because of the way rsync handles hard links (which is it creates a new file for each link). Refer to Directory backed up with rsync is much bigger than source . So finally to do the backup properly, the command I had to use was:

rsync -H -a -vv -z -e 'ssh'

Saturday, April 11, 2015

Write everyday

They say you should write everyday. Write everyday to get better. Will I get better. Will I write everyday?

Does it matter whether I get better at it? Sure it sounds like something I should strive for, but would it finally be worth while in the end?

Maybe I should do it, maybe I shouldn't.

Maybe in the end I will end up doing what I should be doing.

Sunday, December 21, 2014

60 days no rice challenge, my experience

Just a few days before deepavali this year I started learning and practicing goal settings. Setting up your goals and achieving them step by step. One of the ideas about goal setting is that you can learn to get used to setting goals and achieving them. The more you are used to setting goals and achieving them then the more you would be able to set and achieve. Something more the less like that...

Quite a coincidence around that time I saw on my facebook feed the hashtag #60daysnoricechallenge. I thought, "Well, that's a good way to practice goal setting and getting my mind and habit into it. I'll give it a shot". So that was the reason I started the 60 days no rice challenge. Not really to lose weight or anything, but just as a way to practice setting and achieving a goal. But a lot of people didn't know that at the time and when they started to see the hashtag #60daysnoricechallenge on my feed assumed that I was doing it for weight loss. And here's where it gets interesting.....

As part of the 60 days challenge, I would post on my feeds (facebook, instagram, twitter) a picture of the meals I'm taking everyday that was proof that I didn't take rice. And in the first few days when I started posting I got a lot of feedback... a lot.... Most of the feedback was of the kind that gave some moral support, but there was some that gave "advice" on how to lose weight, and some others were just "well, that's made out of rice flour too so you are technically eating rice"... :/ I thank you all who took the time to give feedback on my posts. It was heart warming for me to see so many people are quite concerned about me and my health. But yeah, technically I wasn't doing it to lose weight. And thus my avoiding of rice was limited to only things that "look" like rice including pulut and others and not including things that doesn't look like rice at all even though it was made of rice flour like kueh teow and such. But as expected the amount of feedback started to dwindle down after a few days. I guess there was only so many things one can actually say about those posts. But in less than 10 days the feedback almost died out except for a few likes (which was an easy thing to do, just click the icon) and a few people who was really persistent and I should probably give them an award or something... :P So that was interesting, my goal setting practice became some sort of social experiment.

So apart from just practice settings goals, was there any impact? Well... there is some.

First off, I've lost a few kilos. I'm not sure exactly how much because since I didn't do it to lose weight I didn't actually weight myself just before I started and kept a tab on my weight. But the heaviest I've weight myself before the challenge, I was around 148kg. And just as of yesterday, I was around 142kg. Now I don't really consider that as loosing much (just 6kg) because I could easily gain all that back within just a few days (experience from many ramadhans before this.. :P) But still, I do feel a bit better about myself. My belt notch has gone down by 2 holes and I do feel a bit more awake and energetic than before I started the challenge. So yes, even though I started the challenge not to lose weight and stuff, there is some real physical benefit of doing it.

But for me, more than those physical benefit, it's the mental impact that was startling. Yes, I didn't do it to lose weight so I didn't mind eating more of everything else to "compensate" for not eating rice, but since I'm watching to make sure I don't eat rice, I am so much more aware of what I eat. And the thing is, we eat so much rice every single day. And we don't feel it, we are not aware of it. For example, after having kueh teow goreng for breakfast for almost 3 days, I got sick of it and tried to look for something else. But with rice, we don't get sick of eating rice. Today it might be nasi lemak, tomorrow nasi dagang, the next day nasi goreng, the next day nasi bubur. All that is just the breakfast menu and we don't get sick of it ever. Heck, even nasi lemak you can have it in a variety of ways by mixing and matching the lauk you eat it with. You can have all kinds of variety of nasi 3 times a day every single day and you still would not be sick of it. Amazing... So more aware of what I eat is a good thing.

Another mental impact is just the amount of effort it takes to not eat rice. This has a lot to do with the first point of us eating so much rice that it is on the menu all the time. In some places they only serve rice so finally you end up just eating the lauk. And it tickles me that some of my friends would start considering the places to eat and thinking "but what would dollah eat there". My answer to that is "I'm just not eating rice, not going vegetarian or anything. So it really doesn't matter". In the early days of this challenge, I was really reeling back from the mental effort of avoiding rice. I was thinking on the 61st day I'm so going to get my revenge. I'll eat all kinds of rice meals 3 times a day and probably more. But once I got more and more used to it, the urge is no longer there. So now it is the 61st day and I've decided that I'll continue to avoid rice as a personal choice rather than because of a challenge. So once in a while I'll partake in a rice meal if it's some sort of special occasion, but I'll try my best to avoid it at normal times. With regards to that, I'm reserving my first rice meal for the wedding of my good friend Darmawan. So it'd better be awesome Dar.. :P

And finally, another impact of the challenge was, at least 2 people I know off actually started the 60 days no rice challenge too because they were inspired by me.. :P Good luck guys.. insyaAllah you will find it beneficial.

So that wraps up my thoughts and experience of the 60 days no rice challenge. It has been pretty good and I'm glad I did it. 60 days no rice challenge, accepted and DONE...   :D


Wednesday, October 8, 2014

Painless Functional Specs

Documentation.... Documentation never change.... (end fallout war never change reference)

I don't particularly like documentation. Sorry, let me rephrase that. I LOVE good documentations, I just don't like doing them. That being said, I need to start to really learn how to do it properly and meaningfully so that I too can generate great documentation which everyone loves to refer to but doesn't like to do. So where do I start? From the legend himself, Joel Spolsky. You can read them from his old blog but I'm just going to do a summary here for my own reference.

His first essay is on why functional specs should be done. Well, it's so that Bob the programmer know what to code out, it's so that Tina the marketing exec knows what features are available and what to say to the customers, it's so that Dol the manager knows what on earth he is managing.

Next, he outlines what should be in a spec. In short there should be

  1. A disclaimer
    • A paragraph saying "This spec is not complete" will avoid people coming to bite your head off
  2. An author. One author.
    • Specs should be owned by someone. A real person. Not a group or a committee but an actual breathing, living person who will take responsibility for the spec. A large program can have many small specs written by one person each.
  3. Scenarios
    • Think of some real live scenarios for how people is going to use it
  4. Nongoals
    • Cull features straight away to avoid infinite time and cost
  5. An overview
    • Everybody who reads this will get the big picture, then the details will make more sense
  6. Details, details, details
    • Mind numbing detail
  7. Open issues
    • It's ok for the first version of the spec to have open issues
  8. Side notes
    • Useful factoids which might be useful to just one of the group of audience for the spec
  9. Specs need to stay alive
    • The specs always reflect our best collective understanding of how the software would work
In the third installment of the writing, he mentions about the importance of the Program Manager. 

And in the fourth and last installment he gives some tips for spec writing. They are:
  1. Be funny
  2. Writing a spec is like writing code for a brain to execute
  3. Write as simply as possible
  4. Review and reread several times
  5. Templates considered harmful
And that is all more the less what I need to know. So here I go writing out specs like a boss.....

Is Blogging No Longer a Thing?

As I embark on my new journey to learn the Rust programming language, I find myself pondering—where have all the blogs gone? In search of pr...