<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.7">Jekyll</generator><link href="https://garry.bhatt.al/feed.xml" rel="self" type="application/atom+xml" /><link href="https://garry.bhatt.al/" rel="alternate" type="text/html" /><updated>2020-07-20T15:56:25-07:00</updated><id>https://garry.bhatt.al/feed.xml</id><title type="html">Garry Bhattal</title><subtitle>Software Engineer with a passion for clean code and disruptive ideas</subtitle><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><entry><title type="html">What is the DevOps model and what advantages does it bring to your workflow?</title><link href="https://garry.bhatt.al/what-is-devops" rel="alternate" type="text/html" title="What is the DevOps model and what advantages does it bring to your workflow?" /><published>2020-07-21T10:00:00-07:00</published><updated>2020-07-21T10:00:00-07:00</updated><id>https://garry.bhatt.al/what-is-devops</id><content type="html" xml:base="https://garry.bhatt.al/what-is-devops">&lt;p&gt;It’s 2020 and although DevOps is a practice that’s very commonly adopted today, I feel that a not too overly technical explanation of the subject might be beneficial to those individuals, or companies, that are not using it yet but find themselves in a position where it makes sense to use such model. Moreover, if you’re completely or partially new to this subject, this is a great place to start!&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2020-07-16/devops.gif&quot; alt=&quot;DevOps&quot; /&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;so-what-is-this-devops-thing&quot;&gt;So what is this DevOps thing?&lt;/h2&gt;

&lt;p&gt;DevOps can be defined as a combination between cultural philosophies, practices and tools.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;cultural philosophy&lt;/strong&gt; aspect is about changing how you develop and deploy software. In the DevOps model people who take care of software development and people who take care of operations (by managing, monitoring and operating infrastructure) work very closely together; sometimes the two roles are combined together. The DevOps term originates exactly from here: &lt;strong&gt;Dev&lt;/strong&gt;eloper &lt;strong&gt;Op&lt;/strong&gt;eration&lt;strong&gt;s&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Next, there are &lt;strong&gt;practices&lt;/strong&gt;. They help you to understand how the DevOps model works, in practice. Don’t worry if you have no idea what these are, more on them in just a moment:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Continuous Integration&lt;/li&gt;
  &lt;li&gt;Continuous Delivery&lt;/li&gt;
  &lt;li&gt;Microservices&lt;/li&gt;
  &lt;li&gt;Infrastructure as Code&lt;/li&gt;
  &lt;li&gt;Monitoring and Logging&lt;/li&gt;
  &lt;li&gt;Containerization &amp;amp; Orchestration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, &lt;strong&gt;tools&lt;/strong&gt;. These, along with the aforementioned practices, will help you to concretely adopt the DevOps model. Some of the relevant tools are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Git&lt;/li&gt;
  &lt;li&gt;Jenkins&lt;/li&gt;
  &lt;li&gt;Docker&lt;/li&gt;
  &lt;li&gt;Kubernetes&lt;/li&gt;
  &lt;li&gt;Automated testing libraries/frameworks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The DevOps model will improve every aspect of the application lifecycle, from development and testing to deployments and production rollouts. The team relies on automation to speed up manual processes and, thanks to the appropriate tools, applications can grow in a rapid and flexible way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DevOps is first of all a mentality shift&lt;/strong&gt;, where you are required to change the way you approach software development and release. While it may be good to have one person to be the leader of this change, you should make sure that your whole team/company is ready to take the leap.&lt;/p&gt;

&lt;h2 id=&quot;lets-dive-deeper-into-the-practices&quot;&gt;Let’s dive deeper into the practices&lt;/h2&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2020-07-16/tools.png&quot; alt=&quot;DevOps tools&quot; /&gt;
  &lt;figcaption&gt;DevOps tools&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h3 id=&quot;continuous-integration&quot;&gt;Continuous Integration&lt;/h3&gt;
&lt;p&gt;It is composed by two main elements: a cultural one and a technical/automated one. The cultural part consists in learning how to make frequent integrations. In other words, developers should not wait an excessive amount of time before merging their commits into the rest of the project. The technical/automated part is represented by the tools that helps automating these frequent integrations. Jenkins, for example, is a popular open source tool widely used for this. Continuous Integration solves the problem of heavy integrations and it helps reducing time spent solving merge conflicts. Statistically, the longer you wait to merge the more chances you will incur in a conflict. Merge often to avoid this!&lt;/p&gt;

&lt;h3 id=&quot;continuous-delivery--deployment&quot;&gt;Continuous Delivery / Deployment&lt;/h3&gt;
&lt;p&gt;It extends Continous Integration by automating deployments to staging and production environments. These deployments can have pre-requisites such as automated tests; they can even go beyond Unit Tests and require interface tests, load tests, integration tests, API reliability tests and so on. There is a difference between Continuous Delivery and Continuous Deployment. With C. Delivery you will automatically deploy on a staging environment and manual approval will be required if you want to deploy in production. With C. Deployment you go one step further and also automate production rollouts. You can use Jenkins for this or you can search for more specific tools that will hook into the Continuous Integration offered by Jenkins. This practice will help you reduce human errors and time required to complete the deployment process.&lt;/p&gt;

&lt;h3 id=&quot;microservices&quot;&gt;Microservices&lt;/h3&gt;
&lt;p&gt;It is a type of architecture used to build an application or a set of services. The application is based on a smaller set of services that communicates with each other through, for example, HTTP APIs. Each microservice has its own responsibility and the application is broken down into microservices according to the needs of the application domain. Frameworks or programming languages can be used to write microservices and distribute them, either individually or as a group of services. With this approach, our application will have the following benefits:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;More easily maintainable. You only touch the microservice you need.&lt;/li&gt;
  &lt;li&gt;More resilient to errors. If a microservice fails, the rest of the microservices can continue to work since they are independent.&lt;/li&gt;
  &lt;li&gt;Better testable and more modular. You can use different languages and technologies on each microservice, using the most suitable solution on case by case basis without committing to a single technology for the whole project. Each microservice can then be tested with separate approaches and methodologies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Microservices have gradually become the standard for building systems that make use of practices such as Continuous Deployment.&lt;/p&gt;

&lt;h3 id=&quot;infrastructure-as-code&quot;&gt;Infrastructure as Code&lt;/h3&gt;
&lt;p&gt;It consists in managing the cloud infrastructure through software development methodologies, such as version control and continuous integration. The cloud can be setup via API, allowing developers and administrators to interact with the infrastructure in a programmatic way and on a very large scale rather than through manual setting and configuration of resources. Since everything can be managed by code, the infrastructure and servers can be deployed as quickly as possible via standardized templates, updated with patches or duplicated iteratively. There are several tools to implement this: Chef, Puppet, Terraform, Ansible, etc. The advantages are remarkable, in addition to those above we have zero downtime (if applied well) and auto-scaling of resources.&lt;/p&gt;

