mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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
This commit is contained in:
@ -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)
|
||||
|
@ -10,5 +10,5 @@ public:
|
||||
protected:
|
||||
void Log(const char *msg);
|
||||
void Stop();
|
||||
void Run();
|
||||
void Run(DWORD argc, LPTSTR *argv);
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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() {}
|
||||
|
@ -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= NULL;
|
||||
if (cmdlen > 0)
|
||||
char *cmdline= new char[cmdlen];
|
||||
if (cmdline == NULL)
|
||||
return 1;
|
||||
|
||||
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, "\"");
|
||||
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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,11 +133,11 @@ 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)
|
||||
{
|
||||
if (rc == -1 && errno != EINTR)
|
||||
log_error("Listener_thread::run(): select() failed, %s",
|
||||
strerror(errno));
|
||||
continue;
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user