138 #define UTIL_TYPE_SERVICE "service" 139 #define UTIL_TYPE_SERVER "server" 140 #define UTIL_TYPE_BROKER "broker" 141 #define UTIL_TYPE_MANAGER "manager" 142 #define UTIL_TYPE_HEARTBEAT "heartbeat" 143 #define UTIL_TYPE_HB_SHORT "hb" 144 #define UTIL_TYPE_JAVASP "javasp" 164 {
ADMIN, UTIL_OPTION_DELVOLDB, MASK_ADMIN},
198 #define COMMAND_TYPE_START "start" 199 #define COMMAND_TYPE_STOP "stop" 200 #define COMMAND_TYPE_RESTART "restart" 201 #define COMMAND_TYPE_STATUS "status" 202 #define COMMAND_TYPE_DEREG "deregister" 203 #define COMMAND_TYPE_LIST "list" 204 #define COMMAND_TYPE_RELOAD "reload" 205 #define COMMAND_TYPE_ON "on" 206 #define COMMAND_TYPE_OFF "off" 207 #define COMMAND_TYPE_ACL "acl" 208 #define COMMAND_TYPE_RESET "reset" 209 #define COMMAND_TYPE_INFO "info" 210 #define COMMAND_TYPE_COPYLOGDB "copylogdb" 211 #define COMMAND_TYPE_APPLYLOGDB "applylogdb" 212 #define COMMAND_TYPE_GETID "getid" 213 #define COMMAND_TYPE_TEST "test" 214 #define COMMAND_TYPE_REPLICATION "replication" 215 #define COMMAND_TYPE_REPLICATION_SHORT "repl" 261 static int process_service (
int command_type,
bool process_window_service);
263 bool process_window_service);
265 static int process_manager (
int command_type,
bool process_window_service);
279 static int proc_execute_internal (
const char *file,
const char *args[],
bool wait_child,
bool close_output,
280 bool close_err,
bool hide_cmd_args,
int *
pid);
281 static int proc_execute (
const char *file,
const char *args[],
bool wait_child,
bool close_output,
bool close_err,
284 bool close_err,
int *
pid);
287 static void print_message (FILE * output,
int message_id, ...);
288 static void print_result (
const char *util_name,
int status,
int command_type);
298 static bool is_windows_service_running (
unsigned int sleep_time);
303 bool check_win_service);
308 #if !defined(WINDOWS) 310 const char *remote_host);
312 const char *remote_host);
315 const char *
node_name,
const char *remote_host);
317 const char *remote_host);
319 #if defined (ENABLE_UNUSED_FUNCTION) 331 const char *remote_host);
333 const char *remote_host);
334 #if defined (ENABLE_UNUSED_FUNCTION) 335 static int us_hb_process_server (
int command_type,
HA_CONF * ha_conf,
const char *
db_name);
339 bool * immediate_stop,
int argc,
const char **
argv);
343 char *remote_host_name,
int remote_host_name_size,
int argc,
const char **
argv);
346 #define US_HB_DEREG_WAIT_TIME_IN_SEC 100 364 switch (command_type)
435 va_start (arg_list, message_id);
436 vfprintf (output, format, arg_list);
453 copy_argv = (
char **) malloc (
sizeof (
char *) * (argc + 1));
454 if (copy_argv ==
NULL)
459 memcpy (copy_argv, argv,
sizeof (
char *) * argc);
482 if (us_Service_map[i].option_type == util_type)
501 if (us_Command_map[i].option_type == command_type)
519 int util_type, command_type;
521 bool process_window_service =
false;
522 pid_t
pid = getpid ();
525 #if defined (DO_NOT_USE_CUBRIDENV) 533 "CAUTION : " "The environment variable $%s is set to %s.\n" 541 "CAUTION : " "The environment variable $%s_%s is set to %s.\n" 542 " But, built-in prefix (%s) will be used.\n\n",
envvar_prefix (),
"DATABASES", envval,
547 sprintf (env_buf,
"%d", pid);
552 Argv = (
const char **) argv;
563 if (argc < 2 || argc > 1024)
569 util_type =
parse_arg (us_Service_map, (
char *) argv[1]);
572 util_type =
parse_arg (us_Service_map, (
char *) argv[2]);
592 if (util_type ==
ADMIN)
612 command_type =
parse_arg (us_Command_map, (
char *) argv[2]);
615 command_type =
parse_arg (us_Command_map, (
char *) argv[1]);
627 if ((util_mask & command_mask) == 0)
643 process_window_service =
true;
646 && strcmp ((
char *) argv[3],
"--for-windows-service") == 0)
648 process_window_service =
false;
651 && strcmp ((
char *) argv[4],
"--for-windows-service") == 0)
653 process_window_service =
false;
656 assert (process_window_service ==
false);
667 status =
process_server (command_type, argc - 3, &argv[3],
true,
true, process_window_service);
670 status =
process_broker (command_type, argc - 3, (
const char **) &argv[3], process_window_service);
684 status =
process_javasp (command_type, argc - 3, (
const char **) &argv[3], process_window_service);
692 return ((status ==
NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE);
739 const char *exec_name;
742 exec_name =
basename ((
char *) argv0);
751 proc_execute (
const char *file,
const char *args[],
bool wait_child,
bool close_output,
bool close_err,
int *out_pid)
770 proc_execute_internal (
const char *file,
const char *args[],
bool wait_child,
bool close_output,
bool close_err,
771 bool hide_cmd_args,
int *out_pid)
774 PROCESS_INFORMATION pi;
775 int i, j, k, cmd_arg_len;
779 bool inherited_handle =
TRUE;
780 char fixed_arg[1024];
789 for (i = 0, cmd_arg_len = 0; args[
i]; i++)
791 if (strchr (args[i],
'"') ==
NULL)
793 cmd_arg_len += sprintf (cmd_arg + cmd_arg_len,
"\"%s\" ", args[i]);
798 for (j = 0; j <
strlen (args[i]); j++)
800 if (args[i][j] ==
'"')
802 fixed_arg[k++] =
'"';
804 fixed_arg[k++] = args[
i][j];
808 cmd_arg_len += sprintf (cmd_arg + cmd_arg_len,
"\"%s\" ", fixed_arg);
812 GetStartupInfo (&si);
813 si.dwFlags = si.dwFlags | STARTF_USESTDHANDLES;
814 si.hStdInput = GetStdHandle (STD_INPUT_HANDLE);
815 si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE);
816 si.hStdError = GetStdHandle (STD_ERROR_HANDLE);
817 inherited_handle =
TRUE;
821 si.hStdOutput =
NULL;
829 if (!CreateProcess (executable_path, cmd_arg,
NULL,
NULL, inherited_handle, 0,
NULL,
NULL, &si, &pi))
837 WaitForSingleObject (pi.hProcess, INFINITE);
838 GetExitCodeProcess (pi.hProcess, &status);
845 *out_pid = pi.dwProcessId;
849 CloseHandle (pi.hProcess);
850 CloseHandle (pi.hThread);
857 bool hide_cmd_args,
int *out_pid)
872 signal (SIGCHLD, SIG_DFL);
876 signal (SIGCHLD, SIG_IGN);
888 signal (SIGCHLD, SIG_DFL);
899 if (execv (executable_path, (
char *
const *) args) == -1)
909 if (hide_cmd_args ==
true)
920 tmp = waitpid (-1, &status, 0);
939 if (WIFEXITED (status))
941 return WEXITSTATUS (status);
962 for (i = 2; args[
i] !=
NULL; i++)
964 memset (args[i],
'\0',
strlen (args[i]));
981 int waited_seconds = 0;
985 switch (command_type)
995 while (status !=
NO_ERROR && waited_seconds < 180)
1004 #if !defined(WINDOWS) 1061 #if defined(WINDOWS) 1072 is_windows_service_running (
unsigned int sleep_time)
1075 char buf[32], cmd[PATH_MAX];
1079 make_exec_abspath (cmd, PATH_MAX, (
char *) UTIL_WIN_SERVICE_CONTROLLER_NAME
" " "-status");
1081 input = popen (cmd,
"r");
1087 memset (buf,
'\0',
sizeof (buf));
1089 if ((fgets (buf, 32, input) ==
NULL) || strncmp (buf,
"SERVICE_RUNNING", 15) != 0)
1147 if (check_win_service)
1149 #if defined (WINDOWS) 1151 ret = is_windows_service_running (sleep_time);
1174 char *list, *token, *save;
1175 const char *delim =
" ,:";
1177 memset (buf,
'\0',
sizeof (buf));
1179 strncpy (buf, us_Property_map[
SERVER_START_LIST].property_value,
sizeof (buf) - 1);
1181 for (list = buf;; list =
NULL)
1183 token = strtok_r (list, delim, &save);
1201 char *list, *token, *save;
1202 const char *delim =
" ,:";
1204 memset (buf,
'\0',
sizeof (buf));
1206 strncpy (buf, us_Property_map[
SERVER_START_LIST].property_value,
sizeof (buf) - 1);
1208 for (list = buf;; list =
NULL)
1210 token = strtok_r (list, delim, &save);
1274 switch (command_type)
1277 if (process_window_service)
1279 #if defined(WINDOWS) 1286 proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1339 if (process_window_service)
1341 #if defined(WINDOWS) 1342 if (is_windows_service_running (0))
1348 proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1421 const char *args[] = {
"-b" };
1457 char buf[4096], *token, *save_ptr, *delim = (
char *)
" ";
1461 input = popen (cmd,
"r");
1467 while (fgets (buf, 4096, input) !=
NULL)
1469 token = strtok_r (buf, delim, &save_ptr);
1484 if (strcmp (token, type) != 0)
1490 token = strtok_r (
NULL, delim, &save_ptr);
1491 if (token !=
NULL && strcmp (token, server_name) == 0)
1558 bool process_window_service)
1561 char *list, *token, *save;
1562 const char *delim =
" ,:";
1566 memset (buf,
'\0',
sizeof (buf));
1573 strncpy (buf, us_Property_map[
SERVER_START_LIST].property_value,
sizeof (buf) - 1);
1578 strncpy (buf, argv[0],
sizeof (buf) - 1);
1591 switch (command_type)
1594 if (process_window_service)
1596 #if defined(WINDOWS) 1601 for (list = buf;; list =
NULL)
1603 token = strtok_r (list, delim, &save);
1612 if (check_ha_mode ==
true)
1639 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1661 for (list = buf;; list =
NULL)
1663 token = strtok_r (list, delim, &save);
1670 #if !defined(WINDOWS) 1671 if (check_ha_mode ==
true)
1715 for (list = buf;; list =
NULL)
1717 token = strtok_r (list, delim, &save);
1726 if (process_window_service)
1728 #if defined(WINDOWS) 1734 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1740 #if !defined(WINDOWS) 1773 status =
process_server (
STOP, argc, argv, show_usage, check_ha_mode, process_window_service);
1774 status =
process_server (
START, argc, argv, show_usage, check_ha_mode, process_window_service);
1802 if (strcasecmp (argv[0],
"reload") == 0)
1811 else if (strcasecmp (argv[0],
"status") == 0)
1867 switch (command_type)
1879 if (process_window_service)
1881 #if defined(WINDOWS) 1886 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1911 if (process_window_service)
1913 #if defined(WINDOWS) 1918 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
1944 #if defined (WINDOWS) 1958 args = (
const char **) malloc (
sizeof (
char *) * (argc + 2));
1967 for (i = 0; i <
argc; i++)
1969 args[i + 1] = argv[
i];
1971 args[argc + 1] =
NULL;
1991 if (process_window_service)
1993 #if defined(WINDOWS) 1998 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2017 if (process_window_service)
2019 #if defined(WINDOWS) 2024 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2043 const char *args[5];
2071 if (process_window_service)
2073 #if defined(WINDOWS) 2078 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2118 args = (
const char **) malloc (
sizeof (
char *) * (argc + 3));
2129 for (i = 0; i <
argc; i++)
2131 args[i + 2] = argv[
i];
2133 args[argc + 2] =
NULL;
2150 args = (
const char **) malloc (
sizeof (
char *) * (argc + 2));
2159 for (i = 0; i <
argc; i++)
2161 args[i + 1] = argv[
i];
2163 args[argc + 1] =
NULL;
2194 char buf[16], cmd[PATH_MAX];
2201 if (stat (cmd, &stbuf) == -1)
2207 strcat (cmd,
" getpid");
2208 input = popen (cmd,
"r");
2215 memset (buf,
'\0',
sizeof (buf));
2216 if (fgets (buf, 16, input) ==
NULL)
2245 int cub_manager, status =
NO_ERROR;
2246 char cub_manager_path[PATH_MAX];
2250 cub_manager_path[0] =
'\0';
2255 if (stat (cub_manager_path, &stbuf) == -1)
2269 switch (command_type)
2274 if (process_window_service)
2276 #if defined(WINDOWS) 2281 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2303 if (process_window_service)
2305 #if defined(WINDOWS) 2310 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2330 switch (manager_status)
2360 static const char PING_CMD[] =
" ping ";
2361 static const int PING_CMD_LEN =
sizeof (PING_CMD);
2364 char buf[PATH_MAX] = { 0 };
2365 char cmd[PATH_MAX + PING_CMD_LEN] = { 0 };
2369 strcat (cmd, PING_CMD);
2370 strcat (cmd, server_name);
2372 input = popen (cmd,
"r");
2378 memset (buf,
'\0',
sizeof (buf));
2379 if (fgets (buf, PATH_MAX, input) ==
NULL)
2385 if (strcmp (buf, server_name) == 0)
2390 else if (strcmp (buf,
"NO_CONNECTION") == 0)
2405 static const int wait_timeout = 30;
2406 int waited_secs = 0;
2420 if (process_window_service)
2422 #if defined(WINDOWS) 2426 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2436 while (status !=
NO_ERROR && waited_secs < wait_timeout)
2461 if (waited_secs > 3)
2479 static const int wait_timeout = 5;
2480 int waited_secs = 0;
2486 if (process_window_service)
2488 #if defined(WINDOWS) 2493 status =
proc_execute (UTIL_WIN_SERVICE_CONTROLLER_NAME, args,
true,
false,
false, NULL);
2506 while (status !=
NO_ERROR && waited_secs < wait_timeout);
2545 char buf[4096] = { 0 };
2547 const char *delim =
" ,:";
2555 strncpy (buf, us_Property_map[
SERVER_START_LIST].property_value,
sizeof (buf) - 1);
2560 strncpy (buf, argv[0],
sizeof (buf) - 1);
2571 for (list = buf;; list =
NULL)
2573 db_name = strtok_r (list, delim, &save);
2574 if (db_name ==
NULL)
2578 switch (command_type)
2606 return snprintf (path, size,
"%s/%s_%s", base, db, node) >= 0;
2612 return snprintf (db_host, size,
"%s@%s", db, host) >= 0;
2615 #if defined(WINDOWS) 2617 ha_mkdir (
const char *path,
int dummy)
2626 struct stat statbuf;
2628 if (stat (path, &statbuf) == 0 && S_ISDIR (statbuf.st_mode))
2634 if (stat (dir, &statbuf) == -1)
2636 if (errno == ENOENT &&
ha_mkdir (dir, mode))
2638 return mkdir (path, mode) == 0;
2645 else if (S_ISDIR (statbuf.st_mode))
2647 return mkdir (path, mode) == 0;
2657 return snprintf (mem_size, size,
"--max-mem-size=%d", value) >= 0;
2664 const char *commdb_argv[] = {
2680 commdb_argv[4] = hostname;
2681 commdb_argv[5] =
NULL;
2701 ret = snprintf (args, size,
"%s %s %s %s %s %s %s ",
2712 ret = snprintf (args, size,
"%s %s %s %s %s %s ",
2734 #if !defined(WINDOWS) 2737 const char *remote_host)
2741 int i, j, num_nodes;
2742 int num_db_found = 0, num_node_found = 0;
2744 char db_host[PATH_MAX], log_path[PATH_MAX];
2753 for (i = 0; dbs[
i] !=
NULL; i++)
2755 if (db_name !=
NULL && strcmp (dbs[i], db_name) != 0)
2773 for (j = 0; j < num_nodes; j++)
2775 if (node_name !=
NULL && strcmp (nc[j].node_name, node_name) != 0)
2780 if (remote_host ==
NULL)
2789 if (node_name !=
NULL && strcmp (node_name, remote_host) == 0)
2796 db_host[0] = log_path[0] =
'\0';
2798 (void)
ha_make_log_path (log_path, PATH_MAX, nc[j].copy_log_base, dbs[i], nc[j].node_name);
2799 if (db_host[0] !=
'\0' && log_path[0] !=
'\0')
2815 if (remote_host == NULL)
2845 const char *commdb_argv[] = {
2867 if (db_name !=
NULL && num_db_found == 0)
2875 if (node_name !=
NULL && num_node_found == 0)
2891 int i, j, num_nodes;
2892 int num_db_found = 0, num_node_found = 0;
2894 char db_host[PATH_MAX], log_path[PATH_MAX];
2904 for (i = 0; dbs[
i] !=
NULL; i++)
2906 if (db_name !=
NULL && strcmp (dbs[i], db_name) != 0)
2912 for (j = 0; j < num_nodes; j++)
2914 if (node_name !=
NULL && strcmp (nc[j].node_name, node_name) != 0)
2919 if (remote_host ==
NULL)
2928 if (node_name !=
NULL && strcmp (node_name, remote_host) == 0)
2935 db_host[0] = log_path[0] =
'\0';
2937 (void)
ha_make_log_path (log_path, PATH_MAX, nc[j].copy_log_base, dbs[i], nc[j].node_name);
2938 if (db_host[0] !=
'\0' && log_path[0] !=
'\0')
2941 const char *lw_argv[] = {
2961 if (remote_host != NULL)
2964 commdb_argv[4] = remote_host;
2965 commdb_argv[5] =
NULL;
2969 if (remote_host != NULL && status !=
NO_ERROR)
2997 if (db_name !=
NULL && num_db_found == 0)
3005 if (node_name !=
NULL && num_node_found == 0)
3019 const char *remote_host)
3023 int i, j, num_nodes;
3024 int num_db_found = 0, num_node_found = 0;
3026 char log_path[PATH_MAX], db_host[PATH_MAX], mem_size[PATH_MAX];
3035 for (i = 0; dbs[
i] !=
NULL; i++)
3037 if (db_name !=
NULL && strcmp (dbs[i], db_name) != 0)
3055 for (j = 0; j < num_nodes; j++)
3057 if (node_name !=
NULL && strcmp (nc[j].node_name, node_name) != 0)
3062 if (remote_host ==
NULL)
3071 if (node_name !=
NULL && strcmp (node_name, remote_host) == 0)
3079 log_path[0] = db_host[0] = mem_size[0] =
'\0';
3081 (void)
ha_make_log_path (log_path, PATH_MAX, nc[j].copy_log_base, dbs[i], nc[j].node_name);
3084 if (log_path[0] !=
'\0' && db_host[0] !=
'\0' && mem_size[0] !=
'\0')
3087 const char *la_argv[] = {
3089 "-L", log_path, mem_size, db_host,
NULL 3098 if (remote_host == NULL)
3119 const char *commdb_argv[] = {
3146 if (db_name !=
NULL && num_db_found == 0)
3154 if (node_name !=
NULL && num_node_found == 0)
3170 int i, j, num_nodes;
3171 int num_db_found = 0, num_node_found = 0;
3173 char log_path[PATH_MAX], db_host[PATH_MAX], mem_size[PATH_MAX];
3183 for (i = 0; dbs[
i] !=
NULL; i++)
3185 if (db_name !=
NULL && strcmp (dbs[i], db_name) != 0)
3191 for (j = 0; j < num_nodes; j++)
3193 if (node_name !=
NULL && strcmp (nc[j].node_name, node_name) != 0)
3198 if (remote_host ==
NULL)
3207 if (node_name !=
NULL && strcmp (node_name, remote_host) == 0)
3214 log_path[0] = db_host[0] = mem_size[0] =
'\0';
3216 (void)
ha_make_log_path (log_path, PATH_MAX, nc[j].copy_log_base, dbs[i], nc[j].node_name);
3219 if (log_path[0] !=
'\0' && db_host[0] !=
'\0' && mem_size[0] !=
'\0')
3222 const char *la_argv[] = {
3224 "-L", log_path, mem_size, db_host,
NULL 3241 if (remote_host != NULL)
3244 commdb_argv[4] = remote_host;
3245 commdb_argv[5] =
NULL;
3249 if (remote_host != NULL && status !=
NO_ERROR)
3277 if (db_name !=
NULL && num_db_found == 0)
3285 if (node_name !=
NULL && num_node_found == 0)
3297 #if defined (ENABLE_UNUSED_FUNCTION) 3333 int i, num_db_found = 0;
3337 for (i = 0; dbs[
i] !=
NULL; i++)
3339 if (db_name !=
NULL && strcmp (db_name, dbs[i]))
3377 if (db_name !=
NULL && num_db_found == 0)
3391 int i, num_db_found = 0;
3395 for (i = 0; dbs[
i] !=
NULL; i++)
3397 if (db_name !=
NULL && strcmp (db_name, dbs[i]))
3418 if (db_name !=
NULL && num_db_found == 0)
3464 if (check_result ==
true)
3466 for (i = 0; i <
da_size (pids); i++)
3500 const char *args[] = {
3504 if (hostname != NULL && hostname[0] !=
'\0')
3507 args[opt_idx++] = hostname;
3510 if (immediate_stop ==
true)
3527 if (status == EXIT_FAILURE)
3546 if (status == EXIT_FAILURE)
3584 const char *remote_host)
3593 switch (command_type)
3596 if (remote_host ==
NULL)
3608 for (i = 0; i <
da_size (pids); i++)
3631 for (i = 0; i <
da_size (args); i++)
3670 const char *remote_host)
3678 switch (command_type)
3681 if (remote_host ==
NULL)
3693 for (i = 0; i <
da_size (pids); i++)
3716 for (i = 0; i <
da_size (args); i++)
3751 #if defined (ENABLE_UNUSED_FUNCTION) 3753 us_hb_process_server (
int command_type,
HA_CONF * ha_conf,
const char *
db_name)
3757 switch (command_type)
3793 bool * immediate_stop,
int argc,
const char **
argv)
3799 const char **tmp_argv =
NULL;
3802 const struct option hb_stop_opts[] = {
3808 *db_name = *remote_host_name =
'\0';
3809 *immediate_stop =
false;
3812 tmp_argc = argc + 1;
3815 tmp_argv = (
const char **) malloc ((tmp_argc + 1) *
sizeof (
char *));
3816 if (tmp_argv ==
NULL)
3823 memset (tmp_argv, 0, (tmp_argc + 1) *
sizeof (
char *));
3826 memcpy (&tmp_argv[1], argv, argc *
sizeof (
char *));
3831 opt =
getopt_long (tmp_argc, (
char *
const *) tmp_argv, opt_str, hb_stop_opts, &opt_idx);
3840 copy_len = strnlen (
optarg, remote_host_name_size - 1);
3841 memcpy (remote_host_name,
optarg, copy_len);
3842 remote_host_name[copy_len] =
'\0';
3845 *immediate_stop =
true;
3857 if ((tmp_argc -
optind) > 1)
3866 if ((tmp_argc -
optind) == 1)
3868 copy_len = strnlen (tmp_argv[
optind], db_name_size);
3869 memcpy (db_name, tmp_argv[optind], copy_len);
3870 db_name[copy_len] =
'\0';
3902 const char **tmp_argv =
NULL;
3905 const struct option hb_status_opts[] = {
3906 {
"verbose", 0, 0,
'v'},
3912 *remote_host_name =
'\0';
3915 tmp_argc = argc + 1;
3918 tmp_argv = (
const char **) malloc ((tmp_argc + 1) *
sizeof (
char *));
3919 if (tmp_argv ==
NULL)
3926 memset (tmp_argv, 0, (tmp_argc + 1) *
sizeof (
char *));
3929 memcpy (&tmp_argv[1], argv, argc *
sizeof (
char *));
3934 opt =
getopt_long (tmp_argc, (
char *
const *) tmp_argv, opt_str, hb_status_opts, &opt_idx);
3946 copy_len = (int) strnlen (
optarg, (
size_t) (remote_host_name_size - 1));
3947 memcpy (remote_host_name,
optarg, copy_len);
3948 remote_host_name[copy_len] =
'\0';
3991 int remote_host_name_size,
int argc,
const char **
argv)
3997 const char **tmp_argv =
NULL;
4000 const struct option hb_util_opts[] = {
4011 *db_name = *node_name = *remote_host_name =
'\0';
4014 tmp_argc = argc + 1;
4017 tmp_argv = (
const char **) malloc ((tmp_argc + 1) *
sizeof (
char *));
4018 if (tmp_argv ==
NULL)
4025 memset (tmp_argv, 0, (tmp_argc + 1) *
sizeof (
char *));
4028 memcpy (&tmp_argv[1], argv, argc *
sizeof (
char *));
4033 opt =
getopt_long (tmp_argc, (
char *
const *) tmp_argv, opt_str, hb_util_opts, &opt_idx);
4042 copy_len = strnlen (
optarg, remote_host_name_size);
4043 memcpy (remote_host_name,
optarg, copy_len);
4044 remote_host_name[copy_len] =
'\0';
4056 if ((tmp_argc -
optind) > 2)
4063 else if ((tmp_argc -
optind) < 2)
4071 copy_len = strnlen (tmp_argv[
optind], db_name_size - 1);
4072 memcpy (db_name, tmp_argv[optind], copy_len);
4073 db_name[copy_len] =
'\0';
4075 copy_len = strnlen (tmp_argv[optind + 1], node_name_size - 1);
4076 memcpy (node_name, tmp_argv[optind + 1], copy_len);
4077 node_name[copy_len] =
'\0';
4090 #if !defined(WINDOWS) 4124 const char *args[] = {
4135 db_name = (argc >= 1) ? argv[0] :
NULL;
4136 if (db_name !=
NULL)
4157 if (db_name ==
NULL)
4189 bool immediate_stop =
false;
4194 us_hb_stop_get_options (db_name,
sizeof (db_name), remote_host_name,
sizeof (remote_host_name), &immediate_stop,
4202 if ((db_name[0] !=
'\0') && (remote_host_name[0] !=
'\0' || immediate_stop ==
true))
4213 if (db_name[0] !=
'\0')
4279 pid = (
char *) argv[0];
4293 const char *commdb_argv[] = {
4328 const char *node_list_argv[] = {
4333 const char *proc_list_argv[] = {
4338 const char *ping_host_list_argv[] = {
4343 const char *admin_info_argv[] = {
4352 memset (remote_host_name, 0,
sizeof (remote_host_name));
4361 if (remote_host_name[0] !=
'\0')
4365 ping_host_list_argv[ext_opt_offset] =
COMMDB_HOST;
4369 node_list_argv[ext_opt_offset] = remote_host_name;
4370 proc_list_argv[ext_opt_offset] = remote_host_name;
4371 ping_host_list_argv[ext_opt_offset] = remote_host_name;
4372 admin_info_argv[ext_opt_offset] = remote_host_name;
4386 if (verbose ==
true)
4410 if (verbose ==
true)
4438 const char *args[] = {
4454 #if !defined(WINDOWS) 4470 int sub_command_type;
4475 char *db_name_p, *node_name_p, *host_name_p;
4479 sub_command_type =
parse_arg (us_Command_map, (
char *) argv[0]);
4481 db_name[0] = node_name[0] = host_name[0] =
'\0';
4483 us_hb_util_get_options (db_name,
sizeof (db_name), node_name,
sizeof (node_name), host_name,
sizeof (host_name),
4484 (argc - 1), (argv + 1));
4490 db_name_p = (db_name[0] ==
'\0') ?
NULL : db_name;
4491 node_name_p = (node_name[0] ==
'\0') ?
NULL : node_name;
4492 host_name_p = (host_name[0] ==
'\0') ?
NULL : host_name;
4509 switch (command_type)
4538 int sub_command_type;
4552 sub_command_type =
parse_arg (us_Command_map, (
char *) argv[0]);
4553 node_name = argv[1];
4555 if ((sub_command_type !=
START && sub_command_type !=
STOP) || node_name ==
NULL || node_name[0] ==
'\0')
4566 const char *args[] = {
4572 if (sub_command_type ==
START)
4619 #if !defined(WINDOWS) 4630 memset ((
void *) &ha_conf, 0,
sizeof (
HA_CONF));
4640 switch (command_type)
4695 if (arg ==
NULL || arg[0] == 0)
4701 if (strcasecmp (option[i].option_name, arg) == 0)
4719 bool server_flag =
false;
4720 bool broker_flag =
false;
4721 bool manager_flag =
false;
4722 bool heartbeat_flag =
false;
4723 bool javasp_flag =
false;
4736 const char *error_msg;
4737 char *util =
NULL, *save_ptr =
NULL;
4738 for (util = value;; util =
NULL)
4740 util = strtok_r (util,
" \t,", &save_ptr);
4756 manager_flag =
true;
4760 heartbeat_flag =
true;
4769 fprintf (stderr, error_msg,
"service", util);
4813 if (us_Property_map[i].property_value !=
NULL)
4843 #if defined(WINDOWS) 4846 h_process = OpenProcess (PROCESS_QUERY_INFORMATION,
FALSE, pid);
4847 if (h_process ==
NULL)
4853 CloseHandle (h_process);
4857 if (kill (pid, 0) == -1)
#define PRINT_HA_PROCS_NAME
#define UTIL_OPTION_ALTERDBHOST
bool util_is_localhost(char *host)
const char * envvar_root(void)
#define UTIL_OPTION_VACUUMDB
#define PRINT_CMD_SERVICE
static UTIL_JAVASP_SERVER_STATUS_E is_javasp_running(const char *server_name)
#define UTIL_OPTION_CHANGEMODE
#define COMMAND_TYPE_STATUS
#define UTIL_CUB_MANAGER_NAME
#define COMMDB_HB_DEACT_IMMEDIATELY_S
static int us_hb_applylogdb_stop(HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
#define PRINT_CMD_APPLYLOGDB
#define COMMDB_HA_DEREG_BY_ARGS
#define COMMDB_HA_START_UTIL_PROCESS
#define COMMAND_TYPE_RESTART
#define UTIL_OPTION_LOADDB
#define COMMDB_HB_DEACT_IMMEDIATELY_L
#define COMMAND_TYPE_DEREG
#define PRINT_HEARTBEAT_NAME
static void print_result(const char *util_name, int status, int command_type)
#define COMMAND_TYPE_REPLICATION
int da_destroy(dynamic_array *da)
#define COMMAND_TYPE_REPLICATION_SHORT
static int us_hb_applylogdb_start(dynamic_array *out_ap, HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
#define UTIL_OPTION_KILLTRAN
static int process_heartbeat_replication(HA_CONF *ha_conf, int argc, const char **argv)
#define UTIL_OPTION_GENERATE_LOCALE
#define COMMDB_HA_DEACT_STOP_ALL
static int us_hb_copylogdb_stop(HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
static int process_heartbeat_start(HA_CONF *ha_conf, int argc, const char **argv)
static int us_hb_deactivate(const char *hostname, bool immediate_stop)
static int load_properties(void)
void rel_copy_version_string(char *buf, size_t len)
static void hide_cmd_line_args(char **args)
static int process_heartbeat_deregister(int argc, const char **argv)
int util_log_write_command(int argc, char *argv[])
static bool are_all_services_running(unsigned int sleep_time, bool check_win_service)
int envvar_set(const char *name, const char *val)
#define UTIL_OPTION_RESTOREDB
#define COMMDB_HA_PROC_LIST
static int process_heartbeat(int command_type, int argc, const char **argv)
static const char ** Argv
static bool ha_make_mem_size(char *mem_size, int size, int value)
#define UTIL_MONITOR_NAME
#define UTIL_OPTION_PATCHDB
int getopt_long(int, char *const *, const char *, const struct option *, int *)
#define HB_STOP_WAITING_TIME_IN_SECS
static UTIL_SERVICE_OPTION_MAP_T us_Command_map[]
#define UTIL_OPTION_COPYDB
#define UTIL_PID_ENVVAR_NAME
#define COMMAND_TYPE_LIST
#define COMMDB_SERVER_STATUS
#define UTIL_OPTION_BACKUPDB
#define COMMDB_HA_PING_HOST_LIST
#define UTIL_OPTION_DIAGDB
static void finalize_properties(void)
#define COMMDB_HB_DEACT_IMMEDIATELY
#define COMMDB_HA_DEACT_CONFIRM_STOP_ALL
static int process_heartbeat_util(HA_CONF *ha_conf, int command_type, int argc, const char **argv)
UTIL_JAVASP_SERVER_STATUS_E
void prm_set_integer_value(PARAM_ID prm_id, int value)
bool css_does_master_exist(int port_id)
#define COMMDB_HA_NODE_LIST
static int us_hb_server_start(HA_CONF *ha_conf, const char *db_name)
int util_log_write_errid(int message_id,...)
static int proc_execute_hide_cmd_args(const char *file, const char *args[], bool wait_child, bool close_output, bool close_err, int *pid)
#define UTIL_OPTION_STATDUMP
#define UTIL_OPTION_CHECKDB
#define COMMAND_TYPE_START
static int process_javasp_status(const char *db_name)
#define COMMDB_HA_ACTIVATE
#define UTIL_OPTION_OPTIMIZEDB
static int process_manager(int command_type, bool process_window_service)
static int us_hb_server_stop(HA_CONF *ha_conf, const char *db_name)
static int process_heartbeat_stop(HA_CONF *ha_conf, int argc, const char **argv)
#define UTIL_OPTION_PLANDUMP
int util_log_write_result(int error)
static int us_hb_process_start(HA_CONF *ha_conf, const char *db_name, bool check_result)
#define COMMAND_TYPE_INFO
#define REL_MAX_VERSION_LENGTH
#define UTIL_OPTION_CHECKSUMDB
#define PRINT_MANAGER_NAME
#define COMMDB_HA_ADMIN_INFO
static int process_javasp(int command_type, int argc, const char **argv, bool process_window_service)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
#define PRINT_MASTER_NAME
const char * property_value
#define COMMDB_ALL_STATUS
#define UTIL_OPTION_APPLYINFO
static int process_master(int command_type)
static int process_javasp_start(const char *db_name, bool process_window_service)
static void util_service_usage(int util_type)
static int us_hb_status_get_options(bool *verbose, char *remote_host_name, int remote_host_name_size, int argc, const char **argv)
#define UTIL_OPTION_LOCKDB
int prm_get_integer_value(PARAM_ID prm_id)
static bool check_all_services_status(unsigned int sleep_time, UTIL_ALL_SERVICES_STATUS expected_status, bool check_win_service)
int da_get(dynamic_array *da, int pos, void *data)
static int process_admin(int argc, char **argv)
#define COMMDB_VERBOSE_OUTPUT
#define UTIL_TYPE_SERVICE
#define ER_OUT_OF_VIRTUAL_MEMORY
#define COMMDB_HA_DEACTIVATE
#define HB_MAX_SZ_PROC_ARGS
static const char * command_string(int command_type)
#define COMMDB_SERVER_STOP
static int us_hb_process_copylogdb(int command_type, HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
static void print_message(FILE *output, int message_id,...)
static char executable_path[PATH_MAX]
#define COMMAND_TYPE_STOP
static int process_heartbeat_status(int argc, const char **argv)
static bool is_terminated_process(const int pid)
static int process_server(int command_type, int argc, char **argv, bool show_usage, bool check_ha_mode, bool process_window_service)
#define COMMDB_HA_DEREG_BY_PID
#define PRINT_CMD_MANAGER
const char * envvar_prefix(void)
static int us_hb_stop_get_options(char *db_name, int db_name_size, char *host_name, int host_name_size, bool *immediate_stop, int argc, const char **argv)
int sysprm_load_and_init(const char *db_name, const char *conf_file, const int load_flags)
int prm_get_master_port_id(void)
#define UTIL_TYPE_HB_SHORT
static enum scanner_mode mode
static int process_service(int command_type, bool process_window_service)
int da_size(dynamic_array *da)
#define UTIL_OPTION_RENAMEDB
static bool ha_concat_db_and_host(char *db_host, int size, const char *db, const char *host)
static void util_service_version(const char *argv0)
#define UTIL_OPTION_PARAMDUMP
#define COMMAND_TYPE_COPYLOGDB
#define UTIL_OPTION_SYNCCOLLDB
#define UTIL_TYPE_HEARTBEAT
char * envvar_bindir_file(char *path, size_t size, const char *filename)
int main(int argc, char *argv[])
#define UTIL_TYPE_MANAGER
int cub_dirname_r(const char *path, char *pathbuf, size_t buflen)
#define UTIL_OPTION_DELETEDB
dynamic_array * da_create(int count, size_t len)
void util_free_ha_conf(HA_CONF *ha_conf)
enum hb_proc_type HB_PROC_TYPE
static int process_javasp_stop(const char *db_name, bool process_window_service)
#define UTIL_OPTION_CREATEDB
char * utility_make_getopt_optstring(const GETOPT_LONG *opt_array, char *buf)
static int ha_argv_to_args(char *args, int size, const char **argv, HB_PROC_TYPE type)
#define COMMAND_TYPE_RELOAD
static bool are_all_services_stopped(unsigned int sleep_time, bool check_win_service)
static bool ha_is_registered(const char *args, const char *hostname)
#define PRINT_RESULT_SUCCESS
static int us_hb_copylogdb_start(dynamic_array *out_ap, HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
#define UTIL_OPTION_ACLDB
#define HB_START_WAITING_TIME_IN_SECS
static char * make_exec_abspath(char *buf, int buf_len, char *cmd)
static bool ha_mkdir(const char *path, mode_t mode)
const char * utility_get_generic_message(int message_index)
#define UTIL_OPTION_DUMP_LOCALE
#define UTIL_OPTION_DUMP_TZ
const char * envvar_get(const char *name)
#define UTIL_OPTION_INSTALLDB
#define COMMAND_TYPE_TEST
static void error(const char *msg)
#define PRINT_SERVER_NAME
#define UTIL_OPTION_COMPACTDB
#define UTIL_OPTION_UNLOADDB
static int us_hb_process_applylogdb(int command_type, HA_CONF *ha_conf, const char *db_name, const char *node_name, const char *remote_host)
#define PRINT_RESULT_FAIL
char * envvar_vardir_file(char *path, size_t size, const char *filename)
UTIL_MANAGER_SERVER_STATUS_E
int da_add(dynamic_array *da, void *data)
int css_windows_startup(void)
#define UTIL_OPTION_GEN_TZ
static int process_broker(int command_type, int argc, const char **argv, bool process_window_service)
#define free_and_init(ptr)
static bool is_server_running(const char *type, const char *server_name, int pid)
#define UTIL_OPTION_ESTIMATE_INDEX
char * prm_get_string_value(PARAM_ID prm_id)
#define PRINT_SERVICE_NAME
void css_windows_shutdown(void)
static bool ha_make_log_path(char *path, int size, char *base, char *db, char *node)
#define UTIL_OPTION_ESTIMATE_DATA
#define PRINT_CMD_REPLICATION
int util_log_write_errstr(const char *format,...)
char * basename(const char *path)
static int process_heartbeat_reload(int argc, const char **argv)
static bool check_server(const char *type, const char *server_name)
#define PRINT_CMD_COPYLOGDB
static int ha_mode_in_common
static int parse_arg(UTIL_SERVICE_OPTION_MAP_T *option, const char *arg)
char * strdup(const char *str)
#define UTIL_OPTION_RESTORESLAVE
int util_get_ha_mode_for_sa_utils(void)
#define COMMAND_TYPE_GETID
static int us_hb_process_stop(HA_CONF *ha_conf, const char *db_name)
#define US_HB_DEREG_WAIT_TIME_IN_SEC
static const char * get_property(int property_type)
#define COMMAND_TYPE_APPLYLOGDB
static UTIL_MANAGER_SERVER_STATUS_E is_manager_running(unsigned int sleep_time)
#define COMMDB_HA_DEACT_CONFIRM_NO_SERVER
static UTIL_SERVICE_PROPERTY_T us_Property_map[]
static int proc_execute(const char *file, const char *args[], bool wait_child, bool close_output, bool close_err, int *pid)
#define CUB_MAXHOSTNAMELEN
static int us_hb_util_get_options(char *db_name, int db_name_size, char *node_name, int node_name_size, char *remote_host_name, int remote_host_name_size, int argc, const char **argv)
static UTIL_SERVICE_OPTION_MAP_T us_Service_map[]
int util_make_ha_conf(HA_CONF *ha_conf)
static int util_get_command_option_mask(int command_type)
static int is_broker_running(void)
#define UTIL_OPTION_TRANLIST
#define UTIL_OPTION_SPACEDB
static int proc_execute_internal(const char *file, const char *args[], bool wait_child, bool close_output, bool close_err, bool hide_cmd_args, int *pid)
#define COMMAND_TYPE_RESET
static int util_get_service_option_mask(int util_type)
#define PRINT_JAVASP_NAME
#define UTIL_OPTION_ADDVOLDB
#define PRINT_BROKER_NAME