fix upstart detect. Add platform test.

This commit is contained in:
Daniel Theophanes
2014-10-29 09:05:24 -07:00
parent 7a0abbd49c
commit e8fe9e16c3
5 changed files with 33 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
package service
import (
"testing"
)
func TestPlatformName(t *testing.T) {
s, err := NewServiceConfig(&Config{
Name: "Test",
})
if err != nil {
t.Errorf("Failed to create service: %v", err)
}
t.Logf("Platform is %s", s.String())
}
+1
View File
@@ -89,6 +89,7 @@ type Service interface {
Controller
Runner
Logger
String() string
}
// A Generic way to stop and start a service.
+6
View File
@@ -32,6 +32,12 @@ type darwinLaunchdService struct {
logger *syslog.Writer
}
const version = "Darwin Launchd"
func (s *darwinLaunchdService) String() string {
return version
}
func (s *darwinLaunchdService) getServiceFilePath() (string, error) {
if s.UserService {
u, err := user.Current()
+5 -1
View File
@@ -45,7 +45,7 @@ func newService(c *Config) (Service, error) {
}
func isUpstart() bool {
if _, err := os.Stat("/sbin/initctl"); err == nil {
if _, err := os.Stat("/sbin/upstart-udev-bridge"); err == nil {
return true
}
return false
@@ -64,6 +64,10 @@ type linuxService struct {
logger *syslog.Writer
}
func (ls *linuxService) String() string {
return fmt.Sprintf("Linux %s", ls.flavor.String())
}
type initFlavor uint8
func (f initFlavor) String() string {
+6
View File
@@ -23,6 +23,12 @@ type windowsService struct {
logger *eventlog.Log
}
const version = "Windows Service"
func (ws *windowsService) String() string {
return version
}
func (ws *windowsService) 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}