From 7ff2a5a54371568a414dfbd77082427186d6a83c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 May 2005 16:50:20 +0200 Subject: Removing mysqlshutdown and mysqlwatch from the Windows packages, removing their sources. They were both undocumented and not much useful. Removal has been agreed with Mark, Miguel and MikeZ. Removing winmysqladmin from the source (it was not included anymore in no Windows package). I'll do a test Windows noinstall.zip build before push. MikeZ just removed mysqlshutdown and mysqlwatch from the installer scripts. BitKeeper/deleted/.del-myshutdown.dsp~a8eee34a3d3ab679: Delete: VC++Files/mysqlshutdown/myshutdown.dsp BitKeeper/deleted/.del-myshutdown_ia64.dsp~dd2ad23d744ba1ba: Delete: VC++Files/mysqlshutdown/myshutdown_ia64.dsp BitKeeper/deleted/.del-mysql.ico~d4c55da4e911ced7: Delete: VC++Files/mysqlshutdown/mysql.ico BitKeeper/deleted/.del-mysqlshutdown.c~35d5feec4507d810: Delete: VC++Files/mysqlshutdown/mysqlshutdown.c BitKeeper/deleted/.del-mysqlshutdown.dsp~27db1e088d39987c: Delete: VC++Files/mysqlshutdown/mysqlshutdown.dsp BitKeeper/deleted/.del-mysqlshutdown.rc~454359c66381843c: Delete: VC++Files/mysqlshutdown/mysqlshutdown.rc BitKeeper/deleted/.del-mysqlshutdown_ia64.dsp~53fe7127af678bc: Delete: VC++Files/mysqlshutdown/mysqlshutdown_ia64.dsp BitKeeper/deleted/.del-mysqlwatch.c~de504821ede1cb8: Delete: VC++Files/mysqlwatch/mysqlwatch.c BitKeeper/deleted/.del-mysqlwatch.dsp~4699ddfb6ed23a6d: Delete: VC++Files/mysqlwatch/mysqlwatch.dsp BitKeeper/deleted/.del-mysqlwatch_ia64.dsp~1a11ce58f66a493: Delete: VC++Files/mysqlwatch/mysqlwatch_ia64.dsp BitKeeper/deleted/.del-db.cpp~6bbc3687ff8a2913: Delete: VC++Files/winmysqladmin/db.cpp BitKeeper/deleted/.del-db.h~e38deaf45dffa24d: Delete: VC++Files/winmysqladmin/db.h BitKeeper/deleted/.del-initsetup.cpp~b988f9ab7dbe4e92: Delete: VC++Files/winmysqladmin/initsetup.cpp BitKeeper/deleted/.del-initsetup.h~bc2a39769765e1a5: Delete: VC++Files/winmysqladmin/initsetup.h BitKeeper/deleted/.del-main.cpp~f822deb513ce0250: Delete: VC++Files/winmysqladmin/main.cpp BitKeeper/deleted/.del-Goahead.ico~805e753b7f13c6b7: Delete: VC++Files/winmysqladmin/images/Goahead.ico BitKeeper/deleted/.del-main.h~d17e73cf0b0cbf8: Delete: VC++Files/winmysqladmin/main.h BitKeeper/deleted/.del-mysql.h~a538c356e526804b: Delete: VC++Files/winmysqladmin/mysql.h BitKeeper/deleted/.del-mysql_com.h~8828acc269ca5036: Delete: VC++Files/winmysqladmin/mysql_com.h BitKeeper/deleted/.del-mysql_version.h~674dd1127ee25880: Delete: VC++Files/winmysqladmin/mysql_version.h BitKeeper/deleted/.del-winmysqladmin.cpp~bfac61f49813a983: Delete: VC++Files/winmysqladmin/winmysqladmin.cpp BitKeeper/deleted/.del-HELP.ICO~6b91d6eff4a7b11e: Delete: VC++Files/winmysqladmin/images/HELP.ICO BitKeeper/deleted/.del-INFO.ICO~b1eb08e87e0c1c3e: Delete: VC++Files/winmysqladmin/images/INFO.ICO BitKeeper/deleted/.del-Info.bmp~9c3c5afea29fa9b7: Delete: VC++Files/winmysqladmin/images/Info.bmp BitKeeper/deleted/.del-MYINI.ICO~91c77cc71d665f4: Delete: VC++Files/winmysqladmin/images/MYINI.ICO BitKeeper/deleted/.del-Myini.bmp~6cea36edbb94df3a: Delete: VC++Files/winmysqladmin/images/Myini.bmp BitKeeper/deleted/.del-Noentry.ico~6791fac163575069: Delete: VC++Files/winmysqladmin/images/Noentry.ico BitKeeper/deleted/.del-SETUP.BMP~43bd1e614fc7e5d5: Delete: VC++Files/winmysqladmin/images/SETUP.BMP BitKeeper/deleted/.del-Setup 16.bmp~9a9bf24a5dd952f3: Delete: VC++Files/winmysqladmin/images/Setup 16.bmp BitKeeper/deleted/.del-Table.ico~d64bf78e407b5e50: Delete: VC++Files/winmysqladmin/images/Table.ico BitKeeper/deleted/.del-Working.ico~f5cf304a7b6e592c: Delete: VC++Files/winmysqladmin/images/Working.ico BitKeeper/deleted/.del-database.ico~df8562312d9d9ed8: Delete: VC++Files/winmysqladmin/images/database.ico BitKeeper/deleted/.del-find.ico~44644ca5bab7901e: Delete: VC++Files/winmysqladmin/images/find.ico BitKeeper/deleted/.del-green.ico~88749a9a4ff83d25: Delete: VC++Files/winmysqladmin/images/green.ico BitKeeper/deleted/.del-help.bmp~bb6ac08cf7ab60d7: Delete: VC++Files/winmysqladmin/images/help.bmp BitKeeper/deleted/.del-initsetup.cpp~6704e992d966647f: Delete: VC++Files/winmysqladmin/images/initsetup.cpp BitKeeper/deleted/.del-killdb.ico~1043773bac9da67c: Delete: VC++Files/winmysqladmin/images/killdb.ico BitKeeper/deleted/.del-logo.ico~f00b08cd64695232: Delete: VC++Files/winmysqladmin/images/logo.ico BitKeeper/deleted/.del-multitrg.ico~52f787d7d9509533: Delete: VC++Files/winmysqladmin/images/multitrg.ico BitKeeper/deleted/.del-mysql-07.bmp~c157a2c3573b5c27: Delete: VC++Files/winmysqladmin/images/mysql-07.bmp BitKeeper/deleted/.del-mysql-17.bmp~99b3c90f96a9964b: Delete: VC++Files/winmysqladmin/images/mysql-17.bmp BitKeeper/deleted/.del-mysql.BMP~b58fe4f0c416291: Delete: VC++Files/winmysqladmin/images/mysql.BMP BitKeeper/deleted/.del-red.ico~179f5587e5a706c9: Delete: VC++Files/winmysqladmin/images/red.ico BitKeeper/deleted/.del-red22.BMP~bc47efefee4a5a86: Delete: VC++Files/winmysqladmin/images/red22.BMP BitKeeper/deleted/.del-see.bmp~c6863c3564387841: Delete: VC++Files/winmysqladmin/images/see.bmp VC++Files/mysql.dsw: removing mysqlshutdown and mysqlwatch VC++Files/mysql_ia64.dsw: removing mysqlshutdown and mysqlwatch --- VC++Files/mysqlwatch/mysqlwatch.c | 745 -------------------------------------- 1 file changed, 745 deletions(-) delete mode 100644 VC++Files/mysqlwatch/mysqlwatch.c (limited to 'VC++Files/mysqlwatch/mysqlwatch.c') diff --git a/VC++Files/mysqlwatch/mysqlwatch.c b/VC++Files/mysqlwatch/mysqlwatch.c deleted file mode 100644 index 2a1f62b4394..00000000000 --- a/VC++Files/mysqlwatch/mysqlwatch.c +++ /dev/null @@ -1,745 +0,0 @@ -/**************************************************************************** - MySqlWatch - WinNT service program MySQL - - Re-start MySql server in case of failure -*****************************************************************************/ -#include -#include -#include -#include -#include - - -// name of the executable -#define SZAPPNAME "mysqlwatch" -// internal name of the service -#define SZSERVICENAME "MySqlWatch" -// displayed name of the service -#define SZSERVICEDISPLAYNAME "MySqlWatch" -// list of service dependencies - "dep1\0dep2\0\0" -#define SZDEPENDENCIES "" - - - -VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv); -VOID ServiceStop(void); -BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint); -void AddToMessageLog(LPTSTR lpszMsg); - -// internal variables -SERVICE_STATUS ssStatus; // current status of the service -SERVICE_STATUS_HANDLE sshStatusHandle; -DWORD dwErr = 0; -BOOL bDebug = FALSE; -TCHAR szErr[256]; - -// internal function prototypes -void WINAPI service_ctrl(DWORD dwCtrlCode); -void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv); -void CmdInstallService(void); -void CmdRemoveService(void); -void CmdDebugService(int argc, char **argv); -BOOL WINAPI ControlHandler ( DWORD dwCtrlType ); -LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); - -// -// FUNCTION: main -// -// PURPOSE: entrypoint for service -// -// PARAMETERS: -// argc - number of command line arguments -// argv - array of command line arguments -// -// RETURN VALUE: -// none -// -// COMMENTS: -// main() either performs the command line task, or -// call StartServiceCtrlDispatcher to register the -// main service thread. When the this call returns, -// the service has stopped, so exit. -// -void main(int argc, char **argv) -{ - SERVICE_TABLE_ENTRY dispatchTable[] = - { - { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main }, - { NULL, NULL } - }; - - if ( (argc > 1) && - ((*argv[1] == '-') || (*argv[1] == '/')) ) - { - if ( stricmp( "install", argv[1]+1 ) == 0 ) - { - CmdInstallService(); - } - else if ( stricmp( "remove", argv[1]+1 ) == 0 ) - { - CmdRemoveService(); - } - else if ( stricmp( "debug", argv[1]+1 ) == 0 ) - { - bDebug = TRUE; - CmdDebugService(argc, argv); - } - else - { - goto dispatch; - } - exit(0); - } - - // if it doesn't match any of the above parameters - // the service control manager may be starting the service - // so we must call StartServiceCtrlDispatcher - dispatch: - // this is just to be friendly - printf( "%s -install to install the service\n", SZAPPNAME ); - printf( "%s -remove to remove the service\n", SZAPPNAME ); - printf( "%s -debug to run as a console app for debugging\n", SZAPPNAME ); - printf( "\nStartServiceCtrlDispatcher being called.\n" ); - printf( "This may take several seconds. Please wait.\n" ); - - if (!StartServiceCtrlDispatcher(dispatchTable)) - AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed.")); -} - - - -// -// FUNCTION: service_main -// -// PURPOSE: To perform actual initialization of the service -// -// PARAMETERS: -// dwArgc - number of command line arguments -// lpszArgv - array of command line arguments -// -// RETURN VALUE: -// none -// -// COMMENTS: -// This routine performs the service initialization and then calls -// the user defined ServiceStart() routine to perform majority -// of the work. -// -void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv) -{ - - // register our service control handler: - // - sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl); - - if (!sshStatusHandle) - goto cleanup; - - // SERVICE_STATUS members that don't change in example - // - ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - ssStatus.dwServiceSpecificExitCode = 0; - - - // report the status to the service control manager. - // - if (!ReportStatusToSCMgr( - SERVICE_START_PENDING, // service state - NO_ERROR, // exit code - 3000)) // wait hint - goto cleanup; - - - ServiceStart( dwArgc, lpszArgv ); - -cleanup: - - // try to report the stopped status to the service control manager. - // - if (sshStatusHandle) - ReportStatusToSCMgr( - SERVICE_STOPPED, - dwErr, - 0); - - return; -} - - - -// -// FUNCTION: service_ctrl -// -// PURPOSE: This function is called by the SCM whenever -// ControlService() is called on this service. -// -// PARAMETERS: -// dwCtrlCode - type of control requested -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void WINAPI service_ctrl(DWORD dwCtrlCode) -{ - // Handle the requested control code. - // - switch(dwCtrlCode) - { - // Stop the service. - // - case SERVICE_CONTROL_STOP: - ssStatus.dwCurrentState = SERVICE_STOP_PENDING; - ServiceStop(); - break; - - // Update the service status. - // - case SERVICE_CONTROL_INTERROGATE: - break; - - // invalid control code - // - default: - break; - - } - - ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0); - -} - - - -// -// FUNCTION: ReportStatusToSCMgr() -// -// PURPOSE: Sets the current status of the service and -// reports it to the Service Control Manager -// -// PARAMETERS: -// dwCurrentState - the state of the service -// dwWin32ExitCode - error code to report -// dwWaitHint - worst case estimate to next checkpoint -// -// RETURN VALUE: -// TRUE - success -// FALSE - failure -// -// COMMENTS: -// -BOOL ReportStatusToSCMgr(DWORD dwCurrentState, - DWORD dwWin32ExitCode, - DWORD dwWaitHint) -{ - static DWORD dwCheckPoint = 1; - BOOL fResult = TRUE; - - - if ( !bDebug ) // when debugging we don't report to the SCM - { - if (dwCurrentState == SERVICE_START_PENDING) - ssStatus.dwControlsAccepted = 0; - else - ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; - - ssStatus.dwCurrentState = dwCurrentState; - ssStatus.dwWin32ExitCode = dwWin32ExitCode; - ssStatus.dwWaitHint = dwWaitHint; - - if ( ( dwCurrentState == SERVICE_RUNNING ) || - ( dwCurrentState == SERVICE_STOPPED ) ) - ssStatus.dwCheckPoint = 0; - else - ssStatus.dwCheckPoint = dwCheckPoint++; - - - // Report the status of the service to the service control manager. - // - if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) { - AddToMessageLog(TEXT("SetServiceStatus")); - } - } - return fResult; -} - - - -// -// FUNCTION: AddToMessageLog(LPTSTR lpszMsg) -// -// PURPOSE: Allows any thread to log an error message -// -// PARAMETERS: -// lpszMsg - text for message -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void AddToMessageLog(LPTSTR lpszMsg) -{ - TCHAR szMsg[256]; - HANDLE hEventSource; - LPTSTR lpszStrings[2]; - - - if ( !bDebug ) - { - dwErr = GetLastError(); - - // Use event logging to log the error. - // - hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); - - _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr); - lpszStrings[0] = szMsg; - lpszStrings[1] = lpszMsg; - - if (hEventSource != NULL) { - ReportEvent(hEventSource, // handle of event source - EVENTLOG_ERROR_TYPE, // event type - 0, // event category - 0, // event ID - NULL, // current user's SID - 2, // strings in lpszStrings - 0, // no bytes of raw data - lpszStrings, // array of error strings - NULL); // no raw data - - DeregisterEventSource(hEventSource); - } - } -} - - - - -/////////////////////////////////////////////////////////////////// -// -// The following code handles service installation and removal -// - - -// -// FUNCTION: CmdInstallService() -// -// PURPOSE: Installs the service -// -// PARAMETERS: -// none -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void CmdInstallService() -{ - SC_HANDLE schService; - SC_HANDLE schSCManager; - - TCHAR szPath[512]; - - if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) - { - _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); - return; - } - - schSCManager = OpenSCManager( - NULL, // machine (NULL == local) - NULL, // database (NULL == default) - SC_MANAGER_ALL_ACCESS // access required - ); - if ( schSCManager ) - { - schService = CreateService( - schSCManager, // SCManager database - TEXT(SZSERVICENAME), // name of service - TEXT(SZSERVICEDISPLAYNAME), // name to display - SERVICE_ALL_ACCESS, // desired access - SERVICE_WIN32_OWN_PROCESS, // service type - SERVICE_DEMAND_START, // start type - SERVICE_ERROR_NORMAL, // error control type - szPath, // service's binary - NULL, // no load ordering group - NULL, // no tag identifier - TEXT(SZDEPENDENCIES), // dependencies - NULL, // LocalSystem account - NULL); // no password - - if ( schService ) - { - _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); - CloseServiceHandle(schService); - } - else - { - _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); - } - - CloseServiceHandle(schSCManager); - } - else - _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); -} - - - -// -// FUNCTION: CmdRemoveService() -// -// PURPOSE: Stops and removes the service -// -// PARAMETERS: -// none -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void CmdRemoveService() -{ - SC_HANDLE schService; - SC_HANDLE schSCManager; - - schSCManager = OpenSCManager( - NULL, // machine (NULL == local) - NULL, // database (NULL == default) - SC_MANAGER_ALL_ACCESS // access required - ); - if ( schSCManager ) - { - schService = OpenService(schSCManager, TEXT(SZSERVICENAME), SERVICE_ALL_ACCESS); - - if (schService) - { - // try to stop the service - if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) ) - { - _tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME)); - Sleep( 1000 ); - - while( QueryServiceStatus( schService, &ssStatus ) ) - { - if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING ) - { - _tprintf(TEXT(".")); - Sleep( 1000 ); - } - else - break; - } - - if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) - _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) ); - else - _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) ); - - } - - // now remove the service - if( DeleteService(schService) ) - _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); - else - _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256)); - - - CloseServiceHandle(schService); - } - else - _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); - - CloseServiceHandle(schSCManager); - } - else - _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); -} - - - - - -// -// FUNCTION: CmdRestartService() -// -// PURPOSE: Stops and removes the service -// -// PARAMETERS: -// none -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void CmdRestartService(char *szServiceName) -{ - SC_HANDLE schService; - SC_HANDLE schSCManager; - - schSCManager = OpenSCManager( - NULL, // machine (NULL == local) - NULL, // database (NULL == default) - SC_MANAGER_ALL_ACCESS // access required - ); - if ( schSCManager ) - { - schService = OpenService(schSCManager, TEXT(szServiceName), SERVICE_ALL_ACCESS); - if (schService) - { - if(! ControlService( schService, SERVICE_CONTROL_INTERROGATE, &ssStatus ) ) - //if(QueryServiceStatus( schService, &ssStatus )==0) - { - if(GetLastError()==ERROR_SERVICE_NOT_ACTIVE) - { - - //AddToMessageLog(TEXT("Start service...")); - StartService( schService, 0,NULL); - } - else - { ; - //AddToMessageLog(TEXT("QueryService...")); - //AddToMessageLog(TEXT(GetLastErrorText(szErr,256))); - } - } - CloseServiceHandle(schService); - } - else - { _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); - AddToMessageLog(TEXT("OpenService...")); - AddToMessageLog(TEXT(GetLastErrorText(szErr,256))); - - } - CloseServiceHandle(schSCManager); - } - else - { _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); - AddToMessageLog(TEXT("OpenSCMManager..")); - - } -} - - - - -/////////////////////////////////////////////////////////////////// -// -// The following code is for running the service as a console app -// - - -// -// FUNCTION: CmdDebugService(int argc, char ** argv) -// -// PURPOSE: Runs the service as a console application -// -// PARAMETERS: -// argc - number of command line arguments -// argv - array of command line arguments -// -// RETURN VALUE: -// none -// -// COMMENTS: -// -void CmdDebugService(int argc, char ** argv) -{ - DWORD dwArgc; - LPTSTR *lpszArgv; - -#ifdef UNICODE - lpszArgv = CommandLineToArgvW(GetCommandLineW(), &(dwArgc) ); -#else - dwArgc = (DWORD) argc; - lpszArgv = argv; -#endif - - _tprintf(TEXT("Debugging %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); - - SetConsoleCtrlHandler( ControlHandler, TRUE ); - - ServiceStart( dwArgc, lpszArgv ); -} - - -// -// FUNCTION: ControlHandler ( DWORD dwCtrlType ) -// -// PURPOSE: Handled console control events -// -// PARAMETERS: -// dwCtrlType - type of control event -// -// RETURN VALUE: -// True - handled -// False - unhandled -// -// COMMENTS: -// -BOOL WINAPI ControlHandler ( DWORD dwCtrlType ) -{ - switch( dwCtrlType ) - { - case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate - case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode - _tprintf(TEXT("Stopping %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); - ServiceStop(); - return TRUE; - break; - - } - return FALSE; -} - -// -// FUNCTION: GetLastErrorText -// -// PURPOSE: copies error message text to string -// -// PARAMETERS: -// lpszBuf - destination buffer -// dwSize - size of buffer -// -// RETURN VALUE: -// destination buffer -// -// COMMENTS: -// -LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ) -{ - DWORD dwRet; - LPTSTR lpszTemp = NULL; - - dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY, - NULL, - GetLastError(), - LANG_NEUTRAL, - (LPTSTR)&lpszTemp, - 0, - NULL ); - - // supplied buffer is not long enough - if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) ) - lpszBuf[0] = TEXT('\0'); - else - { - lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character - _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() ); - } - - if ( lpszTemp ) - LocalFree((HLOCAL) lpszTemp ); - - return lpszBuf; -} - -//------------------------------------------------- -// this event is signalled when the -// service should end -//------------------------------------------------- -HANDLE hServerStopEvent = NULL; - - -//------------------------------------------------- -// FUNCTION: ServiceStart -// -// PURPOSE: Actual code of the service -// that does the work. -//------------------------------------------------- -void ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) -{ - DWORD dwWait,dwTimeout=1000*60*1; - - if (!ReportStatusToSCMgr( - SERVICE_START_PENDING, // service state - NO_ERROR, // exit code - 3000)) // wait hint - goto cleanup; - - // create the event object. The control handler function signals - // this event when it receives the "stop" control code. - // - hServerStopEvent = CreateEvent( - NULL, // no security attributes - TRUE, // manual reset event - FALSE, // not-signalled - NULL); // no name - - if ( hServerStopEvent == NULL) goto cleanup; - - - // report the status to the service control manager. - // - if (!ReportStatusToSCMgr( - SERVICE_START_PENDING, // service state - NO_ERROR, // exit code - 3000)) // wait hint - goto cleanup; - - - - // report the status to the service control manager. - // - if (!ReportStatusToSCMgr( - SERVICE_START_PENDING, // service state - NO_ERROR, // exit code - 3000)) // wait hint - goto cleanup; - - - - // report the status to the service control manager. - // - if (!ReportStatusToSCMgr( - SERVICE_RUNNING, // service state - NO_ERROR, // exit code - 0)) // wait hint - goto cleanup; - - // - // End of initialization - // Service is now running, perform work until shutdown - // - - while ( 1 ) - { - - dwWait = WaitForSingleObject( hServerStopEvent, dwTimeout); - if(dwWait==WAIT_FAILED) - { - AddToMessageLog(TEXT("Error in WaitForSingleObject")); - break; - } - else if(dwWait==WAIT_TIMEOUT) - { - CmdRestartService("MySql"); - } - else - { break; //shutdown - } - - } - - cleanup: - - if (hServerStopEvent) - CloseHandle(hServerStopEvent); - -} - - -//------------------------------------------------- -// FUNCTION: ServiceStop -// -// PURPOSE: Stops the service -//------------------------------------------------- -void ServiceStop() -{ - if ( hServerStopEvent ) - SetEvent(hServerStopEvent); -} -//-the end ---------------------------------------- -- cgit v1.2.1