&lt;h3 id=&quot;monitoring-and-logging&quot;&gt;Monitoring and Logging&lt;/h3&gt;
&lt;p&gt;Keeping parameters and logs under check is useful to find out how application and infrastructure performance affects the end-user experience. Data and logs generated by applications and infrastructure are acquired; after categorizing and analyzing them, the possible causes of problems or unforeseen changes can be thoroughly examined. Creating alarms or analyzing data in real time also help in proactively monitoring services. One of the tools to implement this practice is Nagios.&lt;/p&gt;

&lt;h3 id=&quot;containerization--orchestration&quot;&gt;Containerization &amp;amp; Orchestration&lt;/h3&gt;
&lt;p&gt;These are two techniques used to manage software. Containererization, through tools such as Docker, provides a logical packaging mechanism that allows applications to be abstracted from the underlying environment they run on. Decoupling things like this allows for easy and consistent deployments of container-based applications, whether the target environment is a private data center, the public cloud or a developer’s computer. Compared to virtual machines, containers have several advantages such as reduced disk size and low overhead. Orchestration refers to practices such as automatic deployment, scaling, and management of containerized applications and can be achieved using tools such as Kubernetes.&lt;/p&gt;

&lt;h2 id=&quot;what-are-the-advantages-of-the-devops-model&quot;&gt;What are the advantages of the DevOps model?&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Speed. Applications developed using a microservice architecture with the addition of continuous integration allows you to release updates more frequently and to better control services.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Rapid delivery. Practices such as continuous integration (CI) and continuous delivery (CD) lead to faster releases and bug fixes.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Reliability. Thanks to CI/CD and monitoring/logging rest assured that releases will meet quality standards without sacrificing the end-user experience.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Scalability. Infrastructure as code allows you to manage development, testing and production environments in an iterative and more efficient way - on any scale.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;An evolution of software architecture, development and delivery that is not the same as it was twenty years ago.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;a-simple-pipeline-example&quot;&gt;A simple pipeline example&lt;/h2&gt;

&lt;p&gt;Now that we know about DevOps and its advantages, let’s briefly look at a simple pipeline example. There is no correct or definitive structure: you can modify the pipeline to better adapt it to certain situations or as you see fit. This is just an example.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2020-07-16/pipeline.png&quot; alt=&quot;DevOps pipeline&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;In the first step you version the code, with a tool like Git. Developers then develop and commit the code to a repository.&lt;/p&gt;

&lt;p&gt;The second step is not always necessary, it depends on the language and technology used. It consists of building the project, which often means having a working version of the project locally.&lt;/p&gt;

&lt;p&gt;The third step is running unit tests on the project. This can also be automated - useful to prepare for the next step.&lt;/p&gt;

&lt;p&gt;The fourth step is deployment to development/staging environments. At this point you can view the code running on an environment that can be shared with the client. This point can also be automated.&lt;/p&gt;

&lt;p&gt;Subsequently, other tests can be run on the development environment. Other people responsible for testing the project can come into play by running their test tasks, even manually, on a development environment that should be complete and working. Depending on requirements, this step can also be automated.&lt;/p&gt;

&lt;p&gt;If all goes well it’s time to go live! Deployment in production happens. Once this is done there is the operational/monitoring phase. Things such as applications, state of the infrastructure, errors, logs and more are kept under control.&lt;/p&gt;

&lt;h2 id=&quot;final-thoughts&quot;&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;Hopefully by now you have an idea of what DevOps is, at least on paper. DevOps, as I have repeatedly stated, is first and foremost a cultural change that impacts all the figures involved in software development. In fact, it requires a different, more modern approach to software development and distribution; in return, if implemented well, it provides us with several advantages such as the reduction of different problems and timescales. It also prepares us to better face challenges that previously would have been more problematic to manage.&lt;/p&gt;

