4 Copyright (C) Andrew Tridgell 2006
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "lib/events/events.h"
23 #include "system/filesys.h"
30 int main(int argc, const char *argv[])
32 struct ctdb_context *ctdb;
33 const char *nlist = NULL;
34 const char *transport = "tcp";
35 const char *myaddress = NULL;
39 struct poptOption popt_options[] = {
41 { "nlist", 0, POPT_ARG_STRING, &nlist, 0, "node list file", "filename" },
42 { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
43 { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
44 { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
45 { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
49 const char **extra_argv;
53 struct event_context *ev;
55 pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
57 while ((opt = poptGetNextOpt(pc)) != -1) {
60 fprintf(stderr, "Invalid option %s: %s\n",
61 poptBadOption(pc, 0), poptStrerror(opt));
66 /* setup the remaining options for the main program to use */
67 extra_argv = poptGetArgs(pc);
70 while (extra_argv[extra_argc]) extra_argc++;
73 if (nlist == NULL || myaddress == NULL) {
74 printf("You must provide a node list with --nlist and an address with --listen\n");
78 ev = event_context_init(NULL);
83 printf("Failed to init ctdb\n");
88 ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT);
91 ctdb_set_flags(ctdb, CTDB_FLAG_DAEMON_MODE);
94 ret = ctdb_set_transport(ctdb, transport);
96 printf("ctdb_set_transport failed - %s\n", ctdb_errstr(ctdb));
100 /* tell ctdb what address to listen on */
101 ret = ctdb_set_address(ctdb, myaddress);
103 printf("ctdb_set_address failed - %s\n", ctdb_errstr(ctdb));
107 /* tell ctdb what nodes are available */
108 ret = ctdb_set_nlist(ctdb, nlist);
110 printf("ctdb_set_nlist failed - %s\n", ctdb_errstr(ctdb));
114 /* start the protocol running */
115 ret = ctdb_start(ctdb);