Finish windows support

- Fix service creation
- Singleton lock
- Control error/logging
- Revamp run/service interaction
- Add option to turn off stdout/stderr output (for Windows Service)
- Use log instead of fmt.Print*
This commit is contained in:
Daniel
2019-07-24 09:22:16 +02:00
parent d9ae6a140d
commit c6083fc464
10 changed files with 486 additions and 246 deletions

31
pmctl/service.go Normal file
View File

@@ -0,0 +1,31 @@
package main
import (
"sync"
)
var (
startupComplete = make(chan struct{}) // signal that the start procedure completed (is never closed, just signaled once)
shuttingDown = make(chan struct{}) // signal that we are shutting down (will be closed, may not be closed directly, use initiateShutdown)
shutdownInitiated = false // not to be used directly
shutdownError error // may not be read or written to directly
shutdownLock sync.Mutex
)
func initiateShutdown(err error) {
shutdownLock.Lock()
defer shutdownLock.Unlock()
if !shutdownInitiated {
shutdownInitiated = true
shutdownError = err
close(shuttingDown)
}
}
func getShutdownError() error {
shutdownLock.Lock()
defer shutdownLock.Unlock()
return shutdownError
}