&lt;p&gt;Should you find any mistake, technical or grammatical, please don’t hesitate to let me know!&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">It’s 2020 and although DevOps is a practice that’s very commonly adopted today, I feel that a not too overly technical explanation of the subject might be beneficial to those individuals, or companies, that are not using it yet but find themselves in a position where it makes sense to use such model. Moreover, if you’re completely or partially new to this subject, this is a great place to start! So what is this DevOps thing? DevOps can be defined as a combination between cultural philosophies, practices and tools. The cultural philosophy aspect is about changing how you develop and deploy software. In the DevOps model people who take care of software development and people who take care of operations (by managing, monitoring and operating infrastructure) work very closely together; sometimes the two roles are combined together. The DevOps term originates exactly from here: Developer Operations. Next, there are practices. They help you to understand how the DevOps model works, in practice. Don’t worry if you have no idea what these are, more on them in just a moment: Continuous Integration Continuous Delivery Microservices Infrastructure as Code Monitoring and Logging Containerization &amp;amp; Orchestration Finally, tools. These, along with the aforementioned practices, will help you to concretely adopt the DevOps model. Some of the relevant tools are: Git Jenkins Docker Kubernetes Automated testing libraries/frameworks The DevOps model will improve every aspect of the application lifecycle, from development and testing to deployments and production rollouts. The team relies on automation to speed up manual processes and, thanks to the appropriate tools, applications can grow in a rapid and flexible way. DevOps is first of all a mentality shift, where you are required to change the way you approach software development and release. While it may be good to have one person to be the leader of this change, you should make sure that your whole team/company is ready to take the leap. Let’s dive deeper into the practices DevOps tools Continuous Integration It is composed by two main elements: a cultural one and a technical/automated one. The cultural part consists in learning how to make frequent integrations. In other words, developers should not wait an excessive amount of time before merging their commits into the rest of the project. The technical/automated part is represented by the tools that helps automating these frequent integrations. Jenkins, for example, is a popular open source tool widely used for this. Continuous Integration solves the problem of heavy integrations and it helps reducing time spent solving merge conflicts. Statistically, the longer you wait to merge the more chances you will incur in a conflict. Merge often to avoid this! Continuous Delivery / Deployment It extends Continous Integration by automating deployments to staging and production environments. These deployments can have pre-requisites such as automated tests; they can even go beyond Unit Tests and require interface tests, load tests, integration tests, API reliability tests and so on. There is a difference between Continuous Delivery and Continuous Deployment. With C. Delivery you will automatically deploy on a staging environment and manual approval will be required if you want to deploy in production. With C. Deployment you go one step further and also automate production rollouts. You can use Jenkins for this or you can search for more specific tools that will hook into the Continuous Integration offered by Jenkins. This practice will help you reduce human errors and time required to complete the deployment process. Microservices It is a type of architecture used to build an application or a set of services. The application is based on a smaller set of services that communicates with each other through, for example, HTTP APIs. Each microservice has its own responsibility and the application is broken down into microservices according to the needs of the application domain. Frameworks or programming languages can be used to write microservices and distribute them, either individually or as a group of services. With this approach, our application will have the following benefits: More easily maintainable. You only touch the microservice you need. More resilient to errors. If a microservice fails, the rest of the microservices can continue to work since they are independent. Better testable and more modular. You can use different languages and technologies on each microservice, using the most suitable solution on case by case basis without committing to a single technology for the whole project. Each microservice can then be tested with separate approaches and methodologies. Microservices have gradually become the standard for building systems that make use of practices such as Continuous Deployment. Infrastructure as Code It consists in managing the cloud infrastructure through software development methodologies, such as version control and continuous integration. The cloud can be setup via API, allowing developers and administrators to interact with the infrastructure in a programmatic way and on a very large scale rather than through manual setting and configuration of resources. Since everything can be managed by code, the infrastructure and servers can be deployed as quickly as possible via standardized templates, updated with patches or duplicated iteratively. There are several tools to implement this: Chef, Puppet, Terraform, Ansible, etc. The advantages are remarkable, in addition to those above we have zero downtime (if applied well) and auto-scaling of resources. Monitoring and Logging Keeping parameters and logs under check is useful to find out how application and infrastructure performance affects the end-user experience. Data and logs generated by applications and infrastructure are acquired; after categorizing and analyzing them, the possible causes of problems or unforeseen changes can be thoroughly examined. Creating alarms or analyzing data in real time also help in proactively monitoring services. One of the tools to implement this practice is Nagios. Containerization &amp;amp; Orchestration These are two techniques used to manage software. Containererization, through tools such as Docker, provides a logical packaging mechanism that allows applications to be abstracted from the underlying environment they run on. Decoupling things like this allows for easy and consistent deployments of container-based applications, whether the target environment is a private data center, the public cloud or a developer’s computer. Compared to virtual machines, containers have several advantages such as reduced disk size and low overhead. Orchestration refers to practices such as automatic deployment, scaling, and management of containerized applications and can be achieved using tools such as Kubernetes. What are the advantages of the DevOps model? Speed. Applications developed using a microservice architecture with the addition of continuous integration allows you to release updates more frequently and to better control services. Rapid delivery. Practices such as continuous integration (CI) and continuous delivery (CD) lead to faster releases and bug fixes. Reliability. Thanks to CI/CD and monitoring/logging rest assured that releases will meet quality standards without sacrificing the end-user experience. Scalability. Infrastructure as code allows you to manage development, testing and production environments in an iterative and more efficient way - on any scale. An evolution of software architecture, development and delivery that is not the same as it was twenty years ago. A simple pipeline example Now that we know about DevOps and its advantages, let’s briefly look at a simple pipeline example. There is no correct or definitive structure: you can modify the pipeline to better adapt it to certain situations or as you see fit. This is just an example. In the first step you version the code, with a tool like Git. Developers then develop and commit the code to a repository. The second step is not always necessary, it depends on the language and technology used. It consists of building the project, which often means having a working version of the project locally. The third step is running unit tests on the project. This can also be automated - useful to prepare for the next step. The fourth step is deployment to development/staging environments. At this point you can view the code running on an environment that can be shared with the client. This point can also be automated. Subsequently, other tests can be run on the development environment. Other people responsible for testing the project can come into play by running their test tasks, even manually, on a development environment that should be complete and working. Depending on requirements, this step can also be automated. If all goes well it’s time to go live! Deployment in production happens. Once this is done there is the operational/monitoring phase. Things such as applications, state of the infrastructure, errors, logs and more are kept under control. Final Thoughts Hopefully by now you have an idea of what DevOps is, at least on paper. DevOps, as I have repeatedly stated, is first and foremost a cultural change that impacts all the figures involved in software development. In fact, it requires a different, more modern approach to software development and distribution; in return, if implemented well, it provides us with several advantages such as the reduction of different problems and timescales. It also prepares us to better face challenges that previously would have been more problematic to manage. Should you find any mistake, technical or grammatical, please don’t hesitate to let me know!</summary></entry><entry><title type="html">How to set up Jekyll with Docker and GitHub Pages</title><link href="https://garry.bhatt.al/how-to-set-up-Jekyll-with-Docker-and-GitHub-Pages" rel="alternate" type="text/html" title="How to set up Jekyll with Docker and GitHub Pages" /><published>2019-02-18T09:00:00-08:00</published><updated>2019-02-18T09:00:00-08:00</updated><id>https://garry.bhatt.al/how-to-set-up-jekyll-with-docker-and-github-pages</id><content type="html" xml:base="https://garry.bhatt.al/how-to-set-up-Jekyll-with-Docker-and-GitHub-Pages">&lt;p&gt;Want to set up an easy to maintain and highly scalable blog in little to no time? I personally found that running Jekyll in a Docker container for local development and letting GitHub Pages handle the production stack is the best set up for a developer’s blog. Let’s find out how to achieve this, starting from scratch.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2018-03-01/github_jekyll.png&quot; alt=&quot;Jekyll and GitHub logos&quot; /&gt;
  &lt;figcaption&gt;Jekyll and GitHub Pages: a powerful combination!&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;installation-and-configuration-of-docker-and-docker-compose&quot;&gt;Installation and configuration of Docker and Docker Compose&lt;/h2&gt;

&lt;p&gt;I will briefly cover how to install &lt;a href=&quot;https://www.docker.com/&quot;&gt;Docker&lt;/a&gt; and &lt;a href=&quot;https://docs.docker.com/compose&quot;&gt;Docker Compose&lt;/a&gt; since they are required for this set up. This tutorial will work with a fresh Ubuntu install, as long as it is the 64-bit version and sports a kernel version of 3.10 or higher. You can easily find how to do this on a different OS if you search around.&lt;/p&gt;

&lt;p&gt;We shall first add the GPG key for the official Docker repository:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then, add the Docker repo to your system’s APT sources:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Finally, update the package db and install Docker:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install -y docker-ce
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now let’s install Docker Compose and apply executable permissions to the binary:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Be careful to download the &lt;a href=&quot;https://github.com/docker/compose/releases&quot;&gt;latest version&lt;/a&gt; of Docker Composer by changing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.24.0&lt;/code&gt; part in the request URI above.&lt;/p&gt;

&lt;p&gt;You should now be ready to use Docker and Docker Compose. Let’s see what role they play in our set up.&lt;/p&gt;

&lt;h2 id=&quot;creating-the-container&quot;&gt;Creating the container&lt;/h2&gt;

