unit icon indicating copy to clipboard operation
unit copied to clipboard

Question: Finding configuration variables in source code

Open aliahad97 opened this issue 5 years ago • 5 comments

Hello,

I had been going through the source code and because of which had two questions.

  1. Are configuration changes happen through file or in-memory? I saw that the router configuration was using the path to files as can be seen here. So looking by this code, do configuration update take place by reading from files? How does this mean that the configuration update is done dynamically?

  2. Which function in the source is responsible for updating configuration values in-memory? There are a lot of configuration variables and functions that update these variables. However, I want variables in the "settings" JSON object which primarily updates the variable of this struct (nxt_socket_conf_t). Also, I would like to know which global variable is used to store runtime configuration which would be updated or read in memory.

I am trying to understand configuration maintenance in this project and would appreciate all the help that I could get. I really love this project and so would like to understand it better.

Best, Ali

aliahad97 avatar Jun 30 '20 06:06 aliahad97

  1. Configuration changes happen by HTTP API request. Those aren't path to files. Those are URIs to navigate over JSON object received via API.

  2. On configuration change a new configuration object is constructed there. Old requests are still using previous configuration object, while new requests start using a new object. You can't just replace existing values in-memory. That simply won't work properly as it can result in some strange unpredictable behaviour due to inconsistecy between new values and existing connection or request.

VBart avatar Jun 30 '20 09:06 VBart

Thank you so much. This makes a lot more sense.

One last question. These JSON objects which are received via API. Where are they stored? Or are they just used to update the config and dropped once new config objects are created?

And where is the global variable which would maintain the config object which all new requests would use?

aliahad97 avatar Jun 30 '20 17:06 aliahad97

@VBart Would the inclusion of a variables property on the config object be pass down as variables to the application environment?

{
    "variables":{ ...add environment variables here or paths to another json file containing variables },
    "listeners": { ..add listeners here },
    "applications": { ..add applications here},
    "routes": { ..add application routes here}
}

derryspann avatar Sep 27 '21 02:09 derryspann

@hyperking There is the environment option, where you can specify any additional environment variable to pass to the app: https://unit.nginx.org/configuration/#applications

VBart avatar Sep 27 '21 02:09 VBart

@hyperking There is the environment option, where you can specify any additional environment variable to pass to the app: https://unit.nginx.org/configuration/#applications

haha Right! I just noticed that in the docs full examples. it can be a bit hard reading the docs. thanks.

derryspann avatar Sep 27 '21 02:09 derryspann

@hyperking thanks for the feedback about the docs. @aliahad97 glad you like it and keep asking good / challenging questions! Will close this issue for now but as said please come Back to uns in case you have any more questions.

tippexs avatar Dec 03 '22 11:12 tippexs