1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 MySQL
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program 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
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2008 Drizzle Open Source Project
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
16
/* maintaince of drizzle databases */
25
20
#include <mysys/my_pthread.h> /* because of signal() */
26
21
#include <sys/stat.h>
28
/* Added this for string translation. */
29
#include <drizzled/gettext.h>
31
23
#define ADMIN_VERSION "8.42"
32
24
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
34
26
char *host= NULL, *user= NULL, *opt_password= NULL;
35
static bool interrupted= false, opt_verbose= false,tty_password= false;
27
static bool interrupted= false, opt_verbose= false,tty_password= false;
28
static uint8_t opt_protocol= DRIZZLE_PROTOCOL_TCP;
36
29
static uint32_t tcp_port= 0, option_wait= 0, option_silent= 0;
37
30
static uint32_t my_end_arg;
38
31
static uint32_t opt_connect_timeout, opt_shutdown_timeout;
39
32
static myf error_flags; /* flags to pass to my_printf_error, like ME_BELL */
46
37
static void usage(void);
47
38
static void print_version(void);
48
extern "C" void endprog(int signal_number);
39
extern "C" sig_handler endprog(int signal_number);
49
40
extern "C" bool get_one_option(int optid, const struct my_option *opt,
51
42
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv);
73
64
static struct my_option my_long_options[] =
75
{"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG,
66
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
76
67
NO_ARG, 0, 0, 0, 0, 0, 0},
77
{"host", 'h', N_("Connect to host."), (char**) &host, (char**) &host, 0, GET_STR,
68
{"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
78
69
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
80
N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
71
"Password to use when connecting to server. If password is not given it's asked from the tty.",
81
72
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
82
{"port", 'p', N_("Port number to use for connection or 0 for default to, in "
83
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
84
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."),
85
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
86
{"silent", 's', N_("Silently exit if one can't connect to server."),
73
{"port", 'P', "Port number to use for connection or 0 for default to, in "
74
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
75
#if MYSQL_PORT_DEFAULT == 0
78
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
80
(char**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
81
{"silent", 's', "Silently exit if one can't connect to server.",
87
82
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
88
83
#ifndef DONT_ALLOW_USER_CHANGE
89
{"user", 'u', N_("User for login if not current user."), (char**) &user,
84
{"user", 'u', "User for login if not current user.", (char**) &user,
90
85
(char**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
92
{"verbose", 'v', N_("Write more information."), (char**) &opt_verbose,
87
{"verbose", 'v', "Write more information.", (char**) &opt_verbose,
93
88
(char**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
94
{"version", 'V', N_("Output version information and exit."), 0, 0, 0, GET_NO_ARG,
89
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
95
90
NO_ARG, 0, 0, 0, 0, 0, 0},
96
{"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_UINT,
91
{"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_UINT,
97
92
OPT_ARG, 0, 0, 0, 0, 0, 0},
98
93
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (char**) &opt_connect_timeout,
99
94
(char**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0,
108
103
static const char *load_default_groups[]= { "drizzleadmin","client",0 };
111
get_one_option(int optid, const struct my_option *, char *argument)
106
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
114
uint64_t temp_drizzle_port= 0;
119
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
120
/* if there is an alpha character this is not a valid port */
121
if (strlen(endchar) != 0)
123
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
126
/* If the port number is > 65535 it is not a valid port
127
This also helps with potential data loss casting unsigned long to a
129
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
131
fprintf(stderr, _("Value supplied for port is not valid.\n"));
136
tcp_port= (uint32_t) temp_drizzle_port;
142
115
char *start=argument;
146
opt_password= strdup(argument);
147
if (opt_password == NULL)
149
fprintf(stderr, _("Memory allocation error while copying password. "
155
/* Overwriting password with 'x' */
116
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
117
opt_password= my_strdup(argument,MYF(MY_FAE));
118
while (*argument) *argument++= 'x'; /* Destroy argument */
160
/* Cut length of argument */
120
start[1]=0; /* Cut length of argument */
291
252
host= (char*) LOCAL_HOST;
293
my_printf_error(0,_("connect to server at '%s' failed\nerror: '%s'"),
254
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
294
255
error_flags, host, drizzle_error(drizzle));
296
257
if (drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
297
258
drizzle_errno(drizzle) == CR_UNKNOWN_HOST)
299
fprintf(stderr,_("Check that drizzled is running on %s"),host);
300
fprintf(stderr,_(" and that the port is %d.\n"),
301
tcp_port ? tcp_port: drizzle_get_default_port());
302
fprintf(stderr,_("You can check this by doing 'telnet %s %d'\n"),
303
host, tcp_port ? tcp_port: drizzle_get_default_port());
260
fprintf(stderr,"Check that drizzled is running on %s",host);
261
fprintf(stderr," and that the port is %d.\n",
262
tcp_port ? tcp_port: drizzle_port);
263
fprintf(stderr,"You can check this by doing 'telnet %s %d'\n",
264
host, tcp_port ? tcp_port: drizzle_port);
308
if (wait != UINT32_MAX)
269
if (wait != (uint) ~0)
309
270
wait--; /* One less retry */
310
271
if ((drizzle_errno(drizzle) != CR_CONN_HOST_ERROR) &&
311
272
(drizzle_errno(drizzle) != CR_CONNECTION_ERROR))
313
fprintf(stderr,_("Got error: %s\n"), drizzle_error(drizzle));
274
fprintf(stderr,"Got error: %s\n", drizzle_error(drizzle));
315
276
else if (!option_silent)
320
fputs(_("Waiting for Drizzle server to answer"),stderr);
281
fputs("Waiting for Drizzle server to answer",stderr);
321
282
(void) fflush(stderr);
402
363
static void print_version(void)
404
printf(_("%s Ver %s Distrib %s, for %s on %s\n"),my_progname,ADMIN_VERSION,
405
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
365
printf("%s Ver %s Distrib %s, for %s on %s\n",my_progname,ADMIN_VERSION,
366
MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
408
369
static void usage(void)
411
puts(_("Copyright (C) 2000-2008 MySQL AB"));
412
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"));
413
puts(_("Administration program for the drizzled daemon."));
414
printf(_("Usage: %s [OPTIONS] command command....\n"), my_progname);
372
puts("Copyright (C) 2000-2006 DRIZZLE AB");
373
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
374
puts("Administration program for the drizzled daemon.");
375
printf("Usage: %s [OPTIONS] command command....\n", my_progname);
415
376
my_print_help(my_long_options);
417
378
ping Check if server is down\n\
418
shutdown Take server down\n"));
379
shutdown Take server down\n");