&lt;p&gt;The easiest way to get started is probably to download an existing theme to a local folder. We will call this folder &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/site/&lt;/code&gt;, download a Jekyll theme (for example &lt;a href=&quot;https://github.com/johnotander/pixyll&quot;&gt;Pixyll&lt;/a&gt;) and store it there.&lt;/p&gt;

&lt;p&gt;Let’s now create the configuration file relative to our container and let’s use Docker Compose to easily create and run that container. Inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/site/&lt;/code&gt; create a file named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose.yml&lt;/code&gt; with the following content:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jekyll:
    image: jekyll/jekyll:pages
    command: jekyll serve --watch --incremental
    ports:
        - 4000:4000
    volumes:
        - .:/srv/jekyll
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The content of this file deserves further explanation. With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;image: jekyll/jekyll:pages&lt;/code&gt; we specify that we want to use the official Jekyll image for Docker, in its &lt;em&gt;pages&lt;/em&gt; flavor which is suited for GitHub Pages.&lt;/p&gt;

&lt;p&gt;With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;command: jekyll serve --watch --incremental&lt;/code&gt; we are executing the container. This will run Jekyll’s built in development server. It’s actually the same as if you would install Jekyll on your machine without a container and tried to make it serve a blog locally. The two additional flags will make sure that Jekyll automatically picks up your edits without having to build the whole site each time. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4000:4000&lt;/code&gt; is there to forward port 4000 of the container to your local port 4000.&lt;/p&gt;

&lt;p&gt;The last line will create a mapping between your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/site/&lt;/code&gt; directory and the directory where the image is configured to look for a Jekyll site, which is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/srv/jekyll&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Ok, as if that wasn’t easy enough, it gets even easier. Just run the following command inside &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/site/&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and watch your site go live at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://127.0.0.1:4000&lt;/code&gt;. Magic.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2018-03-01/docker.jpg&quot; alt=&quot;Docker logo&quot; /&gt;
  &lt;figcaption&gt;Docker is an amazing tool as it allows to create a working dev enironments in no time! Very useful for teams.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;pushing-the-site-live-with-github-pages&quot;&gt;Pushing the site live with GitHub Pages&lt;/h2&gt;

&lt;p&gt;It’s kinda amazing but things are getting even easier, if possible.&lt;/p&gt;

&lt;p&gt;Create a new GitHub repository named &lt;em&gt;username&lt;/em&gt;.github.io (replace &lt;em&gt;username&lt;/em&gt; with your GitHub username). Figure out a way to clone the new repository in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/site/&lt;/code&gt; while retaining all of your previous blog files.&lt;/p&gt;

&lt;p&gt;Now just commit and push the blog files to your new GitHub repo. Done, your site should be live at https://&lt;em&gt;username&lt;/em&gt;.github.io .&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;This is one way to quickly and efficiently set up a fully functional blog at zero cost; I personally find it very convenient! Let me know if you do too.&lt;/p&gt;

&lt;p&gt;Should you find any mistake, technical or grammatical, please don’t hesitate to let me know!&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">Want to set up an easy to maintain and highly scalable blog in little to no time? I personally found that running Jekyll in a Docker container for local development and letting GitHub Pages handle the production stack is the best set up for a developer’s blog. Let’s find out how to achieve this, starting from scratch.</summary></entry><entry><title type="html">Understanding UNIX/Linux File System Permissions (Part 2)</title><link href="https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-2" rel="alternate" type="text/html" title="Understanding UNIX/Linux File System Permissions (Part 2)" /><published>2017-12-21T15:00:00-08:00</published><updated>2017-12-21T15:00:00-08:00</updated><id>https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-part-2</id><content type="html" xml:base="https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-2">&lt;p&gt;In the first part of this couple of posts about UNIX permissions we saw how the system is structured under a users/groups model. We saw how each user belongs to at least one group and how users and groups are unequivocally identified by UIDs and GIDs respectively.&lt;/p&gt;

&lt;p&gt;In this part we will see the actual UNIX permission system. We will also explain the concept of ownership.&lt;/p&gt;

&lt;h2 id=&quot;ownership-and-permissions&quot;&gt;Ownership and Permissions&lt;/h2&gt;
&lt;p&gt;Each file in UNIX belongs to a user and to a group. So, for a generic user, we have three main scenarios:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;User is the owner of file&lt;/li&gt;
  &lt;li&gt;A group owns the file and user is part of that group&lt;/li&gt;
  &lt;li&gt;User does not own the file nor is in a group who owns the file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But what is Unix ownership, to be more precise? It’s actually very simple. The ownership system is used to assign different &lt;strong&gt;permission&lt;/strong&gt; sets to different users or groups of users.&lt;/p&gt;

&lt;p&gt;Now that we laid down the basics about users and groups, let’s get straight to the core of the question: permissions.&lt;/p&gt;

&lt;p&gt;First of all we need to know how we can actually view the permissions of a file. To do this we execute the following command inside of a directory:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ls -al
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This will print a &lt;strong&gt;list&lt;/strong&gt; of all files present in that directory, along with each file’s details. Among these details, as you may have guessed, we also have the file’s permissions.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2017-12-21/ls.png&quot; alt=&quot;Output of ls -al&quot; /&gt;
  &lt;figcaption&gt;The output of ls -al&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;As you can see, a lot of columns will be displayed. Most of them, like the file’s name, size, owner and group are self-explained in the picture above. What’s interesting here is the first column, the &lt;strong&gt;Mode&lt;/strong&gt; one.
Each UNIX file is assigned a mode, which contains permissions. Let’s take a closer look at how Mode values should be read.&lt;/p&gt;

&lt;p&gt;This the mode for the &lt;em&gt;asset&lt;/em&gt; folder in the picture above, properly spaced to allow us to read it better.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;d rwx rwx r-x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The first letter indicates whether the entry is a directory (&lt;strong&gt;d&lt;/strong&gt;), a symbolic link (&lt;strong&gt;l&lt;/strong&gt;) or a normal file (&lt;strong&gt;-&lt;/strong&gt;). The following three sets of triads are the actual file’s permission:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The first three characters after the one denoting the file’s type, &lt;strong&gt;rwx&lt;/strong&gt;, is the permission class called User and defines permissions for the owner of the file.&lt;/li&gt;
  &lt;li&gt;The second three characters after the one denoting the file’s type, again &lt;strong&gt;rwx&lt;/strong&gt;, is the permission class called Group and defines permissions for each user in that group.&lt;/li&gt;
  &lt;li&gt;The last three characters after the one denoting the file’s type, this time &lt;strong&gt;r-x&lt;/strong&gt;, is the permission class called World (or Other) and defines permissions for anyone else, such as the public.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;read-write-execute&quot;&gt;Read, Write, Execute&lt;/h2&gt;
&lt;p&gt;Ok but what are these &lt;strong&gt;rwx&lt;/strong&gt;? They stand for Read, Write and Execute. Let’s see each one of them in detail.&lt;/p&gt;

&lt;h3 id=&quot;read&quot;&gt;Read&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;In the case of a normal file, read means that the user is allowed to open the file and access its content.&lt;/li&gt;
  &lt;li&gt;In the case of a directory, read means that the user is allowed to see what’s inside of that directory.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;write&quot;&gt;Write&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;In the case of a normal file, write means that the user is allowed to modify and delete the file’s content.&lt;/li&gt;
  &lt;li&gt;In the case of a directory, write means that the user is allowed to create new files inside of the directory and delete it. Always be careful with write, since it’s “stronger” than write!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;execute&quot;&gt;Execute&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;In the case of a normal file, execute means that the user is allowed to run the file as an executable, provided the user also has read permission.&lt;/li&gt;
  &lt;li&gt;In the case of a directory, execute means that the user is allowed to traverse the directory, in other words the user can “cd” (the UNIX command to change directory) into it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;some-examples&quot;&gt;Some examples&lt;/h2&gt;
&lt;p&gt;Let’s make some example to make the permission system more clear.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-rw-rw-rw-
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the case above the file is writable by the user, the group and the world too. Everyone can write the file but no one can execute it.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-rw-------
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the case above the file is writable only by the user; nor the group and the world can read or write the file. Like the previous case, no one can execute.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-rwxr-xr-x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the case above the file is executable by everyone; the user can also modify or delete it.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;drwxr-x---
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In the case above the directory is accessible by everyone but the world. The owner can also delete or create new file inside of it.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Now you should have at least a basic understanding about how the UNIX file system permissions work! If you have any question or should you find typos or mistakes in this page please let me know through the comments.&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">In the first part of this couple of posts about UNIX permissions we saw how the system is structured under a users/groups model. We saw how each user belongs to at least one group and how users and groups are unequivocally identified by UIDs and GIDs respectively.</summary></entry><entry><title type="html">Understanding UNIX/Linux File System Permissions (Part 1)</title><link href="https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-1" rel="alternate" type="text/html" title="Understanding UNIX/Linux File System Permissions (Part 1)" /><published>2016-09-30T16:00:00-07:00</published><updated>2016-09-30T16:00:00-07:00</updated><id>https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-part-1</id><content type="html" xml:base="https://garry.bhatt.al/understanding-unix-linux-file-system-permissions-1">&lt;p&gt;This series of articles is mainly for UNIX/Linux newbies, the topic will be covered in a way that is both simple and easy to understand. One of the things that’s often not clear to users approaching the UNIX world is how the &lt;strong&gt;permission&lt;/strong&gt; system for file and directories works. In fact, &lt;em&gt;UNIX is a multi-user system&lt;/em&gt;, which means there are multiple users that can connect to a UNIX system at the same time and do operations with it. This is also true for other UNIX-like system like Linux.&lt;/p&gt;

&lt;p&gt;Examples of this? Just think of a machine, running a UNIX system, connected to a network (such as an intranet or the Internet). Multiple users can concurrently establish connections with this machine, via telnet or SSH, and execute programs, get outputs and so on.&lt;/p&gt;

&lt;p&gt;So a couple of reasons this permissions system exist is to avoid one user accessing files that are protected by another user and not to allow single users to crash the whole system.&lt;/p&gt;

&lt;h2 id=&quot;not-every-user-is-human&quot;&gt;Not every user is human&lt;/h2&gt;
&lt;p&gt;In UNIX not all users are humans. I may have a user &lt;em&gt;garry&lt;/em&gt; in a system, denoting myself, but there may also be a user called &lt;em&gt;www-data&lt;/em&gt; which denotes the privileges necessary for a web-server process to run. For the system, users represent an abstraction which &lt;strong&gt;defines what they may or may not do&lt;/strong&gt; with any given entity in the file system.&lt;/p&gt;

&lt;p&gt;Each user is unequivocally identified by a &lt;em&gt;UID&lt;/em&gt; (User ID), which is a numeric value that allows the system to discriminate between all present users. Login usernames such as &lt;em&gt;garry&lt;/em&gt; and &lt;em&gt;www-data&lt;/em&gt; are just aliases for human operators, meant to make us more comfortable. For example, in my system, user &lt;em&gt;garry&lt;/em&gt; may have the UID 1021. The system does not have problems associating the UID number with me, but the same number gives no valuable information to other human users operating the system. Instead, if another human user sees my username (garry) instead of my UID (1021), it is much easier for them to recognize me.&lt;/p&gt;

&lt;h2 id=&quot;users-belong-to-groups&quot;&gt;Users belong to groups&lt;/h2&gt;
&lt;p&gt;In UNIX every user belongs to at least one group. This means there can’t be UNIX users not associated to a group. But what are these UNIX groups, precisely?&lt;/p&gt;

&lt;p&gt;The purpose of groups is basically to assign the same privileges over a determined resource to multiple users, in a quick and efficient way. To make an example, you may need this is in a situation where different users are working on the same project files. 
Groups, like users, have also their numerical identifiers. They are called &lt;strong&gt;GID&lt;/strong&gt; (Group ID).&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2016-09-30/perm-1.png&quot; alt=&quot;Graphical permission representation&quot; /&gt;
  &lt;figcaption&gt;A preview from the next article of this series: this is how permissions are generally represented for a given file.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;how-to-find-out-your-uid-and-gid&quot;&gt;How to find out your UID and GID&lt;/h2&gt;
&lt;p&gt;If you are on a UNIX or UNIX-like system you can find out UIDs with the following command:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;id -u username  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Remember to replace &lt;em&gt;username&lt;/em&gt; with the desired user. For example, if I want to get the UID of the user &lt;em&gt;www-data&lt;/em&gt; in my system, I will have to execute the following:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;id -u www-data
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The result will be printed in the terminal as a numerical value, which is the UID for the specified user.&lt;/p&gt;

&lt;p&gt;You can also get the GID of a user by typing the following at the UNIX prompt:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;id -g username  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Don’t forget to replace &lt;em&gt;username&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If you want to find out all groups a user belongs to, you will need to enter the following:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;id -G username  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Note the capital G which is different from the lower-case g in previous command.&lt;/p&gt;

&lt;p&gt;To recap, in this post we saw how a UNIX system is structured, under a user/group point of view. Users in UNIX are quite different than users in Windows; in addition, Windows doesn’t have the concept of group as seen in UNIX. These concepts are mandatory to explain what we will see in the next part, the UNIX permission system.&lt;/p&gt;

&lt;p&gt;Should you find any mistake, technical or grammatical, please don’t hesitate to let me know!&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">This series of articles is mainly for UNIX/Linux newbies, the topic will be covered in a way that is both simple and easy to understand. One of the things that’s often not clear to users approaching the UNIX world is how the permission system for file and directories works. In fact, UNIX is a multi-user system, which means there are multiple users that can connect to a UNIX system at the same time and do operations with it. This is also true for other UNIX-like system like Linux.</summary></entry><entry><title type="html">How to keep Ghost running using pm2</title><link href="https://garry.bhatt.al/how-to-keep-ghost-running-using-pm2" rel="alternate" type="text/html" title="How to keep Ghost running using pm2" /><published>2016-03-10T15:00:00-08:00</published><updated>2016-03-10T15:00:00-08:00</updated><id>https://garry.bhatt.al/how-to-keep-ghost-running-using-pm2</id><content type="html" xml:base="https://garry.bhatt.al/how-to-keep-ghost-running-using-pm2">&lt;p&gt;So you just set up your brand new blog with &lt;a href=&quot;https://ghost.org/&quot;&gt;Ghost&lt;/a&gt;, the node.js-based blogging platform? You will most likely encounter the problem of keeping alive (and/or restarting) the node.js process on which Ghost is running.&lt;/p&gt;

&lt;p&gt;In fact, if you want to launch Ghost on production values, you would normally use npm with the following command:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;npm start --production
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;whats-the-problem&quot;&gt;What’s the Problem?&lt;/h2&gt;

&lt;p&gt;You’ll experience the problem once you close the terminal session where you issued the previous command. Closing the terminal also kills Ghost (i.e. &lt;strong&gt;your blog isn’t available anymore&lt;/strong&gt;) and that’s not what we want! 
You will also notice that once you restart your machine, Ghost will not automatically start on boot. You will have to start it manually &lt;strong&gt;with each physical machine restart&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are multiple ways to solve the aforementioned issues, we’ll examine one method in particular to achieve the solution. Once we’re done you’ll be able to close the terminal and have Ghost running in the background without problems. 
This will also help you to have Ghost automatically start when your machine is subject to a system reboot.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2016-03-10/ghostlogo.png&quot; alt=&quot;Ghost Logo&quot; /&gt;
  &lt;figcaption&gt;I am now using Jekyll but Ghost is a wonderful blogging platform!&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;onto-the-solution&quot;&gt;Onto the solution&lt;/h2&gt;

&lt;p&gt;In order to achieve our solution, we will use two &lt;a href=&quot;https://www.npmjs.com/&quot;&gt;npm&lt;/a&gt; modules called &lt;a href=&quot;https://www.npmjs.com/package/forever&quot;&gt;forever&lt;/a&gt; and &lt;a href=&quot;https://github.com/Unitech/pm2&quot;&gt;pm2&lt;/a&gt;. They are both easy and relatively straight-forward to install and use.&lt;/p&gt;

&lt;p&gt;First of all, we navigate to the directory where Ghost is installed.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd /path-to-your-Ghost-installation-directory
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Then we can proceed with installing and setting up pm2 itself. Execute these commands sequentially, preferably as a non-root user.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo npm install -g pm2
cd /path/to/ghost/folder
sudo npm install -g pm2
echo &quot;export NODE_ENV=production&quot; &amp;gt;&amp;gt; ~/.profile
source ~/.profile
pm2 kill
pm2 start index.js --name ghost
pm2 dump
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now there’s only one last command left to execute. This depends on the OS you’re currently on.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pm2 startup your-os
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;There are good chances that you’re on Ubuntu, Debian or CentOS; if that’s the case you just have to replace “your-os” with the name of your OS.
For example, if you’re on CentOS, you’ll have to execute the following command:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pm2 startup centos
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If you’re on Ubuntu:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pm2 startup ubuntu
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;And so on.&lt;/p&gt;

&lt;h2 id=&quot;some-useful-commands&quot;&gt;Some useful commands&lt;/h2&gt;
&lt;p&gt;Now that we have everything correctly installed and set up let’s see how to use this module. Following there are a few useful commands to get data and stats with pm2.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Stats
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  pm2 status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;Once executed, this command will show you a few useful statistics on your Ghost instance such the status, memory footprint and the process ID.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Stopping and starting&lt;/p&gt;

    &lt;p&gt;If you want to stop your Ghost instance you should first know what’s the “App Name” of the said instance. This can be found under the “App Name” column when you execute the status command. If you followed this guide, your “App Name” should be “ghost”. You can stop your Ghost blog by issuing the following command:&lt;/p&gt;
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  pm2 stop ghost
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;If you now wish to start Ghost, type and execute the following:&lt;/p&gt;
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  pm2 start index.js --name ghost
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;When using the start command you can assign to the newly created instance whichever name you prefer (with the –name parameter as in the example above); to subsequently stop Ghost you will have to use this same name. Notice that we issued this command in the beginning, along with the pm2 setup.
  Otherwise you can simply use:&lt;/p&gt;
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  pm2 restart ghost
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;This will restart your Ghost instance with the same previous parameters.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Logs
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  pm2 logs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;You can use this command if you want to get live statistics and logs from your Ghost instance.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">So you just set up your brand new blog with Ghost, the node.js-based blogging platform? You will most likely encounter the problem of keeping alive (and/or restarting) the node.js process on which Ghost is running.</summary></entry><entry><title type="html">Echo of Today: a Twitter Bot reminding us what happened today, years ago</title><link href="https://garry.bhatt.al/echo-of-today-twitter-bot" rel="alternate" type="text/html" title="Echo of Today: a Twitter Bot reminding us what happened today, years ago" /><published>2015-09-18T16:00:00-07:00</published><updated>2015-09-18T16:00:00-07:00</updated><id>https://garry.bhatt.al/echo-of-today-a-twitter-bot-reminding-us-what-happened-today-years-ago</id><content type="html" xml:base="https://garry.bhatt.al/echo-of-today-twitter-bot">&lt;p&gt;Twitter bots are everywhere. An article from &lt;a href=&quot;https://qz.com/248063/twitter-admits-that-as-many-as-23-million-of-its-active-users-are-actually-bots/&quot;&gt;Quartz&lt;/a&gt; dated last year states that &lt;em&gt;up to approximately 8.5% of the accounts considered active are automatically updated&lt;/em&gt;. That means 23 million of Twitter’s 271 million monthly active users are bots.&lt;/p&gt;

&lt;p&gt;Yes, bots on Twitter are extremely popular so I decided to make one myself. I called it &lt;a href=&quot;https://twitter.com/EchoOfToday&quot;&gt;Echo Of Today&lt;/a&gt;. 
Let’s see how I did it and what was the result!&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2015-09-18/mecha-twitter.jpg&quot; alt=&quot;funny Twitter Logo&quot; /&gt;
  &lt;figcaption&gt;Twitter is becoming increasingly automated&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;what-should-my-bot-do&quot;&gt;What should my bot do?&lt;/h2&gt;

&lt;p&gt;When I first started to think about my upcoming Twitter bot, I had to come up with &lt;strong&gt;something interesting&lt;/strong&gt; yet not already done to death. With 20 million bots around, you may guess that a lot of the most simple and obvious concepts are already implemented. I wanted to do something at least partially &lt;strong&gt;original&lt;/strong&gt;, not your usual bot that just follows random people.&lt;/p&gt;

&lt;p&gt;This meant that my bot would have to sport a certain level of complexity - let’s say I didn’t want to make something too simple but I also wanted to avoid losing myself in something utterly complex.&lt;/p&gt;

&lt;p&gt;Then I had the idea: make a bot that tweets news articles published exactly one year ago, two years ago, three years ago (and so on, until an arbitrary number &lt;em&gt;n&lt;/em&gt; of previous years to work on). I’ll explain better this idea with an example. If today is the 21st September, the bot would look up news published on the 21st September of one year ago and tweet them. It will also find and tweet news published on the 21st September of two years ago, of three years ago and so on (the number of years it goes backwards is configurable). In other words, the bot would remind us what was happening exactly one and two, and three and so on years ago.&lt;/p&gt;

&lt;p&gt;Sounds like a nice idea right? But how to implement it?&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2015-09-18/news.jpg&quot; alt=&quot;newspapers&quot; /&gt;
  &lt;figcaption&gt;Do you remember what happened today, two years ago?&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;getting-the-pieces-together&quot;&gt;Getting the pieces together&lt;/h2&gt;

&lt;p&gt;First of all, I had to decide &lt;strong&gt;which language&lt;/strong&gt; I would use to code the bot. I chose to go with PHP, only because I knew it fairly well. But it can be any language you like, for example, I know many Twitter bots are written in Python or JavaScript. Just be sure that the language you choose can serve your purpose right.&lt;/p&gt;

&lt;p&gt;After that, I had to put together the basics: create a new Twitter account for the bot, set up a new app on the newly created account, get all the API keys I needed and start writing the code necessary to create &lt;strong&gt;basic&lt;/strong&gt; features for the bot, such as tweeting. For this purpose, I found Abraham Williams library &lt;a href=&quot;https://github.com/abraham/twitteroauth&quot;&gt;twitteroauth&lt;/a&gt; very useful.&lt;/p&gt;

&lt;p&gt;Next I was in front of the biggest challenge I faced when coding this bot: &lt;strong&gt;how the get the information&lt;/strong&gt; I needed (old news articles, in this case). After a bit of brainstorm and research, I found out that the New York Times offers awesome APIs through their &lt;a href=&quot;http://developer.nytimes.com/&quot;&gt;Times Developer Network&lt;/a&gt;. After studying their APIs, I managed to get the news I needed as a nicely formatted json response, perfect for my needs. This required a bit of coding (not much, really) but what I needed was there in the end.&lt;/p&gt;

&lt;p&gt;Next there was the &lt;strong&gt;140 characters challenge&lt;/strong&gt;. I decided to structure my tweets as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;#nYearsAgoToday Article Headline http://article.uri #EchoOfToday&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first hashtag indicates how old the news is, in years (6 years old is the oldest I wanted to go back). Next we have the article’s headline, the article’s URI and the last hashtag is simply the name of the bot.&lt;/p&gt;

&lt;p&gt;As you know, each Tweet can be long at most 140 chars and since I wanted to stick in a couple of lengthy hashtags too, not many characters were left for the headline and the URI. Headlines tend to be short enough, though after doing a bit of math I coded an &lt;strong&gt;upper limit&lt;/strong&gt; on how long can I allow a headline to be for a news article to be tweeted. The biggest problem was actually the URI, which can get quite long. The obvious solution was to &lt;strong&gt;shorten it&lt;/strong&gt;, which is what I did. I got my &lt;a href=&quot;https://goo.gl/&quot;&gt;goo.gl&lt;/a&gt; API key and with the help of &lt;a href=&quot;https://github.com/sebi/googl-php&quot;&gt;googl-php&lt;/a&gt;, a simple PHP class that facilitates the use of goo.gl APIs, I got the job done: now all URIs were much shorter and of the same length.&lt;/p&gt;

&lt;h2 id=&quot;a-final-touch-and-the-results&quot;&gt;A final touch and the results&lt;/h2&gt;

&lt;p&gt;Now that the bot was done I had to decide how much it I wanted it to tweet. I decided to make it tweet &lt;strong&gt;12 times a day&lt;/strong&gt;, hourly, from around 11:30 CEST to around 22:30 CEST. I chose this time frame since it’s good for Europeans but also fills part of the day for people in the US.&lt;/p&gt;

&lt;p&gt;I then divided the tweets into &lt;strong&gt;groups of twos&lt;/strong&gt;: the first two tweets would show news from 6 years ago, the following two from 5 years ago and so on, until the last two tweets, which contain news from exactly one year ago. 
To achieve this, in addition to standard PHP coding, I used &lt;a href=&quot;https://en.wikipedia.org/wiki/Cron&quot;&gt;cron&lt;/a&gt; jobs on my server. This allowed me to automatically call the bot 12 times a day, just when I need it to tweet.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2015-09-18/eotTwitter.png&quot; alt=&quot;twitter profile screenshot&quot; /&gt;
  &lt;figcaption&gt;The Twitter page where the bot is working 12 hours shift - be sure to follow his hard work!&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;The outcome was nice. It took me about a day to finish everything, but I’m sure a seasoned programmer can achieve this in much less time. If there’s enough interest in this I may open source it in the future, but just to give you an idea the bot consists in just about &lt;strong&gt;200 lines&lt;/strong&gt; of code. Very simple.&lt;/p&gt;

&lt;p&gt;As always, good APIs make work much easier, no surprises here! Actually, there was a surprise… 
And it was each time I opened &lt;a href=&quot;https://twitter.com/EchoOfToday&quot;&gt;Echo Of Today&lt;/a&gt;! There’s something joyful, sometimes sad, in reading and remembering what was happening today, years ago.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Thank you for reading! It was very fun to code this bot, I hope you found interesting what’s written here.&lt;/p&gt;

&lt;p&gt;If you have any question about this, please do ask in the comments, I’m happy to answer and help. 
Should you find any mistake, technical or grammatical, please don’t hesitate to let me know!&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">Twitter bots are everywhere. An article from Quartz dated last year states that up to approximately 8.5% of the accounts considered active are automatically updated. That means 23 million of Twitter’s 271 million monthly active users are bots.</summary></entry><entry><title type="html">Difference between URL, URI and URN</title><link href="https://garry.bhatt.al/difference-between-url-uri-and-urn" rel="alternate" type="text/html" title="Difference between URL, URI and URN" /><published>2015-08-25T16:00:00-07:00</published><updated>2015-08-25T16:00:00-07:00</updated><id>https://garry.bhatt.al/difference-between-url-uri-and-urn</id><content type="html" xml:base="https://garry.bhatt.al/difference-between-url-uri-and-urn">&lt;p&gt;This is a classic tech debate, and many people will sooner or later ask themselves what’s the difference between URLs, URIs and most possibly even URNs. As of today one can simply refer to URNs and URLs as URIs, but it may be very interesting and useful to know the difference between these three terms since technically a URI can still be further classified as URL, URN or both. If you happen to find these terms somewhere, you should at least know what they mean.&lt;/p&gt;

&lt;p&gt;If regular people don’t know the technical difference between these three acronyms and what they represent it shouldn’t be an issue for them, in my opinion. But if you’re a Software Engineer or, more generally, if you work in the IT field then it might be well worth to have this knowledge in your bag.&lt;/p&gt;

&lt;p&gt;This post is intended to be a clear explanation of the difference between URLs, URIs and URNs and will help you to quickly understand what you need to know. Are you confused about this topic? Let’s begin!&lt;/p&gt;

&lt;h2 id=&quot;origins&quot;&gt;Origins&lt;/h2&gt;

&lt;p&gt;These three acronyms are specified by Tim Berners-Lee as an Internet standards track protocol in the document called &lt;a href=&quot;https://tools.ietf.org/html/rfc3986&quot;&gt;RFC 3986: Uniform Resource Identifier (URI): Generic Syntax&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Citing the document:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A Uniform Resource Identifier (URI) provides a simple and extensible means for identifying a resource. This specification of URI syntax and semantics is derived from concepts introduced by the World Wide Web global information initiative, whose use of these identifiers dates from 1990 and is described in “Universal Resource Identifiers in WWW”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that the Uniform Resource Identifier was conceptualized back in the 1990s with the purpose of distinguishing between &lt;strong&gt;who&lt;/strong&gt; and &lt;strong&gt;where&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s get more technical on this.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2015-08-25/tim.jpg&quot; alt=&quot;Tim Berners-Lee&quot; /&gt;
  &lt;figcaption&gt;Tim Berners-Lee, the man who invented the World Wide Web and actual director of the W3C. Photo by Paul Clarke - Licensed under CC BY-SA 4.0.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&quot;the-difference&quot;&gt;The Difference&lt;/h2&gt;

&lt;p&gt;Let’s start by making one thing clear. &lt;strong&gt;URL and URN are both subsets of URI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In other words, URL and URN are always a URI, but a URI is not always a URL or a URN. To better understand this concept look at the image below.&lt;/p&gt;

&lt;figure&gt;
  &lt;img src=&quot;https://garry.bhatt.al/assets/images/2015-08-25/uriurlurn.png&quot; alt=&quot;URI, URN and URL as sets&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;A great example to understand the difference between URN and URL is the following (taken from &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;Wikipedia&lt;/a&gt;): in the case of a person, we can take in consideration his name and his address. 
The URL is similar to the latter one, the address; it tells you a &lt;strong&gt;method&lt;/strong&gt; to find that object (the person by its street address, in this example). Keep in mind that, by the definition we gave above, this also a URI.&lt;/p&gt;

&lt;p&gt;Instead, we can see the name of a person as a URN; the &lt;strong&gt;URN is therefore used to unequivocally identify a generic object&lt;/strong&gt;. To be more precise, in the case of a person’s name this is not entirely true since there may be another person with the same name (and surname), so a more appropriate example may be the ISBN code of a book or a product’s serial number inside of a system; while this doesn’t tell you how or where to find that object, you indeed have enough information to retrieve it by yourself. Formally, URNs also have their syntax. From &lt;a href=&quot;https://tools.ietf.org:80/html/rfc2141&quot;&gt;this document&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;All URNs have the following syntax (phrases enclosed in quotes are REQUIRED):&lt;/p&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt; URN &amp;gt; ::= &quot;urn:&quot; &amp;lt; NID &amp;gt; &quot;:&quot; &amp;lt; NSS &amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
  &lt;p&gt;where NID is the Namespace Identifier, and NSS is the Namespace Specific String.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;one-example-to-understand-them-all&quot;&gt;One example to understand them all&lt;/h2&gt;

&lt;p&gt;Let’s start by looking at how the concepts above apply to what matters to us: the Internet. 
The following quotes from &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;Wikipedia&lt;/a&gt; give us a bit more technical explanation in comparison to the generic person-address example we used above.&lt;/p&gt;

&lt;p&gt;For URL:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;A URL is a URI that, in addition to identifying a web resource, specifies the means of acting upon or obtaining the representation, specifying both its primary access mechanism and network location.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For URN:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A URN is a URI that identifies a resource by name in a particular namespace. A URN can be used to talk about a resource without implying its location or how to access it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, if you look around the web you will find a lot of examples and these can sometimes create more confusion than anything else. I will present you only &lt;strong&gt;one&lt;/strong&gt; example, which is very simple and clearly shows the difference between URI, URL and URN in contest of the Internet.&lt;/p&gt;

&lt;p&gt;Let’s consider the following fictitious example. This will be our &lt;strong&gt;&lt;em&gt;URI&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;https://garry.bhatt.al/posts/hello.html#intro
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s start by saying that&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;https://
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;is the &lt;strong&gt;method&lt;/strong&gt; that defines how to access that resource. Instead,&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;garry.bhatt.al/posts/hello.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;is the &lt;strong&gt;location&lt;/strong&gt; where the resource resides, while, in this example,&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#intro
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;is the resource.&lt;/p&gt;

&lt;p&gt;So we can say that the &lt;strong&gt;URL&lt;/strong&gt;, a subset of the URI that tells us how to access a network location, is the following part of our complete example:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;https://garry.bhatt.al/posts/hello.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The URN, defined as the URI subset that includes a name (within a given space) but does not provide a method to access it, is:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;garry.bhatt.al/posts/hello.html#intro
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s it! Now you should be able to tell the difference between URL and URN.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Should you ever forget the content of this article, you have to options. One is to get back here and read again about the differences. But URIs can be classified as URLs, URNs or both, right? So the other option is to always use the term &lt;strong&gt;URI&lt;/strong&gt;. This way, you will never be wrong.&lt;/p&gt;

&lt;p&gt;Should you find any mistakes, technical or grammatical, please don’t hesitate to let me know!&lt;/p&gt;</content><author><name>Garry Bhattal</name><email>garry@bhatt.al</email></author><summary type="html">This is a classic tech debate, and many people will sooner or later ask themselves what’s the difference between URLs, URIs and most possibly even URNs. As of today one can simply refer to URNs and URLs as URIs, but it may be very interesting and useful to know the difference between these three terms since technically a URI can still be further classified as URL, URN or both. If you happen to find these terms somewhere, you should at least know what they mean.</summary></entry></feed>