CRON Expressions

Last week I blogged about Azure Timer functions. These functions use CRON Expressions to set the timers.

I created this post of a list of some useful and handy CRON Expressions to help me as I try to automate things. This list will grow as I do more work with automating all the things.

A CRON Expression contains six fields.

{second} {minute} {hour} {day} {month} {day-of-week}

"0 */5 * * * *"  - Every 5 Minutes.

"0 0 * * * *" - At the top of every hour.

"0 30 8 * * *" - At 8:30 AM every day

"0 30 11 * * 1-5" - At 11:30 AM every week day. (Monday - Friday)

"0 0 9 * * 1" - At 9:00 AM every Monday.

"0 0 9,12,20 * * *" - At 9:00 AM, 12:00 PM, 20:00 PM

"0 0 9-18 * * *"  - Every hour between 9:00 AM and 18:00 PM

"0 0 9-18 * * 1-5" - Every hour between 9:00 AM and 18:00 PM every week day. (Monday - Friday)

Last week I blogged about Azure Timer functions. These functions use CRON Expressions to set the timers. I created this post of a list of some useful and handy CRON Expressions to help me as I try to automate things. This list will grow as I do more work with…

Read More

Azure Timer Functions

A quick getting started guide for Azure Timer functions. Timer triggers give us alot more options to automate things. With Azure timer functions we don't have to take care of the timer Azure handles that. We can focus on the code and what our function should do.

CRON Expressions

Azure timer functions use a CRON expression for the schedule. CRON Expressions can be a bit confusing at first but with some time they make sense and really easy to configure and use.

A CRON Expression contains six fields.

{second} {minute} {hour} {day} {month} {day-of-week}

Each field is separated by a space. The value of the fields can vary and this is where I think alot of people get lost.

Examples of values:

A specific value:

"0 */5 * * * *"  - Every 5 Minutes.

"0 0 */6 * * *" - Once every 6 hours.

Note the */X this sets the trigger to every X.

"0 0 * * * *" - At the top of every hour.

"0 30 8 * * *" - At 8:30 AM every day

"0 30 11 * * 1-5" - At 11:30 AM every week day. (Monday - Friday)

To specify months or days you can use numeric values, names, or abbreviations of names:

  • For days, the numeric values are 0 to 6 where 0 starts with Sunday.
  • Names are in English. For example: Monday, January.
  • Names are case-insensitive.
  • Names can be abbreviated. Three letters is the recommended abbreviation length.  For example: Mon, Jan.

The default time zone used with the CRON expressions is Coordinated Universal Time (UTC). Azure Timer functions can run in other time zones to change the time zone you need to add a setting in the Function.json

WEBSITE_TIME_ZONE - "Eastern Standard Time"

For a full list of Azure Time zones see here

Creating a function

In our Azure Portal Go to our functions. If you haven't checked them out, see my getting started guide. For all my Azure function posts.

Create a new Function, on the wizard select the "Timer Trigger" function.

Create an Azure Timer Function

We then need to name our new function.

We can also set a schedule by default. The Timer function I just created uses a every 5 minutes expression: "0 */5 * * * *"

Create our new Timer function. 

Now that we have created a function. The default code will write to the log every 5 minutes.

Default Function will write to it's log.

So that's it, we can now code up our function as we want and Automate all the things.

To change the timer on the function just head to the function.json file

{
  "bindings": [
    {
      "name": "myTimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */5 * * * *"
    }
  ],
  "disabled": false
}

You can see the schedule settings here. Changing it and resaving it will update the triggers timer.

A quick getting started guide for Azure Timer functions. Timer triggers give us alot more options to automate things. With Azure timer functions we don't have to take care of the timer Azure handles that. We can focus on the code and what our function should do.CRON ExpressionsAzure timer…

Read More

NGINX Commands (Ubuntu)

A short guide of commands I've found myself using on Ubuntu for NGINX, I'll update this post as I find more.

Installing NGINX

sudo apt-get update

sudo apt-get install nginx

Restarting NGINX

To restart NGINX

sudo systemctl restart nginx

To just reload the NGINX

