summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <miguel@hegel.local>2002-05-08 05:46:30 -0300
committerunknown <miguel@hegel.local>2002-05-08 05:46:30 -0300
commit2f379cef010275ff83531e3e0cbc5ed1cae1ff3d (patch)
treee9c69476eed5e4a97a2cc67982b7c4181189475f /sql
parentc46074f1cdcd29ab9661dbb18c39b1fde1be75e9 (diff)
downloadmariadb-git-2f379cef010275ff83531e3e0cbc5ed1cae1ff3d.tar.gz
Add several services for NT
Diffstat (limited to 'sql')
-rw-r--r--sql/mysqld.cc85
-rw-r--r--sql/nt_servc.cc30
-rw-r--r--sql/nt_servc.h2
3 files changed, 90 insertions, 27 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 91388197dc4..bdcef2f207f 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -421,6 +421,7 @@ enum db_type default_table_type=DB_TYPE_MYISAM;
#include <process.h>
#if !defined(EMBEDDED_LIBRARY)
HANDLE hEventShutdown;
+static char *event_name;
#include "nt_servc.h"
static NTService Service; // Service object for WinNT
#endif
@@ -2063,7 +2064,7 @@ The server will not act as a slave.");
(void) thr_setconcurrency(concurrency); // 10 by default
#if defined(__WIN__) && !defined(EMBEDDED_LIBRARY) //IRENA
{
- hEventShutdown=CreateEvent(0, FALSE, FALSE, "MySqlShutdown");
+ hEventShutdown=CreateEvent(0, FALSE, FALSE, event_name);
pthread_t hThread;
if (pthread_create(&hThread,&connection_attrib,handle_shutdown,0))
sql_print_error("Warning: Can't create thread to handle shutdown requests");
@@ -2198,46 +2199,70 @@ int mysql_service(void *p)
int main(int argc, char **argv)
{
- // check environment variable OS
- if (Service.GetOS()) // "OS" defined; Should be NT
+ if (Service.GetOS()) /* true NT family */
{
+ char file_path[FN_REFLEN];
+ my_path(file_path, argv[0], ""); /* Find name in path */
+ fn_format(file_path,argv[0],file_path,"",1+4+16); /* Force use of full path */
+
if (argc == 2)
+ {
+ if (Service.got_service_option(argv, "install"))
+ {
+ Service.Install(1, MYSQL_SERVICENAME, MYSQL_SERVICENAME, file_path);
+ return 0;
+ }
+ else if (Service.got_service_option(argv, "install-manual"))
+ {
+ Service.Install(0, MYSQL_SERVICENAME, MYSQL_SERVICENAME, file_path);
+ return 0;
+ }
+ else if (Service.got_service_option(argv, "remove"))
+ {
+ Service.Remove(MYSQL_SERVICENAME);
+ return 0;
+ }
+ else if (Service.IsService(argv[1]))
+ {
+ /* start an optional service */
+ load_default_groups[0]= argv[1];
+ event_name= argv[1];
+ start_mode= 1;
+ Service.Init(event_name, mysql_service );
+ return 0;
+ }
+ }
+ else if (argc == 3) /* install or remove any optional service */
{
- char path[FN_REFLEN];
- my_path(path, argv[0], ""); // Find name in path
- fn_format(path,argv[0],path,"",1+4+16); // Force use of full path
-
- if (!strcmp(argv[1],"-install") || !strcmp(argv[1],"--install"))
+ uint length=strlen(file_path);
+ file_path[sizeof(file_path)-1]=0;
+ strxnmov(file_path + length, sizeof(file_path)-2, " ", argv[2], NullS);
+ if (Service.got_service_option(argv, "install"))
{
- Service.Install(1,MYSQL_SERVICENAME,MYSQL_SERVICENAME,path);
- return 0;
+ Service.Install(1, argv[2], argv[2], file_path);
+ return 0;
}
- else if (!strcmp(argv[1],"-install-manual") || !strcmp(argv[1],"--install-manual"))
+ else if (Service.got_service_option(argv, "install-manual"))
{
- Service.Install(0,MYSQL_SERVICENAME,MYSQL_SERVICENAME,path);
- return 0;
+ Service.Install(0, argv[2], argv[2], file_path);
+ return 0;
}
- else if (!strcmp(argv[1],"-remove") || !strcmp(argv[1],"--remove"))
+ else if (Service.got_service_option(argv, "remove"))
{
- Service.Remove(MYSQL_SERVICENAME);
- return 0;
+ Service.Remove(argv[2]);
+ return 0;
}
}
- else if (argc == 1) // No arguments; start as a service
+ else if (argc == 1 && Service.IsService(MYSQL_SERVICENAME))
{
- // init service
- start_mode = 1;
- long tmp=Service.Init(MYSQL_SERVICENAME,mysql_service);
+ /* start the default service */
+ start_mode= 1;
+ event_name= "MySqlShutdown";
+ Service.Init(MYSQL_SERVICENAME, mysql_service);
return 0;
}
}
-
- /*
- This is a WIN95 machine or a start of mysqld as a standalone program
- we have to pass the arguments, in case of NT-service this will be done
- by ServiceMain()
- */
-
+ /* Start as standalone server */
Service.my_argc=argc;
Service.my_argv=argv;
mysql_service(NULL);
@@ -3825,9 +3850,15 @@ Starts the MySQL server\n");
printf("Usage: %s [OPTIONS]\n", my_progname);
#ifdef __WIN__
puts("NT and Win32 specific options:\n\
+ --console Don't remove the console window\n\
--install Install the default service (NT)\n\
--install-manual Install the default service started manually (NT)\n\
+ --install service_name Install an optional service (NT)\n\
+ --install-manual service_name Install an optional service started manually (NT)\n\
--remove Remove the default service from the service list (NT)\n\
+ --remove service_name Remove the service_name from the service list (NT)\n\
+ --enable-named-pipe Only to be used for the default server (NT)\n\
+ --standalone Dummy option to start as a standalone server (NT)\
");
puts("");
#endif
diff --git a/sql/nt_servc.cc b/sql/nt_servc.cc
index 8c705a94f55..be2ceb9cb7a 100644
--- a/sql/nt_servc.cc
+++ b/sql/nt_servc.cc
@@ -479,3 +479,33 @@ If this condition persist, reboot the machine and try again\n");
return ret_value;
}
+/* ------------------------------------------------------------------------
+ -------------------------------------------------------------------------- */
+BOOL NTService::IsService(LPCSTR ServiceName)
+{
+ BOOL ret_value=FALSE;
+ SC_HANDLE service, scm;
+
+ if (scm = OpenSCManager(0, 0,SC_MANAGER_ENUMERATE_SERVICE))
+ {
+ if ((service = OpenService(scm,ServiceName, SERVICE_ALL_ACCESS )))
+ {
+ ret_value=TRUE;
+ CloseServiceHandle(service);
+ }
+ CloseServiceHandle(scm);
+ }
+ return ret_value;
+}
+/* ------------------------------------------------------------------------
+ -------------------------------------------------------------------------- */
+BOOL NTService::got_service_option(char **argv, char *service_option)
+{
+ char *option = argv[1];
+
+ while (*option)
+ if (!strcmp(option++, service_option))
+ return TRUE;
+
+ return FALSE;
+}
diff --git a/sql/nt_servc.h b/sql/nt_servc.h
index 40d1a8c03fa..ab3238e0f41 100644
--- a/sql/nt_servc.h
+++ b/sql/nt_servc.h
@@ -52,6 +52,8 @@ class NTService
LPCSTR szAccountName=NULL,LPCSTR szPassword=NULL);
BOOL SeekStatus(LPCSTR szInternName, int OperationType);
BOOL Remove(LPCSTR szInternName);
+ BOOL IsService(LPCSTR ServiceName);
+ BOOL got_service_option(char **argv, char *service_option);
void Stop(void); //to be called from app. to stop service