summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager
diff options
context:
space:
mode:
authorunknown <reggie@ubuntu.(none)>2005-09-13 14:53:19 -0500
committerunknown <reggie@ubuntu.(none)>2005-09-13 14:53:19 -0500
commitc6dfe79beba3a4c03468d6e45aface45dfc38967 (patch)
tree9526667b98692215b3c525821064ff5229e93cd8 /server-tools/instance-manager
parent69b1940eefad9f9badbce78104a0fdc4780a05eb (diff)
downloadmariadb-git-c6dfe79beba3a4c03468d6e45aface45dfc38967.tar.gz
fixed the service bits of the IM
server-tools/instance-manager/IMService.cpp: * setting username and password to NULL so that the IM runs at LocalSystem (this should be changed soon) * implemented stop service by raising a sigterm * implemented start service by loading options and calling manager() server-tools/instance-manager/IMService.h: changed the sig for Run() server-tools/instance-manager/WindowsService.cpp: default debugging to false changed the sig of RuN() server-tools/instance-manager/WindowsService.h: change the sig of run() server-tools/instance-manager/instance.cc: * remove the inclusion of process.h * concat all args into a single buffer to pass to CreateProcess server-tools/instance-manager/instance_options.cc: quoting the binary to handle paths with quotes server-tools/instance-manager/listener.cc: use a timeval for select so that our select will only run for 100 msec before we check to see if we are shutting down server-tools/instance-manager/mysqlmanager.cc: if we are given the stand alone option, then run the manager as standalone server-tools/instance-manager/options.cc: Added stand alone command line arg server-tools/instance-manager/options.h: Added stand alone command line arg
Diffstat (limited to 'server-tools/instance-manager')
-rw-r--r--server-tools/instance-manager/IMService.cpp13
-rw-r--r--server-tools/instance-manager/IMService.h2
-rw-r--r--server-tools/instance-manager/WindowsService.cpp5
-rw-r--r--server-tools/instance-manager/WindowsService.h2
-rw-r--r--server-tools/instance-manager/instance.cc28
-rw-r--r--server-tools/instance-manager/instance_options.cc8
-rw-r--r--server-tools/instance-manager/listener.cc13
-rw-r--r--server-tools/instance-manager/mysqlmanager.cc10
-rw-r--r--server-tools/instance-manager/options.cc5
-rw-r--r--server-tools/instance-manager/options.h3
10 files changed, 58 insertions, 31 deletions
diff --git a/server-tools/instance-manager/IMService.cpp b/server-tools/instance-manager/IMService.cpp
index e040a5da8c2..b7ea8e7eb81 100644
--- a/server-tools/instance-manager/IMService.cpp
+++ b/server-tools/instance-manager/IMService.cpp
@@ -1,12 +1,16 @@
#include <windows.h>
+#include <signal.h>
#include "log.h"
#include "options.h"
#include "IMService.h"
+#include "manager.h"
IMService::IMService(void)
{
serviceName= "MySqlManager";
displayName= "MySQL Manager";
+ username= NULL;
+ password= NULL;
}
IMService::~IMService(void)
@@ -16,18 +20,25 @@ IMService::~IMService(void)
void IMService::Stop()
{
ReportStatus(SERVICE_STOP_PENDING);
+
// stop the IM work
+ raise(SIGTERM);
}
-void IMService::Run()
+void IMService::Run(DWORD argc, LPTSTR *argv)
{
// report to the SCM that we're about to start
ReportStatus((DWORD)SERVICE_START_PENDING);
+ Options o;
+ o.load(argc, argv);
+
// init goes here
ReportStatus((DWORD)SERVICE_RUNNING);
// wait for main loop to terminate
+ manager(o);
+ o.cleanup();
}
void IMService::Log(const char *msg)
diff --git a/server-tools/instance-manager/IMService.h b/server-tools/instance-manager/IMService.h
index 60c202fc561..cad38bebdaf 100644
--- a/server-tools/instance-manager/IMService.h
+++ b/server-tools/instance-manager/IMService.h
@@ -10,5 +10,5 @@ public:
protected:
void Log(const char *msg);
void Stop();
- void Run();
+ void Run(DWORD argc, LPTSTR *argv);
};
diff --git a/server-tools/instance-manager/WindowsService.cpp b/server-tools/instance-manager/WindowsService.cpp
index fb7e00e0d9b..192045b7a4c 100644
--- a/server-tools/instance-manager/WindowsService.cpp
+++ b/server-tools/instance-manager/WindowsService.cpp
@@ -8,7 +8,8 @@ WindowsService::WindowsService(void) :
statusCheckpoint(0),
serviceName(NULL),
inited(false),
- dwAcceptedControls(SERVICE_ACCEPT_STOP)
+ dwAcceptedControls(SERVICE_ACCEPT_STOP),
+ debugging(false)
{
gService= this;
status.dwServiceType= SERVICE_WIN32_OWN_PROCESS;
@@ -148,7 +149,7 @@ void WindowsService::RegisterAndRun(DWORD argc, LPTSTR *argv)
{
statusHandle= ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
if (statusHandle && ReportStatus(SERVICE_START_PENDING))
- Run();
+ Run(argc, argv);
ReportStatus(SERVICE_STOPPED);
}
diff --git a/server-tools/instance-manager/WindowsService.h b/server-tools/instance-manager/WindowsService.h
index 612eeda21e9..1a034ce1351 100644
--- a/server-tools/instance-manager/WindowsService.h
+++ b/server-tools/instance-manager/WindowsService.h
@@ -30,7 +30,7 @@ public:
static void WINAPI ControlHandler(DWORD CtrlType);
protected:
- virtual void Run()= 0;
+ virtual void Run(DWORD argc, LPTSTR *argv)= 0;
virtual void Stop() {}
virtual void Shutdown() {}
virtual void Pause() {}
diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc
index 7f705bac1c1..5e1c3d2ea9f 100644
--- a/server-tools/instance-manager/instance.cc
+++ b/server-tools/instance-manager/instance.cc
@@ -18,9 +18,6 @@
#pragma implementation
#endif
-#ifdef __WIN__
-#include <process.h>
-#endif
#include "instance.h"
#include "mysql_manager_error.h"
@@ -171,25 +168,24 @@ static int start_process(Instance_options *instance_options,
ZeroMemory(pi, sizeof(PROCESS_INFORMATION));
int cmdlen= 0;
- for (int i= 1; instance_options->argv[i] != 0; i++)
- cmdlen+= strlen(instance_options->argv[i]) + 1;
- cmdlen++; /* we have to add a single space for CreateProcess (see docs) */
+ for (int i= 0; instance_options->argv[i] != 0; i++)
+ cmdlen+= strlen(instance_options->argv[i]) + 3;
+ cmdlen++; /* make room for the null */
+
+ char *cmdline= new char[cmdlen];
+ if (cmdline == NULL)
+ return 1;
- char *cmdline= NULL;
- if (cmdlen > 0)
+ for (int i= 0; instance_options->argv[i] != 0; i++)
{
- cmdline= new char[cmdlen];
- cmdline[0]= 0;
- for (int i= 1; instance_options->argv[i] != 0; i++)
- {
- strcat(cmdline, " ");
- strcat(cmdline, instance_options->argv[i]);
- }
+ strcat(cmdline, "\"");
+ strcat(cmdline, instance_options->argv[i]);
+ strcat(cmdline, "\" ");
}
/* Start the child process */
BOOL result=
- CreateProcess(instance_options->mysqld_path, /* File to execute */
+ CreateProcess(NULL, /* Put it all in cmdline */
cmdline, /* Command line */
NULL, /* Process handle not inheritable */
NULL, /* Thread handle not inheritable */
diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc
index 124195aad37..70950a91015 100644
--- a/server-tools/instance-manager/instance_options.cc
+++ b/server-tools/instance-manager/instance_options.cc
@@ -46,8 +46,16 @@ static inline int create_mysqld_command(Buffer *buf,
if (buf->get_size()) /* malloc succeeded */
{
+#ifdef __WIN__
+ buf->append(position, "\"", 1);
+ position++;
+#endif
buf->append(position, mysqld_path_str, mysqld_path_len);
position+= mysqld_path_len;
+#ifdef __WIN__
+ buf->append(position, "\"", 1);
+ position++;
+#endif
/* here the '\0' character is copied from the option string */
buf->append(position, option, option_len);
diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc
index 790770be09e..374946d3b73 100644
--- a/server-tools/instance-manager/listener.cc
+++ b/server-tools/instance-manager/listener.cc
@@ -121,6 +121,9 @@ void Listener_thread::run()
n= max(n, sockets[i]);
n++;
+ timeval tv;
+ tv.tv_sec= 0;
+ tv.tv_usec= 100000;
while (!thread_registry.is_shutdown())
{
fd_set read_fds_arg= read_fds;
@@ -130,13 +133,13 @@ void Listener_thread::run()
signal during shutdown. This results in failing assert
(Thread_registry::~Thread_registry). Valgrind 2.2 works fine.
*/
- int rc= select(n, &read_fds_arg, 0, 0, 0);
+ int rc= select(n, &read_fds_arg, 0, 0, &tv);
-
- if (rc == -1 && errno != EINTR)
+ if (rc == 0 || rc == -1)
{
- log_error("Listener_thread::run(): select() failed, %s",
- strerror(errno));
+ if (rc == -1 && errno != EINTR)
+ log_error("Listener_thread::run(): select() failed, %s",
+ strerror(errno));
continue;
}
diff --git a/server-tools/instance-manager/mysqlmanager.cc b/server-tools/instance-manager/mysqlmanager.cc
index a1420a639cb..3d2907f4776 100644
--- a/server-tools/instance-manager/mysqlmanager.cc
+++ b/server-tools/instance-manager/mysqlmanager.cc
@@ -102,10 +102,12 @@ int main(int argc, char *argv[])
angel(options);
}
#else
-#ifdef NDEBUG
- return_value= HandleServiceOptions(options);
- goto err; /* this is not always an error but we reuse the label */
-#endif
+ if (!options.stand_alone)
+ {
+ if (HandleServiceOptions(options))
+ goto err;
+ }
+ else
#endif
manager(options);
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index 36fe0a89dda..74ccade3a2c 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -33,6 +33,7 @@
#ifdef __WIN__
char Options::install_as_service;
char Options::remove_service;
+char Options::stand_alone;
char windows_config_file[FN_REFLEN];
char default_password_file_name[FN_REFLEN];
char default_log_file_name[FN_REFLEN];
@@ -72,6 +73,7 @@ enum options {
#else
OPT_INSTALL_SERVICE,
OPT_REMOVE_SERVICE,
+ OPT_STAND_ALONE,
#endif
OPT_MONITORING_INTERVAL,
OPT_PORT,
@@ -131,6 +133,9 @@ static struct my_option my_long_options[] =
{ "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},
+ { "standalone", OPT_STAND_ALONE, "Run the application in stand alone mode.",
+ (gptr *)&Options::stand_alone, (gptr*) &Options::stand_alone,
+ 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,
diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h
index 5cc14e7ee7f..a5cd049decf 100644
--- a/server-tools/instance-manager/options.h
+++ b/server-tools/instance-manager/options.h
@@ -31,6 +31,7 @@ struct Options
#ifdef __WIN__
static char install_as_service;
static char remove_service;
+ static char stand_alone;
#else
static char run_as_service; /* handle_options doesn't support bool */
static const char *user;
@@ -52,7 +53,7 @@ struct Options
int load(int argc, char **argv);
void cleanup();
#ifdef __WIN__
- int setup_windows_defaults(const char *progname);
+ int setup_windows_defaults();
#endif
};