nginx -s reload

This will reload the NGINX config and any changes you make to it.

NGINX Config

A Sample Config for one of my static sites.

server {
  listen 80;

  listen [::]:80;

  root /var/www/jameskenny.co;

  index index.html;

  server_name jameskenny.io www.jameskenny.io;

  location / {
    try_files $uri $uri/ =404;
  }
}

A sample config of a reverse proxy for a docker container.

server {
  listen 80;

  listen [::]:80;

  server_name touroperator.io www.touroperator.io;

   set $upstream 127.0.0.1:8080;

 location / {
 
 proxy_pass_header Authorization;
 proxy_pass http://$upstream;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_http_version 1.1;
 proxy_set_header Connection "";
 proxy_buffering off;
 client_max_body_size 0;
 proxy_read_timeout 36000s;
 proxy_redirect off;

 }
}

A short guide of commands I've found myself using on Ubuntu for NGINX, I'll update this post as I find more. Installing NGINX sudo apt-get update sudo apt-get install nginx Restarting NGINX To restart NGINX sudo systemctl restart nginx To just reload the NGINX nginx -s reload This will reload…

Read More

NGINX Reverse Proxy for Docker

This post is a guide on setting the NGINX Config to work as a reverse proxy to our web application inside a docker container. When you use docker to host your web applications and services. It's handy to be able to use a reverse proxy to pass the traffic on port 80 and route it to the right container.

One cool thing about NGINX is we can running docker and static sites on the same linux box. It's just a case of having different NGINX config files.

I've setup a web application built in .net core and running inside a container. On my linux server I create a docker instance and set it to run on port 8080.

docker run --name some-app1 -d -p 8080:80 some-app1

Once the docker container is running we can go ahead and create a NGINX config for the reverse proxy.

Reverse Proxy Config

First in the folder we need to create our config.

/etc/nginx/site-available

The following is our reverse proxy config for a website I have called 'touroperator.io'

server {
  listen 80;

  listen [::]:80;

  server_name touroperator.io www.touroperator.io;

   set $upstream 127.0.0.1:8080;

 location / {
 
 proxy_pass_header Authorization;
 proxy_pass http://$upstream;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_http_version 1.1;
 proxy_set_header Connection "";
 proxy_buffering off;
 client_max_body_size 0;
 proxy_read_timeout 36000s;
 proxy_redirect off;
 }
}

The config is doing a number of things.

  • Listen for traffic on Port 80
  • Only deal with requests for the touroperator.io or www.touroperator.io domain name
  • Upstream we set it to 127.0.0.1 and port 8080 so it's sending traffic to it's own network card on port 8080. This is the same port our docker image is running on.
  • Next in Location we pass a number of bits of information up the pipe to the website.

Note: this type of config can be used for load balancing and other things. As I explore this deeper more posts will follow.

Next we need to create a short cut in the 'site-enabled' folder.

ln -s /etc/nginx/sites-available/touroperator.io /etc/nginx/sites-enabled/touroperator.io

Remember to change the file name to your own.

Lastly reload the NGINX server

nginx -s reload

And point your DNS and you are running. The traffic will be routed to the docker container.

This post is a guide on setting the NGINX Config to work as a reverse proxy to our web application inside a docker container. When you use docker to host your web applications and services. It's handy to be able to use a reverse proxy to pass the traffic on…

Read More

Setting up Docker on Linode

A quick guide to setting up Docker on a Linode Ubuntu server. As I go deeper into exploring docker and building applications and services in new ways, I wanted a post that acts as a starting point.

Installing docker

$ sudo apt-get update

First, add the GPG key for the official Docker repository to the system:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources:

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Then Install Docker

sudo apt-get install -y docker-ce

Check the Docker Status

sudo systemctl status docker

That's it docker is now running on our Linux server. I will be adding more posts to the blog as I explore docker more.

A quick guide to setting up Docker on a Linode Ubuntu server. As I go deeper into exploring docker and building applications and services in new ways, I wanted a post that acts as a starting point. Installing docker $ sudo apt-get update First, add the GPG key for the official…

Read More