-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support windows service registration
- Loading branch information
1 parent
1e15a5b
commit f0e9201
Showing
8 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package pusher | ||
|
||
import ( | ||
"crypto/tls" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package pusher | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package windows | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"golang.org/x/sys/windows/svc" | ||
) | ||
|
||
// WindowsExporterService channel for service stop | ||
type WindowsExporterService struct { | ||
stopCh chan<- bool | ||
} | ||
|
||
// NewWindowsExporterService return new WindowsExporterService | ||
func NewWindowsExporterService(ch chan<- bool) *WindowsExporterService { | ||
return &WindowsExporterService{stopCh: ch} | ||
} | ||
|
||
// Execute run programm directly or for service | ||
func (s *WindowsExporterService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { | ||
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | ||
changes <- svc.Status{State: svc.StartPending} | ||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} | ||
loop: | ||
for { | ||
select { | ||
case c := <-r: | ||
switch c.Cmd { | ||
case svc.Interrogate: | ||
changes <- c.CurrentStatus | ||
case svc.Stop, svc.Shutdown: | ||
s.stopCh <- true | ||
break loop | ||
default: | ||
log.Fatalf(fmt.Sprintf("unexpected control request #%d", c)) | ||
} | ||
} | ||
} | ||
changes <- svc.Status{State: svc.StopPending} | ||
return | ||
} |
This file was deleted.
Oops, something went wrong.