ironsmile / nedomi

Highly performant HTTP reverse proxy with efficient caching of big files
GNU General Public License v3.0
81 stars 9 forks source link

How to reload JSON config #227

Closed alectrocute closed 5 years ago

alectrocute commented 5 years ago

@ironsmile

I looked through the PR’s for reload* functions but as a Golang noob, can’t figure out how to reload the config on an actively running nedomi PID.

Do I have to daemonize it? Or what? How could I go about adding a virtual host without stopping and starting the process?

I absolutely love this software. Thanks so much.

ironsmile commented 5 years ago

Hello @alectrocute ! I am more than happy it is helpful to someone.

You don't have to daemonize the process. When the nedomi starts it will print in its logs its process ID (PID) with the following line:

2019/03/05 09:40:43 Application 26110 started

You can find out what the PID of a running instance using pidof nedomi as well.

Then you can edit the JSON config file add add, remove or change directives as much as you like. Once you've saved the config file you have to send nedomi a HUP signal using its PID:

kill -s 1 26110

Nedomi will then reload itself without dropping any connections. And you don't have to be particularly careful with the configuration. If there is some logic or syntax error in the new JSON file then Nedomi will refuse to use it and notify you about the problem in its logs. There are certain things which cannot be changed via this "live" reload and if you've changed any of those you will be notified in the logs as well. Example:

2019/03/05 09:40:41 Reloading failed: can't change read_timeout by reload

If you don't see "Reloading failed" message then your reload has gone through without a problem and everything in your new config has been loaded. We've tested it with many reloads under heavy load and it does it without a hiccup.

alectrocute commented 5 years ago

@ironsmile Wow, I don’t think I’ve ever gotten such helpful info in a GitHub issue. I greatly appreciate that.

alectrocute commented 5 years ago

For anybody here, tomorrow or years in the future (hello, from the past), here's a simple shell/bash script that will easily reload your configuration (great for if you have a network of 20+ nedomi instances and want to reload the config across the entire fleet):

pid=$(cat /tmp/nedomi_pidfile.pid);
kill -s 1 ${pid};
echo "nedomi instance with pid ${pid} reloaded";