(file) Return to ServerProcessWindows.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Service

  1 martin 1.13 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.14 //
  3 martin 1.13 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.14 //
 10 martin 1.13 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.14 //
 17 martin 1.13 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.14 //
 20 martin 1.13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.14 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.13 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.14 //
 28 martin 1.13 //////////////////////////////////////////////////////////////////////////
 29 h.sterling 1.1  //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 
 32                 #include <windows.h>
 33                 #include <process.h>    /* _beginthread, _endthread */
 34                 #include <tchar.h>
 35                 #include <direct.h>
 36 kumpf      1.7  #include <Pegasus/Common/MessageLoader.h>
 37                 #include <Pegasus/Common/Thread.h>
 38 kavita.gupta 1.16 #include <Pegasus/Common/Exception.h>
 39 h.sterling   1.1  #include <Pegasus/Server/CIMServer.h>
 40 kumpf        1.8  #include <Service/ServerRunStatus.h>
 41 h.sterling   1.1  
 42                   #include "Service.cpp"
 43                   
 44                   PEGASUS_USING_PEGASUS;
 45                   PEGASUS_USING_STD;
 46                   
 47                   //-------------------------------------------------------------------------
 48                   // GLOBALS
 49                   //-------------------------------------------------------------------------
 50                   static Mutex _cimserverLock;
 51                   static ServerProcess* _server_proc = 0;
 52                   static bool _shutdown = false;
 53                   static Service pegasus_service;
 54                   static HANDLE pegasus_service_event = NULL;
 55 kumpf        1.10 static LPCSTR g_cimservice_key =
 56                       TEXT("SYSTEM\\CurrentControlSet\\Services\\%s");
 57 h.sterling   1.1  static LPCSTR g_cimservice_home = TEXT("home");
 58                   static int g_argc = 0;
 59                   static char **g_argv = 0;
 60                   
 61                   //  Constants representing the command line options.
 62                   static const char OPTION_INSTALL[] = "install";
 63                   static const char OPTION_REMOVE[]  = "remove";
 64                   static const char OPTION_START[]   = "start";
 65                   static const char OPTION_STOP[]    = "stop";
 66                   
 67                   //-------------------------------------------------------------------------
 68                   // PROTOTYPES
 69                   //-------------------------------------------------------------------------
 70                   int cimserver_windows_main(int flag, int argc, char **argv);
 71                   static bool _getRegInfo(const char *lpchKeyword, char *lpchRetValue);
 72                   static bool _setRegInfo(const char *lpchKeyword, const char *lpchValue);
 73                   
 74                   //-------------------------------------------------------------------------
 75                   // NO-OPs for windows platform
 76                   //-------------------------------------------------------------------------
 77 kumpf        1.10 int ServerProcess::cimserver_fork() { return(0); }
 78 h.sterling   1.1  void ServerProcess::notify_parent(int id) { return; }
 79                   void cimserver_exitRC(int rc) {}
 80 kumpf        1.10 int ServerProcess::cimserver_initialize() { return 0; }
 81                   int ServerProcess::cimserver_wait() { return 0; }
 82 h.sterling   1.1  
 83                   
 84                   //-------------------------------------------------------------------------
 85                   // Helper for platform specific handling
 86                   //-------------------------------------------------------------------------
 87                   
 88                   ServerProcess::ServerProcess()
 89                   {
 90 kumpf        1.10     // Be sure to call cimserver_set_process right after instantiating this in
 91                       // order for everything to work
 92 h.sterling   1.1  }
 93                   
 94                   ServerProcess::~ServerProcess()
 95                   {
 96                   }
 97                   
 98                   void ServerProcess::cimserver_set_process(void* p)
 99                   {
100 kumpf        1.10     AutoMutex am(_cimserverLock);
101 h.sterling   1.1      _server_proc = static_cast<ServerProcess *>(p);
102 kumpf        1.10     if (_server_proc && _shutdown)
103 h.sterling   1.1          _server_proc->cimserver_stop();
104                   
105 karl         1.16.6.1  #ifndef PEGASUS_FLAVOR
106 h.sterling   1.1          pegasus_service = Service(getProcessName());
107 karl         1.16.6.1  #else
108                           String serviceName(PEGASUS_FLAVOR);
109                           serviceName.append(Char16('-'));
110                           serviceName.append(getProcessName());
111                           pegasus_service = Service(serviceName.getCString());
112                        #endif
113 h.sterling   1.1      }
114                       
115                       void signal_shutdown()
116                       {
117 kumpf        1.10         AutoMutex am(_cimserverLock);
118 h.sterling   1.1          _shutdown = true;
119 kumpf        1.10         if (_server_proc)
120 kumpf        1.15             _server_proc->cimserver_stop();
121 h.sterling   1.1      }
122                       
123                       //-------------------------------------------------------------------------
124                       // Run main server asynchronously
125                       //-------------------------------------------------------------------------
126 kumpf        1.10     static unsigned __stdcall cimserver_windows_thread(void* parm)
127 h.sterling   1.1      {
128                           int argc = 0;
129 kumpf        1.10         int rc = _server_proc->cimserver_run(g_argc, g_argv, false, false);
130 h.sterling   1.1          SetEvent(pegasus_service_event);
131 kumpf        1.10         _endthreadex(rc);
132 h.sterling   1.1          return rc;
133                       }
134                       
135                       //-------------------------------------------------------------------------
136 kumpf        1.15     //  Windows NT Service Control Code
137 h.sterling   1.1      //-------------------------------------------------------------------------
138                       
139                       //-------------------------------------------------------------------------
140 kumpf        1.15     // START/STOP handler
141 h.sterling   1.1      //-------------------------------------------------------------------------
142                       int cimserver_windows_main(int flag, int argc, char *argv[])
143                       {
144 kumpf        1.10         switch(flag)
145 h.sterling   1.1          {
146                           case Service::STARTUP_FLAG:
147                           {
148                               //
149                               // Start up main run in a separate thread and wait for it to finish.
150                               //
151                       
152                               unsigned threadid = 0;
153                               g_argc = argc;
154                               g_argv = argv;
155 kumpf        1.10             HANDLE hThread = (HANDLE)_beginthreadex(
156                                   NULL, 0, cimserver_windows_thread, NULL, 0, &threadid);
157                               if (hThread == NULL)
158 h.sterling   1.1                  return 1;
159                       
160 kumpf        1.10             WaitForSingleObject(pegasus_service_event, INFINITE);
161 h.sterling   1.1      
162                               //
163                               // Shutdown the cimserver.
164                               //
165                       
166                               signal_shutdown();
167                       
168                               //
169                               // Make sure we upate the SCM that our stop is pending.
170                               // Wait for the main run thread to exit.
171                               //
172                       
173                               DWORD dwCheckPoint = 1; // service code should have already started at 0
174                       
175 kumpf        1.10             while (WaitForSingleObject(hThread, 3000) == WAIT_TIMEOUT)
176 h.sterling   1.1              {
177 kumpf        1.15                 pegasus_service.report_status(
178 kumpf        1.10                     SERVICE_STOP_PENDING, NO_ERROR, dwCheckPoint++, 5000);
179 h.sterling   1.1              }
180                       
181 kumpf        1.10             CloseHandle(hThread);
182 h.sterling   1.1              break;
183                           }
184                           case Service::SHUTDOWN_FLAG:
185                               SetEvent(pegasus_service_event);
186                               break;
187                       
188                           default:
189                               break;
190                           }
191                       
192                           return 0;
193                       }
194                       
195                       
196                       //-------------------------------------------------------------------------
197                       // INSTALL
198                       //-------------------------------------------------------------------------
199                       bool cimserver_install_nt_service(char *service_name)
200                       {
201 kumpf        1.10         Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
202                           char filename[_MAX_PATH] = {0};
203                           char displayname[_MAX_PATH] = {0};
204                           char descriptionname[_MAX_PATH] = {0};
205                       
206                           // If service name is specified, override default
207                           if (service_name == NULL)
208                           {
209                               strcpy(displayname, _server_proc->getExtendedName());
210                           }
211                           else
212                           {
213                               pegasus_service.SetServiceName(service_name);
214                               sprintf(displayname, "%s - %s",
215                                   _server_proc->getExtendedName(),
216                                   service_name);
217                           }
218                       
219                           strcpy(descriptionname, _server_proc->getDescription());
220                       
221                           if (0 != GetModuleFileName(NULL, filename, sizeof(filename)))
222 kumpf        1.10         {
223                               status =
224                                   pegasus_service.Install(displayname, descriptionname, filename);
225                       
226                               // Upon success, set home in registry
227                               if (status == Service::SERVICE_RETURN_SUCCESS)
228                               {
229                                   char pegasus_homepath[_MAX_PATH];
230                                   System::extract_file_path(filename, pegasus_homepath);
231                                   pegasus_homepath[strlen(pegasus_homepath)-1] = '\0';
232                                   strcpy(filename, pegasus_homepath);
233                                   System::extract_file_path(filename, pegasus_homepath);
234                                   pegasus_homepath[strlen(pegasus_homepath)-1] = '\0';
235                                   _setRegInfo(g_cimservice_home, pegasus_homepath);
236                               }
237                           }
238                           else
239                           {
240                               status = (Service::ReturnCode) GetLastError();
241                           }
242                       
243 kumpf        1.10         return (status == Service::SERVICE_RETURN_SUCCESS);
244 h.sterling   1.1      }
245                       
246                       //-------------------------------------------------------------------------
247                       // REMOVE
248                       //-------------------------------------------------------------------------
249 kumpf        1.10     bool cimserver_remove_nt_service(char* service_name)
250 h.sterling   1.1      {
251 kumpf        1.10         Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
252 h.sterling   1.1      
253 kumpf        1.10         // If service name is specified, override default
254                           if (service_name != NULL)
255 h.sterling   1.1          {
256 kumpf        1.10             pegasus_service.SetServiceName(service_name);
257 h.sterling   1.1          }
258                       
259 kumpf        1.10         status = pegasus_service.Remove();
260 h.sterling   1.1      
261 kumpf        1.10         return (status == Service::SERVICE_RETURN_SUCCESS);
262 h.sterling   1.1      }
263                       
264                       //-------------------------------------------------------------------------
265                       // START
266                       //-------------------------------------------------------------------------
267 kumpf        1.10     bool cimserver_start_nt_service(
268                           char* service_name,
269                           int num_args,
270                           char** service_args)
271 h.sterling   1.1      {
272 kumpf        1.10         Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
273 h.sterling   1.1      
274 kumpf        1.10         // If service name is specified, override default
275                           if (service_name != NULL)
276 h.sterling   1.1          {
277 kumpf        1.10             pegasus_service.SetServiceName(service_name);
278 h.sterling   1.1          }
279                       
280 kumpf        1.10         if (num_args > 0 && service_args != NULL)
281                           {
282                               pegasus_service.SetServiceArgs(num_args, service_args);
283                           }
284 h.sterling   1.1      
285 kumpf        1.10         status = pegasus_service.Start(5);
286 h.sterling   1.1      
287 kumpf        1.10         return (status == Service::SERVICE_RETURN_SUCCESS);
288 h.sterling   1.1      }
289                       
290                       //-------------------------------------------------------------------------
291                       // STOP
292                       //-------------------------------------------------------------------------
293 kumpf        1.10     bool cimserver_stop_nt_service(char* service_name)
294 h.sterling   1.1      {
295 kumpf        1.10         Service::ReturnCode status = Service::SERVICE_RETURN_SUCCESS;
296 h.sterling   1.1      
297 kumpf        1.10         // If service name is specified, override default
298                           if (service_name != NULL)
299 h.sterling   1.1          {
300 kumpf        1.10             pegasus_service.SetServiceName(service_name);
301 h.sterling   1.1          }
302                       
303 kumpf        1.10         status = pegasus_service.Stop(5);
304 h.sterling   1.1      
305 kumpf        1.10         return (status == Service::SERVICE_RETURN_SUCCESS);
306 h.sterling   1.1      }
307                       
308                       //-------------------------------------------------------------------------
309                       // HELPER Utilities
310                       //-------------------------------------------------------------------------
311 kumpf        1.10     static bool _getRegInfo(
312                           const char* lpchKeyword,
313                           char* lpchRetValue)
314 h.sterling   1.1      {
315 kumpf        1.10         HKEY hKey;
316                           DWORD dw = _MAX_PATH;
317                           char subKey[_MAX_PATH] = {0};
318                       
319                           sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
320 h.sterling   1.1      
321 kumpf        1.10         if ((RegOpenKeyEx(
322                                    HKEY_LOCAL_MACHINE,
323                                    subKey,
324                                    0,
325                                    KEY_READ,
326                                    &hKey)) != ERROR_SUCCESS)
327 h.sterling   1.1          {
328 kumpf        1.10             return false;
329 h.sterling   1.1          }
330                       
331 kumpf        1.10         if ((RegQueryValueEx(
332                                    hKey,
333                                    lpchKeyword,
334                                    NULL,
335                                    NULL,
336                                    (LPBYTE)lpchRetValue,
337                                    &dw)) != ERROR_SUCCESS)
338 h.sterling   1.1          {
339 kumpf        1.10             RegCloseKey(hKey);
340                               return false;
341 h.sterling   1.1          }
342                       
343 kumpf        1.10         RegCloseKey(hKey);
344 h.sterling   1.1      
345 kumpf        1.10         return true;
346 h.sterling   1.1      }
347                       
348 kumpf        1.10     static bool _setRegInfo(
349                           const char* lpchKeyword,
350                           const char* lpchValue)
351 h.sterling   1.1      {
352 kumpf        1.10         HKEY hKey;
353                           DWORD dw = _MAX_PATH;
354                           char home_key[_MAX_PATH] = {0};
355                           char subKey[_MAX_PATH] = {0};
356 h.sterling   1.1      
357 kumpf        1.10         if (lpchKeyword == NULL || lpchValue == NULL)
358                               return false;
359 h.sterling   1.1      
360 kumpf        1.10         sprintf(subKey, g_cimservice_key, pegasus_service.GetServiceName());
361 h.sterling   1.1      
362 kumpf        1.10         if ((RegCreateKeyEx(
363                                    HKEY_LOCAL_MACHINE,
364                                    subKey,
365                                    0,
366                                    NULL,
367                                    0,
368                                    KEY_ALL_ACCESS,
369                                    NULL,
370                                    &hKey,
371                                    NULL) != ERROR_SUCCESS))
372 h.sterling   1.1          {
373 kumpf        1.10             return false;
374 h.sterling   1.1          }
375                       
376 kumpf        1.10         if ((RegSetValueEx(
377                                    hKey,
378                                    lpchKeyword,
379                                    0,
380                                    REG_SZ,
381                                    (CONST BYTE *)lpchValue,
382                                    (DWORD)(strlen(lpchValue)+1))) != ERROR_SUCCESS)
383 h.sterling   1.1          {
384 kumpf        1.10             RegCloseKey(hKey);
385                               return false;
386 h.sterling   1.1          }
387                       
388 kumpf        1.10         RegCloseKey(hKey);
389 h.sterling   1.1      
390 kumpf        1.10         return true;
391 h.sterling   1.1      }
392                       
393                       //void ServerProcess::setHome(const String& home)
394 kumpf        1.10     String ServerProcess::getHome()
395 h.sterling   1.1      {
396 kumpf        1.7          String home;
397 h.sterling   1.1      
398 kumpf        1.10         // Determine the absolute path to the running program
399                           char exe_pathname[_MAX_PATH] = {0};
400                           char home_pathname[_MAX_PATH] = {0};
401                           if (0 != GetModuleFileName(NULL, exe_pathname, sizeof(exe_pathname)))
402                           {
403                               // Pegasus home search rules:
404                               // - look in registry (if set)
405                               // - if not found, look in PEGASUS_HOME (if set)
406                               // - if not found, use exe directory minus one level
407                       
408                               bool found_reg = _getRegInfo("home", home_pathname);
409                               if (found_reg)
410                               {
411                                   // Make sure home matches
412                                   String current_home(home_pathname);
413                                   String current_exe(exe_pathname);
414                                   current_home.toLower();
415                                   current_exe.toLower();
416                       
417                                   Uint32 pos = current_exe.find(current_home);
418                                   if (pos != PEG_NOT_FOUND)
419 kumpf        1.10                 {
420                                       home = home_pathname;
421                                   }
422                                   else
423                                   {
424                                       found_reg = false;
425                                   }
426                               }
427                               if (found_reg == false)
428                               {
429                                   const char* tmp = getenv("PEGASUS_HOME");
430                                   if (tmp)
431                                   {
432                                       home = tmp;
433                                   }
434                                   else
435                                   {
436                                       // ASSUMPTION: At a minimum, the cimserver program is running
437                                       // from a "bin" directory
438                                       home = FileSystem::extractFilePath(exe_pathname);
439                                       home.remove(home.size()-1, 1);
440 kumpf        1.10                     home = FileSystem::extractFilePath(home);
441                                       home.remove(home.size()-1, 1);
442                                   }
443                               }
444                           }
445 h.sterling   1.1          return home;
446                       }
447                       
448                       //
449                       // Our console control handler
450                       //
451                       
452 kumpf        1.10     static BOOL WINAPI ControlHandler(DWORD dwCtrlType)
453 h.sterling   1.1      {
454 kumpf        1.10         switch (dwCtrlType)
455 h.sterling   1.1          {
456                           case CTRL_BREAK_EVENT:  // use Ctrl+C or Ctrl+Break to simulate
457                           case CTRL_C_EVENT:      // SERVICE_CONTROL_STOP in debug mode
458                           {
459                               signal_shutdown();
460                               return TRUE;
461                           }
462                           }
463                           return FALSE;
464                       }
465                       
466                       //
467                       // Platform specific run
468                       //
469                       
470 kumpf        1.4      int ServerProcess::platform_run(
471                           int argc,
472                           char** argv,
473                           Boolean shutdownOption,
474                           Boolean debugOutputOption)
475 h.sterling   1.1      {
476                           //
477                           // Check for my command line options
478                           //
479                       
480 kumpf        1.10         for (int i = 1; i < argc; )
481 h.sterling   1.1          {
482                               const char* arg = argv[i];
483                       
484                               // Check for -option
485                               if (*arg == '-')
486                               {
487                                   // Get the option
488                                   const char* option = arg + 1;
489                       
490                                   if (strcmp(option, OPTION_INSTALL) == 0)
491                                   {
492                                       //
493                                       // Install as a NT service
494                                       //
495                                       char *opt_arg = NULL;
496                                       if (i+1 < argc)
497                                       {
498                                           opt_arg = argv[i+1];
499                       
500                                       }
501 kumpf        1.10                     if (cimserver_install_nt_service(opt_arg))
502 h.sterling   1.1                      {
503                                           //l10n
504                                           //cout << "\nPegasus installed as NT Service";
505                                           MessageLoaderParms parms(
506                                               "src.Server.cimserver.INSTALLED_NT_SERVICE",
507                                               "\nPegasus installed as a Windows service");
508                                           cout << MessageLoader::getMessage(parms) << endl;
509                                           exit(0);
510                                       }
511                                       else
512                                       {
513                                           exit(0);
514                                       }
515                                   }
516                                   else if (strcmp(option, OPTION_REMOVE) == 0)
517                                   {
518                                       //
519                                       // Remove Pegasus as an NT service
520                                       //
521                                       char *opt_arg = NULL;
522                                       if (i+1 < argc)
523 h.sterling   1.1                      {
524 kumpf        1.10                         opt_arg = argv[i+1];
525 h.sterling   1.1                      }
526 kumpf        1.10                     if (cimserver_remove_nt_service(opt_arg))
527 h.sterling   1.1                      {
528                                           //l10n
529                                           //cout << "\nPegasus removed as NT Service";
530                                           MessageLoaderParms parms(
531                                               "src.Server.cimserver.REMOVED_NT_SERVICE",
532                                               "\nPegasus removed as a Windows service");
533                                           cout << MessageLoader::getMessage(parms) << endl;
534                                           exit(0);
535                                       }
536                                       else
537                                       {
538                                           exit(0);
539                                       }
540                       
541                                   }
542                                   else if (strcmp(option, OPTION_START) == 0)
543                                   {
544                                       //
545                                       // Start as a NT service
546                                       //
547                                       char *opt_arg = NULL;
548 h.sterling   1.1                      int num_args = 0;
549                                       if (i+1 < argc)
550                                       {
551 kumpf        1.10                         opt_arg = argv[i+1];
552 h.sterling   1.1                          num_args = argc - 3;
553                                       }
554                                       else
555                                       {
556                                           num_args = argc - 2;
557                                       }
558                       
559                                       char **service_args = &argv[1];
560 kumpf        1.10                     if (cimserver_start_nt_service(opt_arg, num_args, service_args))
561 h.sterling   1.1                      {
562                                           MessageLoaderParms parms(
563                                               "src.Server.cimserver.STARTED_NT_SERVICE",
564                                               "\nPegasus started as a Windows service");
565                                           cout << MessageLoader::getMessage(parms) << endl;
566                                           exit(0);
567                                       }
568                                       else
569                                       {
570                                           exit(0);
571                                       }
572                                   }
573                                   else if (strcmp(option, OPTION_STOP) == 0)
574                                   {
575                                       //
576                                       // Stop as a NT service
577                                       //
578                                       char *opt_arg = NULL;
579                                       if (i+1 < argc)
580                                       {
581 kumpf        1.10                         opt_arg = argv[i+1];
582 h.sterling   1.1                      }
583 kumpf        1.10                     if (cimserver_stop_nt_service(opt_arg))
584 h.sterling   1.1                      {
585                                           MessageLoaderParms parms(
586                                               "src.Server.cimserver.STOPPED_NT_SERVICE",
587                                               "\nPegasus stopped as a Windows service");
588                                           cout << MessageLoader::getMessage(parms) << endl;
589                                           exit(0);
590                                       }
591                                       else
592                                       {
593                                           exit(0);
594                                       }
595                                   }
596                                   else
597                                       i++;
598                               }
599                               else
600                                   i++;
601                           }
602                       
603                           //
604                           // Signal ourself as running
605 h.sterling   1.1          //
606                       
607 kumpf        1.8          // NOTE: This object must persist for the life of the server process
608 kumpf        1.11         ServerRunStatus serverRunStatus(getProcessName(), 0);
609 kumpf        1.8      
610                           if (!shutdownOption)
611                           {
612 dave.sudlik  1.9              serverRunStatus.setServerRunning();
613 kumpf        1.8          }
614 h.sterling   1.1      
615                           //
616                           // Check if already running
617                           //
618                           // Hmm, when starting as a service, should we do this here (before
619                           // starting the control dispatcher)?  If we do then the SCM reports
620 kumpf        1.10         // a dumb message to the user.  If we don't, and it in the serviceProc
621 h.sterling   1.1          // then the service will start up then die silently.
622                           //
623                       
624 kumpf        1.8          if (!shutdownOption && serverRunStatus.isServerRunning())
625 h.sterling   1.1          {
626                               MessageLoaderParms parms(
627                                   "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
628 kumpf        1.10                 "Unable to start CIMServer.\nCIMServer is already running.");
629 kumpf        1.12             Logger::put_l(
630 h.sterling   1.1                  Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
631 kumpf        1.12                 parms);
632 kumpf        1.10             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
633                                   PEGASUS_STD(endl);
634 h.sterling   1.1              return 1;
635                           }
636                       
637                           //
638                           // Check if running from a console window. If so then just run
639                           // as a console process.
640                           //
641                       
642                           char console_title[ _MAX_PATH ] = {0};
643 kumpf        1.10         if (GetConsoleTitle(console_title, _MAX_PATH) > 0)
644 h.sterling   1.1          {
645 kumpf        1.10             SetConsoleCtrlHandler(ControlHandler, TRUE);
646 h.sterling   1.1      
647 kumpf        1.4              return cimserver_run(argc, argv, shutdownOption, debugOutputOption);
648 h.sterling   1.1          }
649                       
650                           //
651                           // Run as a service
652                           //
653                       
654 kumpf        1.10         pegasus_service_event = CreateEvent(NULL, FALSE, FALSE, NULL);
655 kavita.gupta 1.16         if (pegasus_service_event == NULL)
656                           {
657                               throw Exception(MessageLoaderParms(
658                                   "src.Server.cimserver_windows.EVENT_CREATION_FAILED",
659                                   "Event Creation Failed : $0.",
660                                   PEGASUS_SYSTEM_ERRORMSG_NLS));
661                           }
662 h.sterling   1.1      
663                           Service::ReturnCode status;
664 kumpf        1.10         status = pegasus_service.Run(cimserver_windows_main);
665 h.sterling   1.1      
666 kumpf        1.10         if (status != Service::SERVICE_RETURN_SUCCESS)
667 h.sterling   1.1          {
668                               // todo: put into localized messages when messages unfreezes.
669                               Logger::put_l(
670                                   Logger::ERROR_LOG, "CIMServer", Logger::SEVERE,
671 kumpf        1.12                 MessageLoaderParms(
672                                       "src.Server.cimserver_windows.LISTENING_ON_HTTP_PORT",
673                                       "Error during service run: code = $0.",
674                                       status));
675 h.sterling   1.1              return 1;
676                           }
677                       
678                           return 0;
679                       }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2