summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager/options.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server-tools/instance-manager/options.cc')
-rw-r--r--server-tools/instance-manager/options.cc119
1 files changed, 98 insertions, 21 deletions
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index 34a9a0792e9..5d8483d3b0b 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -21,7 +21,7 @@
#include "options.h"
#include "priv.h"
-
+#include "port.h"
#include <my_sys.h>
#include <my_getopt.h>
#include <m_string.h>
@@ -30,15 +30,24 @@
#define QUOTE2(x) #x
#define QUOTE(x) QUOTE2(x)
+const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
+const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
+#ifdef __WIN__
+char windows_config_file[FN_REFLEN];
+
+char Options::install_as_service;
+char Options::remove_service;
+#else
char Options::run_as_service;
-const char *Options::log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
+const char *Options::user= 0; /* No default value */
+#endif
+const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
+const char *Options::log_file_name= default_log_file_name;
const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME);
const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
-const char *Options::password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
+const char *Options::password_file_name= default_password_file_name;
const char *Options::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH);
-const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
const char *Options::bind_address= 0; /* No default value */
-const char *Options::user= 0; /* No default value */
uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
uint Options::port_number= DEFAULT_PORT;
/* just to declare */
@@ -55,8 +64,13 @@ enum options {
OPT_SOCKET,
OPT_PASSWORD_FILE,
OPT_MYSQLD_PATH,
+#ifndef __WIN__
OPT_RUN_AS_SERVICE,
OPT_USER,
+#else
+ OPT_INSTALL_SERVICE,
+ OPT_REMOVE_SERVICE,
+#endif
OPT_MONITORING_INTERVAL,
OPT_PORT,
OPT_BIND_ADDRESS
@@ -97,28 +111,36 @@ static struct my_option my_long_options[] =
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "default-mysqld-path", OPT_MYSQLD_PATH, "Where to look for MySQL"
- " Server binary.",
- (gptr *) &Options::default_mysqld_path, (gptr *) &Options::default_mysqld_path,
+ " Server binary.",
+ (gptr *) &Options::default_mysqld_path,
+ (gptr *) &Options::default_mysqld_path,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
- { "monitoring-interval", OPT_MONITORING_INTERVAL, "Interval to monitor instances"
- " in seconds.",
- (gptr *) &Options::monitoring_interval,
- (gptr *) &Options::monitoring_interval,
- 0, GET_UINT, REQUIRED_ARG, DEFAULT_MONITORING_INTERVAL,
- 0, 0, 0, 0, 0 },
-
+ { "monitoring-interval", OPT_MONITORING_INTERVAL, "Interval to monitor"
+ " instances in seconds.",
+ (gptr *) &Options::monitoring_interval,
+ (gptr *) &Options::monitoring_interval,
+ 0, GET_UINT, REQUIRED_ARG, DEFAULT_MONITORING_INTERVAL,
+ 0, 0, 0, 0, 0 },
+#ifdef __WIN__
+ { "install", OPT_INSTALL_SERVICE, "Install as system service.",
+ (gptr *) &Options::install_as_service, (gptr*) &Options::install_as_service,
+ 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
+ { "remove", OPT_REMOVE_SERVICE, "Remove system service.",
+ (gptr *)&Options::remove_service, (gptr*) &Options::remove_service,
+ 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0},
+#else
{ "run-as-service", OPT_RUN_AS_SERVICE,
"Daemonize and start angel process.", (gptr *) &Options::run_as_service,
0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
{ "user", OPT_USER, "Username to start mysqlmanager",
- (gptr *) &Options::user,
- (gptr *) &Options::user,
- 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
-
+ (gptr *) &Options::user,
+ (gptr *) &Options::user,
+ 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+#endif
{ "version", 'V', "Output version information and exit.", 0, 0, 0,
- GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
+ GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }
};
@@ -233,12 +255,39 @@ int Options::load(int argc, char **argv)
{
/* the log is not enabled yet */
fprintf(stderr, "The --defaults-extra-file and --no-defaults options"
- " are not supported by\n"
- "Instance Manager. Program aborted.\n");
+ " are not supported by\n"
+ "Instance Manager. Program aborted.\n");
goto err;
}
}
+#ifdef __WIN__
+ setup_windows_defaults(*argv);
+
+ /*
+ On Windows, there are two possibilities. Either we are given
+ a defaults file on the command line or we use the my.ini file
+ that is in our app dir
+ */
+ if (Options::config_file == NULL)
+ {
+ char *filename;
+ static const char default_win_config_file_name[]= "\\my.ini";
+
+ if (!GetModuleFileName(NULL, windows_config_file,
+ sizeof(windows_config_file)))
+ goto err;
+
+ filename= strrchr(windows_config_file, "\\");
+ /*
+ Don't check for the overflow as strlen("\\my.ini") is less
+ then strlen("mysqlmanager") (the binary name)
+ */
+ strcpy(filename, default_win_config_file_name);
+ Options::config_file= windows_config_file;
+ }
+#endif
+
/* config-file options are prepended to command-line ones */
load_defaults(config_file, default_groups, &argc,
&saved_argv);
@@ -257,4 +306,32 @@ void Options::cleanup()
{
/* free_defaults returns nothing */
free_defaults(Options::saved_argv);
+#ifdef __WIN__
+ free((char*)default_password_file_name);
+#endif
}
+
+#ifdef __WIN__
+
+char* change_extension(const char *src, const char *newext)
+{
+ char *dot= (char*)strrchr(src, '.');
+ if (!dot) return (char*)src;
+
+ int newlen= dot-src+strlen(newext)+1;
+ char *temp= (char*)malloc(newlen);
+ bzero(temp, newlen);
+ strncpy(temp, src, dot-src+1);
+ strcat(temp, newext);
+ return temp;
+}
+
+void Options::setup_windows_defaults(const char *progname)
+{
+ Options::password_file_name= default_password_file_name=
+ change_extension(progname, "passwd");
+ Options::log_file_name= default_log_file_name=
+ change_extension(progname, "log");
+}
+
+#endif