Posts

Showing posts from September, 2014

Fix git's "The remote end hung up unexpectedly" error

If you push your changes to a remote branch and get this error: error: RPC failed; result=22, HTTP code = 411 fatal: The remote end hung up unexpectedly Writing objects: 100% (460/460), 1.08 MiB | 0 bytes/s, done. Total 460 (delta 33), reused 0 (delta 0) fatal: The remote end hung up unexpectedly Just increase your git buffer (e.g 500MB) and it will be fine: $ git config http.postBuffer 524288000

Another morning

Image

Empty

Force git pull from remote

If you want to discard the commits you've made locally, i.e. never have them in the history again, you can just do a hard reset: # fetch from the default remote, origin git fetch # reset your current branch (master) to origin's master git reset --hard origin/master

Just a great moment

Image

Active Directory - Update AD users's field data starting with number ZERO from a csv file

Last Friday, when I was trying to update Active Directory users data from a csv file, I accidentally changed value of a very important attribute (let's call it the X field). X was a string of numbers which has a number ZERO at the beginning. And my company uses X to identify users in another system which requires ids in the form of 0xyz, and 1xyz. I exported all the users AD data, modified value of some of the fields, than updated back to Active Directory. I realized that X value of all users had been changed (without ZERO at the beginning). I totally forgot that csv/excel will ignore any number ZERO if it stays at the beginning of the number (e.g. 061898989 will be translated to 61898989). So, to change the value back to what It was, I did: 1. Export X value data of all the users to a csv file. 2. Add ZERO to the beginning of attribute X's data of all users (using a text editor, find & replace) 3. Make all field were quotes ("") 4. Update the modified...

Gunicorn error when running with Django1.7

If you running your django1.7 apps with Gunicorn, you will get this error: Traceback (most recent call last):   File "/home/.venv/ptc/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker     worker.init_process()   File "/home/.venv/ptc/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 114, in init_process     self.wsgi = self.app.wsgi()   File "/home/.venv/ptc/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 66, in wsgi     self.callable = self.load()   File "/home/.venv/ptc/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 105, in load     mod = util.import_module("gunicorn.app.django_wsgi")   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module     __import__(name)   File "/home/.venv/ptc/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 20, in <module>     from...

Docker - Install supervisord in a Trusty container

Because supervisord needs Upstart to be running but docker only runs one process at a time (When apt-get is running, upstart is not). So, to install supervisord in a docker container, I need to do some little tricks: Prerequisites # echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" >> /etc/apt/sources.list # apt-get update # apt-get upgrade To avoid the error " initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused " when installing supervisor: # dpkg-divert --local --rename --add /sbin/initctl # ln -s /bin/true /sbin/initctl Install supervisord: # apt-get install supervisor # ln -s /usr/bin/supervisorctl /usr/local/bin/supervisorctl References: [0]  https://github.com/docker/docker/issues/1024 [1]  http://docs.docker.com/articles/using_supervisord/

Docker - Trying to dockerize my Django app

I've spent sometime messing around the docker engine for couple days. I guess It's time to try dockerizing my Django app. Assuming I have already created a Ubuntu Trusty image  , open a container: Prerequisites: * The container (by default: eth0 - 172.17.0.2 ): python2.7, pip, virtualenv, mysql-client * The host machine (by default: docker0 - 172.17.42.1 ): mysql-server, grant permisson to the container host: MariaDB [(none)]> use appdb; MariaDB [appdb]> grant all privileges on appdb.* to 'myuser'@'172.17.0.2' identified by 'mypassword'; Inside the container: (mydjangoenv)root@93b3f27d3129:~# git clone https//my.git.repo/myproject (mydjangoenv)root@93b3f27d3129:~# cd myproject (mydjangoenv)root@93b3f27d3129:~# pip install -r requirements.txt (mydjangoenv)root@93b3f27d3129:~# ./manage run 0.0.0.0:8000 (remember to add the container's hostname ( 93b3f27d3129 ) to ALLOWED_HOSTS ) In the host machine:  Open the browser, ...

Docker - Install pip in a Trusty docker container

For some reason (maybe the source), I could not install python-pip  in the full Trusty docker container I created ( in the previous blog post ) using apt-get . So, easy_install is for the rescue : root@93b3f27d3129:# apt-get install -y python-setuptools root@93b3f27d3129:# easy_install pip

Docker - Create a full Ubuntu Trusty base image using tar

I tried to use the pre-built Ubuntu docker base image from official reposity: $ sudo docker pull ubuntu $ sudo docker run -i -t ubuntu:trusty /bin/bash but the trusty container only has python 3, and I could not install python2.7 or wget. It's such a pain in the ass. So, I decided to build the image myself using the following method: $ sudo apt-get install debootstrap $ sudo debootstrap trusty trusty > /dev/null $ sudo tar -C trusty -c . | sudo docker import - trusty 32f486151f08fa838fd6aa6b9e23b92ebc98e12e8ab36c173f23f71836c003d5 $ sudo docker run trusty cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=14.04 DISTRIB_CODENAME=trusty DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS" Now I can install python2.7 inside the container running on the new image: $ sudo docker run -i -t trusty /bin/bash root@2ff30118feb7:/# apt-get install python2.7 Reference:   https://docs.docker.com/articles/baseimages/

Docker - DNS setting in a default Ubuntu docker image

I just tried to create a container for my django apps this morning with docker. These were steps that I's following: $ sudo apt-get update $ sudo apt-get install docker.io $ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker $ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io Then I pulled the ubuntu images to my docker environemt: $ sudo docker pull ubuntu Execute the bash shell of the ubuntu image: $ sudo docker run -i -t ubuntu /bin/bash But, I could not install any package (e.g. python2.7). I could not connect to the Internet. I checked the DNS settings on the container and found that It's configured with Google's DNS servers by default which is forbidden in my company's network (8.8.8.8 and 8.8.4.4). But, the thing is I could not even change the DNS configuration on that Ubuntu image. So, I go back to the docker's documentation and found a way to indicate the dns server when running the image: $ sudo docker r...

edx-platform - Re-install Open EdX in Ubuntu 12.04 using the Configuration repo

As I mentioned in the previous blog post  about installing Open EdX using the Configuration repository, you can only run the bootstrap script successfully on a freshly installed Ubuntu server . Actually, you can do a re-installation of the Open EdX stack on the same server with an extra effort. There will be a couple of issues you need to solve in order to move forward. Here are some of them: 1. MySQL error: TASK : [ edxlocal | create a database for edxapp ] ******************************* failed : [ localhost ] => { "failed" : true , "item" : "" } msg : unable to connect , check login_user and login_password are correct , or alternatively check ~/. my . cnf contains credentials This means that your server has already been installed mysql server and have a different login privilege from the default. => Read this blog post to solve the error: http://iambusychangingtheworld.blogspot.com/2014/09/edx-platform-how-to-fix-my...

edx-platform - Install Open EdX on a freshly installed Ubuntu 14.04 server

Even though the official installation guide for Open EdX using the Configuration repository only supports Ubuntu 12.04 but you can actually using the same method to install an Open EdX instance on a freshly installed Ubuntu 14.04 server : Do not run the one-step install script because it has a platform check to make sure it only run on a Ubuntu 12.04 server: ... ## Sanity check ## if [[ ! "$(lsb_release -d | cut -f2)" = ~ $'Ubuntu 12.04' ]] ; then echo "This script is only known to work on Ubuntu 12.04, exiting..." ; exit ; fi ... You should install the stack manually following these steps: ## ## Update and Upgrade apt packages ## sudo apt-get update -y sudo apt-get upgrade -y ## ## Install system pre-requisites ## sudo apt-get install -y build-essential software-properties-common python-software-properties curl git-core libxml2-dev libxslt1-dev python-pip python-apt python-dev sudo pip install --upgrade pip sudo pip insta...

edx-platform - How to fix mysql error when installing OpenEdX using the Configuration repo

The installation method of Open EdX using the Configuration repository listed on github supposes to work only for a freshly installed server. So if you have already installed mysql-server, you will got this error: TASK : [ edxlocal | create a database for edxapp ] ******************************* failed : [ localhost ] => { "failed" : true , "item" : "" } msg : unable to connect , check login_user and login_password are correct , or alternatively check ~/. my . cnf contains credentials FATAL : all hosts have already failed -- aborting To fix this error and continue the installation process, create the /root/.my.cnf file with the following content: [ client ] user = root password =< your root pass > [ mysql ] user = root password =< your root pass > [ mysqldump ] user = root password =< your root pass > [ mysqldiff ] user = root password =< your root pass > Run the installing script ...

Parental Control in Ubuntu 14.04

Image
There are some good solutions for doing Parental Control in Ubuntu 14.04. One is SelfControl which is a fork from the Mac OSX version ( installation instructions ). But, one of the SelfControl's shortfall is that It only does the web content filtering, and without a scheduling functionality (It only allows you to block a certain website in an amount of time). Luckily, there is another Parental Control software for Linux called gnome-nanny . Beside web content filtering, gnome-nanny also helps you to control the PC, mail client, and Intant messaging use time: Official repo: https://github.com/GNOME/nanny To install gnome-nanny in Ubuntu 14.04: $ sudo add-apt-repository ppa:boamaod/nanny-test $ sudo apt-get update $ sudo apt-get install nanny Nanny's Ubuntu packaging repo: https://github.com/boamaod/nanny-ubuntu Nanny's Ubuntu PPA:  https://launchpad.net/~boamaod/+archive/ubuntu/nanny-test