service.h 3.1 KB

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