hot config reload with OS signal

Imagine a scenario where you have a monolithic application which uses a config file to store information about log directories, cert dirs and other service information. As an example to it following config file (- it is taken and modified from Haaukins project which I work on- ) can be considered:

In this config file we have some set of keys which are defined to be used inside the application, however let’s say we would like to update some values from the config file. Then in normal cases (-if no hot reload kind of function implemented- ), user needs to restart entire application. It means application will have some down time, it may be less or more however it is not good way of doing it, in particular to update only a value from config file.

In this point, os signals can be used to update config file without restarting or closing the application. There are some other libraries which it is possible to enable watch on config file mode. It means the library will immediately notify entire application when there is change on the config file. However in this scenario, I assume that there is no such a library or framework is integrated.

Here I am considering the situation from Go language perspective, this may differ or not needed for some programming languages or frameworks.

Channel and go routine will be used to listen any SIGHUP signal to the process of the application.

First of all, it is nice to create the function which will re-assign config variable of the application when SIGHUP signal received.

When SIGNUP signal received by user given function above needs to be called to update configuration file.

Here is the code which listens any SIGHUP signal to the application

handleHotConfigReload function

This function can be called before or after the application started. It can be called as shown below:

call handleHotConfigReload function

Then it can be tested with :

kill -SIGHUP <process-id>

It will create SIGHUP signal on the process to call ReloadConfig function.

This is how OS Signal can be used to update configuration file in an application which is written in Go, when you do not have already implemented library or framework.

Originally published at on April 18, 2021.




Software Engineer at Aalborg University, Denmark

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Example of fast creation of PHP client for Jira REST API.

Leet Code 32. Longest Valid Parentheses — Graphically Explained Python3 Solution

Blurb/Article Format

A Telegram Bot with the Power of Computer Vision

June Insights for the Next Breakthrough: Intento Named a Cool Vendor by Gartner, and more!

Git: Download a Repository’s Specific Subfolder

Making a Raspbian Cross Compilation SDK

How to really unit test code that uses a DB.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmet Türkmen

Ahmet Türkmen

Software Engineer at Aalborg University, Denmark

More from Medium

I’m doing Advent of code and you should too

Memory usage analysis for a go application on Linux

Which special characters must be escaped in regular expressions

Go: validate email address