/src/mongo/util/ntservice.h

https://github.com/tadmarshall/mongo · C Header · 85 lines · 27 code · 15 blank · 43 comment · 0 complexity · 62a0152b07be5e64d4fa679894f89b04 MD5 · raw file

  1. /* Copyright 2009 10gen Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /**
  16. * The ntservice namespace provides minimal support for running mongo servers as NT services.
  17. *
  18. * TODO: ntservice should only provide implementation for a more general server process
  19. * startup/shutdown/management interface.
  20. */
  21. #pragma once
  22. #ifdef _WIN32
  23. #include <boost/program_options.hpp>
  24. #include <string>
  25. #include <vector>
  26. #include "mongo/platform/compiler.h"
  27. namespace mongo {
  28. namespace ntservice {
  29. struct NtServiceDefaultStrings {
  30. const wchar_t* serviceName;
  31. const wchar_t* displayName;
  32. const wchar_t* serviceDescription;
  33. };
  34. typedef void (*ServiceCallback)(void);
  35. /**
  36. * Configure the service.
  37. *
  38. * Also performs service installation and removal.
  39. *
  40. * This function calls _exit() with an error if bad parameters are passed in. If
  41. * the parameters specify that the service should be installed, removed, etc, performs that
  42. * operation and exits.
  43. *
  44. * If this function returns to the caller, the caller should either call startService, or run
  45. * the service as a regular process, depending on the return value of shouldStartService().
  46. */
  47. void configureService(
  48. ServiceCallback serviceCallback,
  49. const boost::program_options::variables_map& params,
  50. const NtServiceDefaultStrings& defaultStrings,
  51. const std::vector<std::string>& disallowedOptions,
  52. const std::vector<std::string>& argv);
  53. bool shouldStartService();
  54. /**
  55. * Construct an argv array that Windows should use to start mongod/mongos as a service
  56. * if mongo was started with "inputArgv", which is assumed to be an argument vector that
  57. * dictates that Windows should install mongo as a service.
  58. *
  59. * The result is suitable for passing to mongo::constructUtf8WindowsCommandLine() to construct
  60. * a properly quoted command line string.
  61. */
  62. std::vector<std::string> constructServiceArgv(const std::vector<std::string>& inputArgv);
  63. /**
  64. * Start the service. Never returns.
  65. */
  66. MONGO_COMPILER_NORETURN void startService();
  67. bool reportStatus(DWORD reportState, DWORD waitHint = 0);
  68. } // namespace ntservice
  69. } // namespace mongo
  70. #endif // defined(_WIN32)