A lightweight mechanism to provide an *instant kickstart* to a Go web server instance upon changing any Go source files under the project directory (and its subdirectories).

service.go 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package windows
  6. const (
  7. SC_MANAGER_CONNECT = 1
  8. SC_MANAGER_CREATE_SERVICE = 2
  9. SC_MANAGER_ENUMERATE_SERVICE = 4
  10. SC_MANAGER_LOCK = 8
  11. SC_MANAGER_QUERY_LOCK_STATUS = 16
  12. SC_MANAGER_MODIFY_BOOT_CONFIG = 32
  13. SC_MANAGER_ALL_ACCESS = 0xf003f
  14. )
  15. //sys OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenSCManagerW
  16. const (
  17. SERVICE_KERNEL_DRIVER = 1
  18. SERVICE_FILE_SYSTEM_DRIVER = 2
  19. SERVICE_ADAPTER = 4
  20. SERVICE_RECOGNIZER_DRIVER = 8
  21. SERVICE_WIN32_OWN_PROCESS = 16
  22. SERVICE_WIN32_SHARE_PROCESS = 32
  23. SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS
  24. SERVICE_INTERACTIVE_PROCESS = 256
  25. SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER | SERVICE_RECOGNIZER_DRIVER
  26. SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER | SERVICE_INTERACTIVE_PROCESS
  27. SERVICE_BOOT_START = 0
  28. SERVICE_SYSTEM_START = 1
  29. SERVICE_AUTO_START = 2
  30. SERVICE_DEMAND_START = 3
  31. SERVICE_DISABLED = 4
  32. SERVICE_ERROR_IGNORE = 0
  33. SERVICE_ERROR_NORMAL = 1
  34. SERVICE_ERROR_SEVERE = 2
  35. SERVICE_ERROR_CRITICAL = 3
  36. SC_STATUS_PROCESS_INFO = 0
  37. SERVICE_STOPPED = 1
  38. SERVICE_START_PENDING = 2
  39. SERVICE_STOP_PENDING = 3
  40. SERVICE_RUNNING = 4
  41. SERVICE_CONTINUE_PENDING = 5
  42. SERVICE_PAUSE_PENDING = 6
  43. SERVICE_PAUSED = 7
  44. SERVICE_NO_CHANGE = 0xffffffff
  45. SERVICE_ACCEPT_STOP = 1
  46. SERVICE_ACCEPT_PAUSE_CONTINUE = 2
  47. SERVICE_ACCEPT_SHUTDOWN = 4
  48. SERVICE_ACCEPT_PARAMCHANGE = 8
  49. SERVICE_ACCEPT_NETBINDCHANGE = 16
  50. SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 32
  51. SERVICE_ACCEPT_POWEREVENT = 64
  52. SERVICE_ACCEPT_SESSIONCHANGE = 128
  53. SERVICE_CONTROL_STOP = 1
  54. SERVICE_CONTROL_PAUSE = 2
  55. SERVICE_CONTROL_CONTINUE = 3
  56. SERVICE_CONTROL_INTERROGATE = 4
  57. SERVICE_CONTROL_SHUTDOWN = 5
  58. SERVICE_CONTROL_PARAMCHANGE = 6
  59. SERVICE_CONTROL_NETBINDADD = 7
  60. SERVICE_CONTROL_NETBINDREMOVE = 8
  61. SERVICE_CONTROL_NETBINDENABLE = 9
  62. SERVICE_CONTROL_NETBINDDISABLE = 10
  63. SERVICE_CONTROL_DEVICEEVENT = 11
  64. SERVICE_CONTROL_HARDWAREPROFILECHANGE = 12
  65. SERVICE_CONTROL_POWEREVENT = 13
  66. SERVICE_CONTROL_SESSIONCHANGE = 14
  67. SERVICE_ACTIVE = 1
  68. SERVICE_INACTIVE = 2
  69. SERVICE_STATE_ALL = 3
  70. SERVICE_QUERY_CONFIG = 1
  71. SERVICE_CHANGE_CONFIG = 2
  72. SERVICE_QUERY_STATUS = 4
  73. SERVICE_ENUMERATE_DEPENDENTS = 8
  74. SERVICE_START = 16
  75. SERVICE_STOP = 32
  76. SERVICE_PAUSE_CONTINUE = 64
  77. SERVICE_INTERROGATE = 128
  78. SERVICE_USER_DEFINED_CONTROL = 256
  79. SERVICE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE | SERVICE_USER_DEFINED_CONTROL
  80. SERVICE_RUNS_IN_SYSTEM_PROCESS = 1
  81. SERVICE_CONFIG_DESCRIPTION = 1
  82. SERVICE_CONFIG_FAILURE_ACTIONS = 2
  83. NO_ERROR = 0
  84. )
  85. type SERVICE_STATUS struct {
  86. ServiceType uint32
  87. CurrentState uint32
  88. ControlsAccepted uint32
  89. Win32ExitCode uint32
  90. ServiceSpecificExitCode uint32
  91. CheckPoint uint32
  92. WaitHint uint32
  93. }
  94. type SERVICE_TABLE_ENTRY struct {
  95. ServiceName *uint16
  96. ServiceProc uintptr
  97. }
  98. type QUERY_SERVICE_CONFIG struct {
  99. ServiceType uint32
  100. StartType uint32
  101. ErrorControl uint32
  102. BinaryPathName *uint16
  103. LoadOrderGroup *uint16
  104. TagId uint32
  105. Dependencies *uint16
  106. ServiceStartName *uint16
  107. DisplayName *uint16
  108. }
  109. type SERVICE_DESCRIPTION struct {
  110. Description *uint16
  111. }
  112. //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle
  113. //sys CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) [failretval==0] = advapi32.CreateServiceW
  114. //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW
  115. //sys DeleteService(service Handle) (err error) = advapi32.DeleteService
  116. //sys StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) = advapi32.StartServiceW
  117. //sys QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) = advapi32.QueryServiceStatus
  118. //sys ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) = advapi32.ControlService
  119. //sys StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) = advapi32.StartServiceCtrlDispatcherW
  120. //sys SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) = advapi32.SetServiceStatus
  121. //sys ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) = advapi32.ChangeServiceConfigW
  122. //sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW
  123. //sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W
  124. //sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W