Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config reloading feature #18

Closed
flashmob opened this issue Nov 21, 2016 · 3 comments · Fixed by #33
Closed

Config reloading feature #18

flashmob opened this issue Nov 21, 2016 · 3 comments · Fixed by #33

Comments

@flashmob
Copy link
Owner

flashmob commented Nov 21, 2016

Currently working on it. Hope to have the following features when a SIG_HUP is caught:

  1. "allowed hosts" map reloading (need this since we change/add hosts frequently)
  2. Backend switching, ie. detect if backend config changed, close old backend and spawn a new one
  3. detect if SSL cert changed and reload it (useful since letsencrypt certs expire every few months, so our server would need to reload the ssl certs once per day at least)
  4. Listening interface changes. Detect if interface changed. If changed, shutdown old server(s) and start a new one(s) (Not really needed feature, may leave for later)
  5. Close and re-open log files. (Need this for logrotate)

That way the server can continue working without disrupting the hundreds of connections it may have open.

Going to implement it using an event based approach using https://github.com/asaskevich/EventBus

@flashmob
Copy link
Owner Author

flashmob commented Nov 22, 2016

Since the config can change, another thing to take into account would be thread safety. This should be handy https://golang.org/pkg/sync/atomic/#example_Value_config

@flashmob
Copy link
Owner Author

To make it easier, old connections will still use existing config. Subsequent new connections will use the new config.

@flashmob
Copy link
Owner Author

First draft #19

flashmob added a commit that referenced this issue Jan 16, 2017
Fixes #18 

* Fixed a bug where pidFile from config was ignored and replaced with the default
* removed unused 'verbose' variable
* guerrilla struct now holds servers as a map instead of slice
* API change: guerrilla.New() now returns error
* Refactor TLS config into a separate function
* server's serverConfig is now kept in an atomic value, ready for hot config reload
* Slightly raised the hard limit on DATA state, to avoid potential errors
* Refactored allowedHosts to use a map for lookup instead of doing O(n)
*  Discard ending .\r\n - fixes #24
* Split the Envelope struct into its own package, as both backend and guerrilla depend on it
* update tests after merging latest tests from master
* Removed case statement in serve.go to make backends dynamically loaded. Structural changes so that that backends support worker pools & can re-use code.
* Future groundwork for decorator pattern
* pass saveMailChan via function instead of embedding (simplify)
going to save decorator pattern for another day, needs more thinking
* added event bus package to use for hot config reload
* emit config change events on config file changes when SIGHUP gets caught
* config tests, including events and sample config
* add pid_file to config sample
* add tests for backend config changes
* plug in test to travis
* generate cert before test
* tests for serve.go config reload
* add tests to Makefile
* pass server config as pointer
* events for adding, starting, stopping and removing a server
* fix server would hang on Accept error
* New Errors type for guerrilla package to hold multiple errors
* Start() and New() return the new Errors type
* Behavior change of serve: does not exit if servers could not be started
* Tests for server_change:start_server fired when server was enabled after reloading config - TestServerStartEvent
* refactoring to client to prevent a race condition on setTimeout function
bug found during this build https://travis-ci.org/flashmob/go-guerrilla/jobs/191348662
* Server stop event now working, added test TestServerStopEvent
* Backend proxy: added states & shutdown is protected by mutex
* Behaviour change: sigHandler will return rather than exit on kill / sigterm signals
* Backend errors: revert to return error as error rather than custom type...
* fix TLS handshake error formatting
*  "allowed hosts" config setting moved back to root level. Servers still keep their own table in a map, which may be customized in the future.
* "allowed hosts" now supports config reload event, will reload for all servers when SIGHUP is caught.
* test for allowed_hosts config reload
* TLS certificate config reload
* config reload for server's Timeout setting + test
* leave max_clients for another issue since it requires pool resizing
* embedded the event bus in the guerrilla struct and be as part of the Guerrilla interface. This should make the event bus easy to swap out should it be changed to a different implementation. Users of the API can also have easier access to the server events
* update readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant