mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 06:40:59 +01:00
[MEDIUM] config: support loading multiple configuration files
We now support up to 10 distinct configuration files. They are all loaded in the order defined by -f <file1> -f <file2> ... This can be useful in order to store global, private, public, etc... configurations in distinct files.
This commit is contained in:
parent
915e1ebe63
commit
5d01a63b78
@ -58,6 +58,9 @@
|
|||||||
#define LINESIZE 2048
|
#define LINESIZE 2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// max # of configuration files
|
||||||
|
#define MAX_CFG_FILES 10
|
||||||
|
|
||||||
// max # args on a configuration line
|
// max # args on a configuration line
|
||||||
#define MAX_LINE_ARGS 64
|
#define MAX_LINE_ARGS 64
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,8 @@
|
|||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
char *cfg_cfgfile = NULL; /* configuration file */
|
static int cfg_nbcfgfiles; /* number of config files */
|
||||||
|
static char *cfg_cfgfile[10]; /* configuration files, stop at NULL */
|
||||||
char *progname = NULL; /* program name */
|
char *progname = NULL; /* program name */
|
||||||
int pid; /* current process id */
|
int pid; /* current process id */
|
||||||
int relative_pid = 1; /* process id starting at 1 */
|
int relative_pid = 1; /* process id starting at 1 */
|
||||||
@ -197,7 +198,7 @@ void usage(char *name)
|
|||||||
{
|
{
|
||||||
display_version();
|
display_version();
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage : %s -f <cfgfile> [ -vdV"
|
"Usage : %s [-f <cfgfile>]* [ -vdV"
|
||||||
"D ] [ -n <maxconn> ] [ -N <maxpconn> ]\n"
|
"D ] [ -n <maxconn> ] [ -N <maxpconn> ]\n"
|
||||||
" [ -p <pidfile> ] [ -m <max megs> ]\n"
|
" [ -p <pidfile> ] [ -m <max megs> ]\n"
|
||||||
" -v displays version ; -vv shows known build options.\n"
|
" -v displays version ; -vv shows known build options.\n"
|
||||||
@ -205,7 +206,7 @@ void usage(char *name)
|
|||||||
" -V enters verbose mode (disables quiet mode)\n"
|
" -V enters verbose mode (disables quiet mode)\n"
|
||||||
" -D goes daemon\n"
|
" -D goes daemon\n"
|
||||||
" -q quiet mode : don't display messages\n"
|
" -q quiet mode : don't display messages\n"
|
||||||
" -c check mode : only check config file and exit\n"
|
" -c check mode : only check config files and exit\n"
|
||||||
" -n sets the maximum total # of connections (%d)\n"
|
" -n sets the maximum total # of connections (%d)\n"
|
||||||
" -m limits the usable amount of memory (in MB)\n"
|
" -m limits the usable amount of memory (in MB)\n"
|
||||||
" -N sets the default, per-proxy maximum # of connections (%d)\n"
|
" -N sets the default, per-proxy maximum # of connections (%d)\n"
|
||||||
@ -507,7 +508,14 @@ void init(int argc, char **argv)
|
|||||||
case 'n' : cfg_maxconn = atol(*argv); break;
|
case 'n' : cfg_maxconn = atol(*argv); break;
|
||||||
case 'm' : global.rlimit_memmax = atol(*argv); break;
|
case 'm' : global.rlimit_memmax = atol(*argv); break;
|
||||||
case 'N' : cfg_maxpconn = atol(*argv); break;
|
case 'N' : cfg_maxpconn = atol(*argv); break;
|
||||||
case 'f' : cfg_cfgfile = *argv; break;
|
case 'f' :
|
||||||
|
if (cfg_nbcfgfiles > MAX_CFG_FILES) {
|
||||||
|
Alert("Cannot load configuration file %s : too many configuration files (max %d).\n",
|
||||||
|
*argv, MAX_CFG_FILES);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
cfg_cfgfile[cfg_nbcfgfiles++] = *argv;
|
||||||
|
break;
|
||||||
case 'p' : cfg_pidfile = *argv; break;
|
case 'p' : cfg_pidfile = *argv; break;
|
||||||
default: usage(old_argv);
|
default: usage(old_argv);
|
||||||
}
|
}
|
||||||
@ -522,7 +530,7 @@ void init(int argc, char **argv)
|
|||||||
(arg_mode & (MODE_DAEMON | MODE_FOREGROUND | MODE_VERBOSE
|
(arg_mode & (MODE_DAEMON | MODE_FOREGROUND | MODE_VERBOSE
|
||||||
| MODE_QUIET | MODE_CHECK | MODE_DEBUG));
|
| MODE_QUIET | MODE_CHECK | MODE_DEBUG));
|
||||||
|
|
||||||
if (!cfg_cfgfile)
|
if (!cfg_nbcfgfiles)
|
||||||
usage(old_argv);
|
usage(old_argv);
|
||||||
|
|
||||||
gethostname(hostname, MAX_HOSTNAME_LEN);
|
gethostname(hostname, MAX_HOSTNAME_LEN);
|
||||||
@ -532,10 +540,12 @@ void init(int argc, char **argv)
|
|||||||
|
|
||||||
init_default_instance();
|
init_default_instance();
|
||||||
|
|
||||||
if (readcfgfile(cfg_cfgfile) < 0) {
|
for (i = 0; i < cfg_nbcfgfiles; i++) {
|
||||||
Alert("Error reading configuration file : %s\n", cfg_cfgfile);
|
if (readcfgfile(cfg_cfgfile[i]) < 0) {
|
||||||
|
Alert("Error reading configuration file : %s\n", cfg_cfgfile[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (check_config_validity() < 0) {
|
if (check_config_validity() < 0) {
|
||||||
Alert("Errors found in configuration.\n");
|
Alert("Errors found in configuration.\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user