Thursday, September 14, 2017

Notes on AWS Lightsail

Finally, I'm trying Amazon Lightsail. Just few notes:-




1. The direct console is great. This is basically what EC2 should have, instead of web ssh console. You need this console to verify the ssh key fingerprint before connecting through ssh first time.
2. There's simple firewall manager. Only port 22 and 80 opened by default. Click Manage from the instance menu to get into the firewall manager.
3. Now there's apac region !

Friday, September 8, 2017

A brief look into nginx unit

So nginx has come out with it's own application server that can run multiple types of application from PHP, Python and Go, with more languages support coming soon. Deployment is always my topic of interest so this kind of news definitely caught my eyes.

There's not much technical information yet, other than the official blog post. I'm quite interested to know how the python support being implemented. The Application model also remind me to the Webfaction hosting model and with unit HTTP API, it provide possibility to implement something like Webfaction hosting panel where you can add new application and manage it all through just a web interface.

Reading through the source code of python module support, it look like python wsgi application is being executed in-process through python C API (my guess), particularly if you look at the line 337:-

result = PyObject_CallObject(nxt_py_application, args);

For Go application however it simply execute the Go built-in http server and communicate through that. The current implementation is merely 100 lines compared to python implementation which is almost 1000 lines.

Enough with all the theories, I decided to give it a try. It has deb packages for Ubuntu Xenial. Just follow the documentation how to install it through apt. The docs however seem missing on how to start unit after installing it. After scouring around the apt file then I know the binary is named as unitd, so to start it:-

sudo systemctl start unitd

After that you can start communicating with unitd through the HTTP JSON API:-

sudo curl --unix-socket /var/run/control.unit.sock http://localhost/

Btw, it also through this I learned that curl has unix socket support !

For the rest, you can just follow the docs. I did try with simple wsgi applications and discovered few issues:-
  • https://github.com/nginx/unit/issues/17 - How to apply changes to our app script ?
  • https://github.com/nginx/unit/issues/16 - All applications and listeners lost after restarting unitd
  • https://github.com/nginx/unit/issues/12 - How to inject environment variables ?
  • https://github.com/nginx/unit/issues/15 - How to add venv packages ?
That's all for now. Next probably trying it from source instead of packages to get all the latest changes.

Tuesday, August 15, 2017

List of DNS server software

It's been quite a long time I'm not following the recent development in dns scene, especially on the server software itself. In the past, I did try setting up my own BIND installation just to understand how all these things work.

I tweet reminded me back:-
So what else dns server software we have these days other than BIND 9 ?

  • PowerDNS (as in tweet above).
  • CoreDNS - now also a server type plugin of Caddy. It's a successor of SkyDNS.
  • SkyDNS - SkyDNS is a distributed service for announcement and discovery of services built on top of etcd.
  • Knot
  • NSD

Monday, July 24, 2017

How smart-contract is possible in blockchain ?

The idea was derived from the scripting support in bitcoin. Part of bitcoin transaction contain a Script, a stack based language that will be executed to verify the transaction. Complex conditions can be expressed in this language, which has 80 different opcodes including arithmetic, bitwise operations, string operations, conditionals, and stack manipulation.

This language however still pretty limited, such as not having loop and thus not Turing complete. So new blockchain implementation like Etherium expand the idea further to include support for real programming language, thus enabling more complex conditions to the blockchain transaction, which now commonly known as smart-contract.

Sunday, June 11, 2017

How to build your own programming language

I've always fascinated in how programming languages are built and have made it into my 2017's new year resolution to learn building one myself. So here are all the notes collected along the way.

My presentation at Malaysia Open Source Conference - How to build your programming language ? I plan to extend this presentation at upcoming PyCon APAC in this August with an example in Python.

A write up in Malay - Bagaimana bahasa pengaturcaraan dibina ?

A series on building simple interpreter in Python by Ruslan Plivak - Let's Build a Simple Interpreter !

A book on writing an interpreter with Go (Golang). I'm still making up my mind whether to buy this or not - https://interpreterbook.com/.

Free book on building interpreter using Java and then C. This is not complete yet but the author also recommend Interpreter book above in his reply to my reddit's comment.

A classic on building compiler, the original essay was using Pascal. This is my first time trying Pascal and to my surprise the example code (from 1986) still compile in the modern FreePascal - Let's Build a Compiler.

A question on reddit on how to build own programming language.

Creating toy programming language using Python PyParsing library.

An Intro to Compilers - A step by step guide on how a simple "Hello World" in C get pre-processed, tokenized, parsed, optimized and finally compiled to machine language using LLVM frontend and backend tools. Very interesting read and easy to understand.

Friday, December 23, 2016

My Python Workflow

This is basically what I did whenever starting on new Python project.

mkdir project_name
cd project_name
wget https://bootstrap.pypa.io/bootstrap-buildout.py
vim buildout.cfg

Where my buildout.cfg look like:-

[buildout]
parts = main

[main]
recipe = zc.recipe.egg
eggs =
    python-telegram-bot

interpreter = python


Then I just execute the following to get my new python environment initialize:-

python bootstrap.py
./bin/buildout

A python interpreter that already has access to my packages dependencies - in this case python-telegram-bot is ready in ./bin/python.

I'm a fan of buildout and shall write more about it in later post.

Friday, September 11, 2015

Trying out Ajenti

Ajenti is server control panel, in the same space as Webmin. It allow you to manage your linux server directy via web interface.

In term of installation, Ajenti really win. All available as OS packages, so if using Ubuntu or Debian it just a matter of apt-get. The initial installation is covered by a script that you download from Ajenti's website.

wget -O- https://raw.github.com/ajenti/ajenti/1.x/scripts/install-ubuntu.sh | sudo sh
One thing that tripped me up is that I thought the web hosting plugins also in the same packages. Turn out it a separate package called ajenti-v (It clearly shown on the website, so my bad). To get the webhosting packages you need to install ajenti-v package.

sudo apt-get install ajenti-v ajenti-v-nginx ajenti-v-mysql ajenti-v-php-fpm php5-mysql ajenti-v-python-gunicorn

If you have already install apache2 before, you need to remove it as Ajenti-v use nginx.

The whole experiences of getting a Django website running is still not very smooth. Those who are not familiar with Python deployment might be in hard time trying to fit everything together. This is I some room that I want to explore me in Ajenti-V. In order for this to be really usable, we don't have to touch the terminal at all to get things running.

The first problem I got is 
supervisor FATAL Exited too quickly (process log may have details). This turn out that I don't have gunicorn installed in the virtualenv set for my site. There are lot of things that need to be set - virtualenv, install gunicorn, the path to wsgi script.

One that taking so much of my time is figuring out why nginx keep doing 301 redirect for static files. In the end, I have to choose the 'root' method instead of 'alias' in nginx location.

http://nginx.2469901.n2.nabble.com/stop-automatic-trailing-slash-addition-td7592389.html
http://wiki.nginx.org/HttpCoreModule#alias

There's a subtle difference between root and alias.