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

Virtual Machine

Welcome to Notarum!

React Native CI/CD Pipeline using Fastlane and Azure

3sat Mediathek Download Mac

Writeup — HTsP X-MAS CTF 2020 — Comfort bot

Part 2: Troubleshooting our Architecture Decision Process

Know about OpenShift tech and its industry use cases…

GraphQL Schemas Will Make Your Existing Data Modeling Practices Obsolete

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

Go for REST API development

Simple REST service in Golang with OpenAPI spec and ORM

Behind the scene Golang Static Analysis

Validate Zero Enum Value in Protocol Buffer