service.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. typedef struct {
  18. TCHAR name[SERVICE_NAME_LENGTH];
  19. TCHAR displayname[SERVICE_DISPLAYNAME_LENGTH];
  20. TCHAR description[VALUE_LENGTH];
  21. unsigned long startup;
  22. TCHAR exe[EXE_LENGTH];
  23. TCHAR flags[VALUE_LENGTH];
  24. TCHAR dir[MAX_PATH];
  25. TCHAR *env;
  26. unsigned long envlen;
  27. TCHAR *env_extra;
  28. unsigned long env_extralen;
  29. TCHAR stdin_path[MAX_PATH];
  30. unsigned long stdin_sharing;
  31. unsigned long stdin_disposition;
  32. unsigned long stdin_flags;
  33. TCHAR stdout_path[MAX_PATH];
  34. unsigned long stdout_sharing;
  35. unsigned long stdout_disposition;
  36. unsigned long stdout_flags;
  37. TCHAR stderr_path[MAX_PATH];
  38. unsigned long stderr_sharing;
  39. unsigned long stderr_disposition;
  40. unsigned long stderr_flags;
  41. bool rotate_files;
  42. unsigned long rotate_seconds;
  43. unsigned long rotate_bytes_low;
  44. unsigned long rotate_bytes_high;
  45. unsigned long default_exit_action;
  46. unsigned long throttle_delay;
  47. unsigned long stop_method;
  48. unsigned long kill_console_delay;
  49. unsigned long kill_window_delay;
  50. unsigned long kill_threads_delay;
  51. SC_HANDLE handle;
  52. SERVICE_STATUS status;
  53. SERVICE_STATUS_HANDLE status_handle;
  54. HANDLE process_handle;
  55. unsigned long pid;
  56. HANDLE wait_handle;
  57. bool stopping;
  58. bool allow_restart;
  59. unsigned long throttle;
  60. CRITICAL_SECTION throttle_section;
  61. bool throttle_section_initialised;
  62. CONDITION_VARIABLE throttle_condition;
  63. HANDLE throttle_timer;
  64. LARGE_INTEGER throttle_duetime;
  65. FILETIME creation_time;
  66. FILETIME exit_time;
  67. } nssm_service_t;
  68. void WINAPI service_main(unsigned long, TCHAR **);
  69. TCHAR *service_control_text(unsigned long);
  70. void log_service_control(TCHAR *, unsigned long, bool);
  71. unsigned long WINAPI service_control_handler(unsigned long, unsigned long, void *, void *);
  72. nssm_service_t *alloc_nssm_service();
  73. void set_nssm_service_defaults(nssm_service_t *);
  74. void cleanup_nssm_service(nssm_service_t *);
  75. SC_HANDLE open_service_manager();
  76. int pre_install_service(int, TCHAR **);
  77. int pre_remove_service(int, TCHAR **);
  78. int install_service(nssm_service_t *);
  79. int remove_service(nssm_service_t *);
  80. void set_service_recovery(nssm_service_t *);
  81. int monitor_service(nssm_service_t *);
  82. int start_service(nssm_service_t *);
  83. int stop_service(nssm_service_t *, unsigned long, bool, bool);
  84. void CALLBACK end_service(void *, unsigned char);
  85. void throttle_restart(nssm_service_t *);
  86. int await_shutdown(nssm_service_t *, TCHAR *, unsigned long);
  87. #endif