mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-daemon: Implement ctdb configuration file loading
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
b42dbadbef
commit
239f189b10
161
ctdb/server/ctdb_config.c
Normal file
161
ctdb/server/ctdb_config.c
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
CTDB daemon config handling
|
||||
|
||||
Copyright (C) Martin Schwenke 2018
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "replace.h"
|
||||
|
||||
#include "lib/util/debug.h"
|
||||
|
||||
#include "common/conf.h"
|
||||
#include "common/logging_conf.h"
|
||||
#include "common/path.h"
|
||||
|
||||
#include "cluster/cluster_conf.h"
|
||||
#include "database/database_conf.h"
|
||||
#include "event/event_conf.h"
|
||||
#include "legacy_conf.h"
|
||||
|
||||
#include "ctdb_config.h"
|
||||
|
||||
struct ctdb_config ctdb_config;
|
||||
|
||||
static void setup_config_pointers(struct conf_context *conf)
|
||||
{
|
||||
/*
|
||||
* Cluster
|
||||
*/
|
||||
|
||||
conf_assign_string_pointer(conf,
|
||||
CLUSTER_CONF_SECTION,
|
||||
CLUSTER_CONF_TRANSPORT,
|
||||
&ctdb_config.transport);
|
||||
conf_assign_string_pointer(conf,
|
||||
CLUSTER_CONF_SECTION,
|
||||
CLUSTER_CONF_NODE_ADDRESS,
|
||||
&ctdb_config.node_address);
|
||||
conf_assign_string_pointer(conf,
|
||||
CLUSTER_CONF_SECTION,
|
||||
CLUSTER_CONF_RECOVERY_LOCK,
|
||||
&ctdb_config.recovery_lock);
|
||||
|
||||
/*
|
||||
* Database
|
||||
*/
|
||||
|
||||
conf_assign_string_pointer(conf,
|
||||
DATABASE_CONF_SECTION,
|
||||
DATABASE_CONF_VOLATILE_DB_DIR,
|
||||
&ctdb_config.dbdir_volatile);
|
||||
conf_assign_string_pointer(conf,
|
||||
DATABASE_CONF_SECTION,
|
||||
DATABASE_CONF_PERSISTENT_DB_DIR,
|
||||
&ctdb_config.dbdir_persistent);
|
||||
conf_assign_string_pointer(conf,
|
||||
DATABASE_CONF_SECTION,
|
||||
DATABASE_CONF_STATE_DB_DIR,
|
||||
&ctdb_config.dbdir_state);
|
||||
conf_assign_string_pointer(conf,
|
||||
DATABASE_CONF_SECTION,
|
||||
DATABASE_CONF_LOCK_DEBUG_SCRIPT,
|
||||
&ctdb_config.lock_debug_script);
|
||||
|
||||
/*
|
||||
* Event
|
||||
*/
|
||||
conf_assign_string_pointer(conf,
|
||||
EVENT_CONF_SECTION,
|
||||
EVENT_CONF_DEBUG_SCRIPT,
|
||||
&ctdb_config.event_debug_script);
|
||||
|
||||
/*
|
||||
* Legacy
|
||||
*/
|
||||
|
||||
conf_assign_boolean_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_NO_REALTIME,
|
||||
&ctdb_config.no_realtime);
|
||||
conf_assign_boolean_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_RECMASTER_CAPABILITY,
|
||||
&ctdb_config.recmaster_capability);
|
||||
conf_assign_boolean_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_LMASTER_CAPABILITY,
|
||||
&ctdb_config.lmaster_capability);
|
||||
conf_assign_boolean_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_START_AS_STOPPED,
|
||||
&ctdb_config.start_as_stopped);
|
||||
conf_assign_boolean_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_START_AS_DISABLED,
|
||||
&ctdb_config.start_as_disabled);
|
||||
conf_assign_string_pointer(conf,
|
||||
LEGACY_CONF_SECTION,
|
||||
LEGACY_CONF_SCRIPT_LOG_LEVEL,
|
||||
&ctdb_config.script_log_level);
|
||||
}
|
||||
|
||||
int ctdbd_config_load(TALLOC_CTX *mem_ctx,
|
||||
struct conf_context **result)
|
||||
{
|
||||
struct conf_context *conf = NULL;
|
||||
int ret = 0;
|
||||
char *conf_file = NULL;
|
||||
|
||||
ret = conf_init(mem_ctx, &conf);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
logging_conf_init(conf, "NOTICE");
|
||||
cluster_conf_init(conf);
|
||||
database_conf_init(conf);
|
||||
event_conf_init(conf);
|
||||
legacy_conf_init(conf);
|
||||
|
||||
setup_config_pointers(conf);
|
||||
|
||||
if (! conf_valid(conf)) {
|
||||
ret = EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
conf_file = path_config(conf);
|
||||
if (conf_file == NULL) {
|
||||
D_ERR("Memory allocation error\n");
|
||||
ret = ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
ret = conf_load(conf, conf_file, true);
|
||||
/* Configuration file does not need to exist */
|
||||
if (ret != 0 && ret != ENOENT) {
|
||||
D_ERR("Failed to load configuration file %s\n", conf_file);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
talloc_free(conf_file);
|
||||
*result = conf;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
talloc_free(conf);
|
||||
return ret;
|
||||
}
|
53
ctdb/server/ctdb_config.h
Normal file
53
ctdb/server/ctdb_config.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
CTDB daemon config handling
|
||||
|
||||
Copyright (C) Martin Schwenke 2018
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CTDB_CONFIG_H__
|
||||
#define __CTDB_CONFIG_H__
|
||||
|
||||
#include "common/conf.h"
|
||||
|
||||
struct ctdb_config {
|
||||
/* Cluster */
|
||||
const char *transport;
|
||||
const char *node_address;
|
||||
const char *recovery_lock;
|
||||
|
||||
/* Database */
|
||||
const char *dbdir_volatile;
|
||||
const char *dbdir_persistent;
|
||||
const char *dbdir_state;
|
||||
const char *lock_debug_script;
|
||||
|
||||
/* Event */
|
||||
const char *event_debug_script;
|
||||
|
||||
/* Legacy */
|
||||
bool no_realtime;
|
||||
bool recmaster_capability;
|
||||
bool lmaster_capability;
|
||||
bool start_as_stopped;
|
||||
bool start_as_disabled;
|
||||
const char *script_log_level;
|
||||
};
|
||||
|
||||
extern struct ctdb_config ctdb_config;
|
||||
|
||||
int ctdbd_config_load(TALLOC_CTX *mem_ctx, struct conf_context **conf);
|
||||
|
||||
#endif /* __CTDB_CONFIG_H__ */
|
@ -509,10 +509,17 @@ def build(bld):
|
||||
ctdb_statistics.c
|
||||
ctdb_update_record.c
|
||||
ctdb_lock.c ctdb_fork.c
|
||||
ctdb_tunnel.c ctdb_client.c'''),
|
||||
ctdb_tunnel.c ctdb_client.c
|
||||
ctdb_config.c
|
||||
'''),
|
||||
includes='include',
|
||||
deps='''ctdb-common ctdb-system ctdb-protocol
|
||||
ctdb-tcp ctdb-util replace sys_rw popt
|
||||
ctdb-logging-conf
|
||||
ctdb-cluster-conf
|
||||
ctdb-database-conf
|
||||
ctdb-event-conf
|
||||
ctdb-legacy-conf
|
||||
talloc tevent tdb-wrap tdb talloc_report''' +
|
||||
ib_deps,
|
||||
install_path='${SBINDIR}',
|
||||
|
Loading…
Reference in New Issue
Block a user