things in mind and a bunch of tech rants

Author: EA Faisal

Love it or hate it, systemd is here to stay. It seems more and more Linux distributions are putting systemd as their default init system. Although initially systemd was meant to replace the existing init system, but systemd dev decided to add features beyond a typical init system. One of it is task/job scheduler which traditionally handled from cron system.

While working on the online quiz system, I came to a need to run a script every 10 minutes. Of course I can easily add an entry to the cron but I thought this might be a good opportunity to try scheduling this task with systemd. So here’s how you can use systemd instead of cron system to run a job.

First, I created a service file (a file with .service extension). This is actually to define the script that I want to run. In my example the “Type” under [Service] directive is set to “simple” since the script I wanted to run was simply a shell script. The “ExecStart” option specifies the command to be executed. For other options, you may refer to the official documentation.

There is nothing special with the service file. It looks like a typical service file, only much simpler.

In systemd, there is a scheduling facility called timer. So next, I created a timer file (a file with .timer extension) with the following entries:

[Unit]
Description=Description for my timer directive
[Timer]
# Runs every 10 minutes
OnCalendar=*-*-* *:00,10,20,30,40,50:00
# Run even we site the time set
Persistent=true
Unit=&lt;the service file I created above&gt;
[Install]
WantedBy=multi-user.target

The “OnCalendar” option does look similar to cron but systemd support various other formats. The “Persistent” option means systemd will keep track when was the last time the event triggered and is useful in case the timer misses any run and systemd will ensure that my script will be executed at least once during the time the timer is inactive (for example during downtime). For other timer options you may refer to the documentation.

After having those 2 files, I just copied to /etc/systemd/system and execute the systemctl command to run the timer and enable it to persist after reboot

Recently, we were tasked to setup the infrastructure for an online quiz system on Amazon AWS. The brief for the assignment were:

High availability

Good performance

Easy to scale

We decided to implement a Virtual Private Cloud (VPC), spanning across two availability zones denoted as A (10.0.0.0/24) and B (10.0.1.0/24). The general outline of the infrastructure design is illustrated below:

Interacting with the outside world was done by Elastic Load Balancer (ELB) which helped to load balance the traffic not only between the availability zones but also between various instances within a zone. ELB will ensure high availability (HA) simply registering EC2 instances to the list of managed instances by ELB. Just like HA, scaling horizontally is easily achieved by creating a new instance and adding it to the list of managed instances by ELB. Also worth noting that control of traffics and access was done via a security group.