service.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef SERVICE_H
  2. #define SERVICE_H
  3. /*
  4. MSDN says the commandline in CreateProcess() is limited to 32768 characters
  5. and the application name to MAX_PATH.
  6. A registry key is limited to 255 characters.
  7. A registry value is limited to 16383 characters.
  8. Therefore we limit the service name to accommodate the path under HKLM.
  9. */
  10. #define EXE_LENGTH MAX_PATH
  11. #define CMD_LENGTH 32768
  12. #define KEY_LENGTH 255
  13. #define VALUE_LENGTH 16383
  14. #define SERVICE_NAME_LENGTH KEY_LENGTH - 55
  15. #define SERVICE_DISPLAYNAME_LENGTH 256
  16. #define ACTION_LEN 16
  17. #define NSSM_LOCALSYSTEM_ACCOUNT _T("LocalSystem")
  18. typedef struct {
  19. bool native;
  20. TCHAR name[SERVICE_NAME_LENGTH];
  21. TCHAR displayname[SERVICE_DISPLAYNAME_LENGTH];
  22. TCHAR description[VALUE_LENGTH];
  23. unsigned long startup;
  24. TCHAR *username;
  25. size_t usernamelen;
  26. TCHAR *password;
  27. size_t passwordlen;
  28. unsigned long type;
  29. TCHAR image[MAX_PATH];
  30. TCHAR exe[EXE_LENGTH];
  31. TCHAR flags[VALUE_LENGTH];
  32. TCHAR dir[MAX_PATH];
  33. TCHAR *env;
  34. unsigned long envlen;
  35. TCHAR *env_extra;
  36. unsigned long env_extralen;
  37. TCHAR stdin_path[MAX_PATH];
  38. unsigned long stdin_sharing;
  39. unsigned long stdin_disposition;
  40. unsigned long stdin_flags;
  41. TCHAR stdout_path[MAX_PATH];
  42. unsigned long stdout_sharing;
  43. unsigned long stdout_disposition;
  44. unsigned long stdout_flags;
  45. TCHAR stderr_path[MAX_PATH];
  46. unsigned long stderr_sharing;
  47. unsigned long stderr_disposition;
  48. unsigned long stderr_flags;
  49. bool rotate_files;
  50. unsigned long rotate_seconds;
  51. unsigned long rotate_bytes_low;
  52. unsigned long rotate_bytes_high;
  53. unsigned long default_exit_action;
  54. unsigned long throttle_delay;
  55. unsigned long stop_method;
  56. unsigned long kill_console_delay;
  57. unsigned long kill_window_delay;
  58. unsigned long kill_threads_delay;
  59. SC_HANDLE handle;
  60. SERVICE_STATUS status;
  61. SERVICE_STATUS_HANDLE status_handle;
  62. HANDLE process_handle;
  63. unsigned long pid;
  64. HANDLE wait_handle;
  65. bool stopping;
  66. bool allow_restart;
  67. unsigned long throttle;
  68. CRITICAL_SECTION throttle_section;
  69. bool throttle_section_initialised;
  70. CONDITION_VARIABLE throttle_condition;
  71. HANDLE throttle_timer;
  72. LARGE_INTEGER throttle_duetime;
  73. FILETIME creation_time;
  74. FILETIME exit_time;
  75. } nssm_service_t;
  76. void WINAPI service_main(unsigned long, TCHAR **);
  77. TCHAR *service_control_text(unsigned long);
  78. void log_service_control(TCHAR *, unsigned long, bool);
  79. unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);
  80. nssm_service_t *alloc_nssm_service();
  81. void set_nssm_service_defaults(nssm_service_t *);
  82. void cleanup_nssm_service(nssm_service_t *);
  83. SC_HANDLE open_service_manager();
  84. int pre_install_service(int, TCHAR **);
  85. int pre_remove_service(int, TCHAR **);
  86. int pre_edit_service(int, TCHAR **);
  87. int install_service(nssm_service_t *);
  88. int remove_service(nssm_service_t *);
  89. int edit_service(nssm_service_t *, bool);
  90. void set_service_recovery(nssm_service_t *);
  91. int monitor_service(nssm_service_t *);
  92. int start_service(nssm_service_t *);
  93. int stop_service(nssm_service_t *, unsigned long, bool, bool);
  94. void CALLBACK end_service(void *, unsigned char);
  95. void throttle_restart(nssm_service_t *);
  96. int await_shutdown(nssm_service_t *, TCHAR *, unsigned long);
  97. #endif