Skip to content

Commit

Permalink
Merge branch 'release-0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Aug 13, 2014
2 parents bb66d6d + 2a58c49 commit ea57136
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

/*
Package daemon 0.1.4 for use with Go (golang) services.
Package daemon 0.2.0 for use with Go (golang) services.
Package daemon provides primitives for daemonization of golang services.
This package is not provide implementation of user daemon,
Expand Down
24 changes: 12 additions & 12 deletions darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ import (
"text/template"
)

// DarwinRecord - standard record (struct) for darwin version of daemon package
type DarwinRecord struct {
// darwinRecord - standard record (struct) for darwin version of daemon package
type darwinRecord struct {
name string
description string
}

func newDaemon(name, description string) (*DarwinRecord, error) {
func newDaemon(name, description string) (Daemon, error) {

return &DarwinRecord{name, description}, nil
return &darwinRecord{name, description}, nil
}

// Standard service path for system daemons
func (darwin *DarwinRecord) servicePath() string {
func (darwin *darwinRecord) servicePath() string {
return "/Library/LaunchDaemons/" + darwin.name + ".plist"
}

// Check service is installed
func (darwin *DarwinRecord) checkInstalled() bool {
func (darwin *darwinRecord) checkInstalled() bool {

if _, err := os.Stat(darwin.servicePath()); err == nil {
return true
Expand All @@ -46,7 +46,7 @@ func execPath() (string, error) {
}

// Check service is running
func (darwin *DarwinRecord) checkRunning() (string, bool) {
func (darwin *darwinRecord) checkRunning() (string, bool) {
output, err := exec.Command("launchctl", "list", darwin.name).Output()
if err == nil {
if matched, err := regexp.MatchString(darwin.name, string(output)); err == nil && matched {
Expand All @@ -63,7 +63,7 @@ func (darwin *DarwinRecord) checkRunning() (string, bool) {
}

// Install the service
func (darwin *DarwinRecord) Install() (string, error) {
func (darwin *darwinRecord) Install() (string, error) {
installAction := "Install " + darwin.description + ":"

if checkPrivileges() == false {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (darwin *DarwinRecord) Install() (string, error) {
}

// Remove the service
func (darwin *DarwinRecord) Remove() (string, error) {
func (darwin *darwinRecord) Remove() (string, error) {
removeAction := "Removing " + darwin.description + ":"

if checkPrivileges() == false {
Expand All @@ -124,7 +124,7 @@ func (darwin *DarwinRecord) Remove() (string, error) {
}

// Start the service
func (darwin *DarwinRecord) Start() (string, error) {
func (darwin *darwinRecord) Start() (string, error) {
startAction := "Starting " + darwin.description + ":"

if checkPrivileges() == false {
Expand All @@ -147,7 +147,7 @@ func (darwin *DarwinRecord) Start() (string, error) {
}

// Stop the service
func (darwin *DarwinRecord) Stop() (string, error) {
func (darwin *darwinRecord) Stop() (string, error) {
stopAction := "Stopping " + darwin.description + ":"

if checkPrivileges() == false {
Expand All @@ -170,7 +170,7 @@ func (darwin *DarwinRecord) Stop() (string, error) {
}

// Status - Get service status
func (darwin *DarwinRecord) Status() (string, error) {
func (darwin *darwinRecord) Status() (string, error) {

if checkPrivileges() == false {
return "", errors.New(rootPrivileges)
Expand Down
4 changes: 2 additions & 2 deletions linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
// Get the daemon properly
func newDaemon(name, description string) (Daemon, error) {
if _, err := os.Stat("/run/systemd/system"); err == nil {
return &SystemDRecord{name, description}, nil
return &systemDRecord{name, description}, nil
}
return &SystemVRecord{name, description}, nil
return &systemVRecord{name, description}, nil
}

// Get executable path
Expand Down
20 changes: 10 additions & 10 deletions linux_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
"text/template"
)

// SystemDRecord - standard record (struct) for linux systemD version of daemon package
type SystemDRecord struct {
// systemDRecord - standard record (struct) for linux systemD version of daemon package
type systemDRecord struct {
name string
description string
}

// Standard service path for systemD daemons
func (linux *SystemDRecord) servicePath() string {
func (linux *systemDRecord) servicePath() string {
return "/etc/systemd/system/" + linux.name + ".service"
}

// Check service is installed
func (linux *SystemDRecord) checkInstalled() bool {
func (linux *systemDRecord) checkInstalled() bool {

if _, err := os.Stat(linux.servicePath()); err == nil {
return true
Expand All @@ -35,7 +35,7 @@ func (linux *SystemDRecord) checkInstalled() bool {
}

// Check service is running
func (linux *SystemDRecord) checkRunning() (string, bool) {
func (linux *systemDRecord) checkRunning() (string, bool) {
output, err := exec.Command("systemctl", "status", linux.name+".service").Output()
if err == nil {
if matched, err := regexp.MatchString("Active: active", string(output)); err == nil && matched {
Expand All @@ -52,7 +52,7 @@ func (linux *SystemDRecord) checkRunning() (string, bool) {
}

// Install the service
func (linux *SystemDRecord) Install() (string, error) {
func (linux *systemDRecord) Install() (string, error) {
installAction := "Install " + linux.description + ":"

if checkPrivileges() == false {
Expand Down Expand Up @@ -102,7 +102,7 @@ func (linux *SystemDRecord) Install() (string, error) {
}

// Remove the service
func (linux *SystemDRecord) Remove() (string, error) {
func (linux *systemDRecord) Remove() (string, error) {
removeAction := "Removing " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -125,7 +125,7 @@ func (linux *SystemDRecord) Remove() (string, error) {
}

// Start the service
func (linux *SystemDRecord) Start() (string, error) {
func (linux *systemDRecord) Start() (string, error) {
startAction := "Starting " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -148,7 +148,7 @@ func (linux *SystemDRecord) Start() (string, error) {
}

// Stop the service
func (linux *SystemDRecord) Stop() (string, error) {
func (linux *systemDRecord) Stop() (string, error) {
stopAction := "Stopping " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -171,7 +171,7 @@ func (linux *SystemDRecord) Stop() (string, error) {
}

// Status - Get service status
func (linux *SystemDRecord) Status() (string, error) {
func (linux *systemDRecord) Status() (string, error) {

if checkPrivileges() == false {
return "", errors.New(rootPrivileges)
Expand Down
24 changes: 12 additions & 12 deletions linux_systemv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
"text/template"
)

// SystemVRecord - standard record (struct) for linux systemV version of daemon package
type SystemVRecord struct {
// systemVRecord - standard record (struct) for linux systemV version of daemon package
type systemVRecord struct {
name string
description string
}

// Standard service path for systemV daemons
func (linux *SystemVRecord) servicePath() string {
func (linux *systemVRecord) servicePath() string {
return "/etc/init.d/" + linux.name
}

// Check service is installed
func (linux *SystemVRecord) checkInstalled() bool {
func (linux *systemVRecord) checkInstalled() bool {

if _, err := os.Stat(linux.servicePath()); err == nil {
return true
Expand All @@ -35,7 +35,7 @@ func (linux *SystemVRecord) checkInstalled() bool {
}

// Check service is running
func (linux *SystemVRecord) checkRunning() (string, bool) {
func (linux *systemVRecord) checkRunning() (string, bool) {
output, err := exec.Command("service", linux.name, "status").Output()
if err == nil {
if matched, err := regexp.MatchString(linux.name, string(output)); err == nil && matched {
Expand All @@ -52,7 +52,7 @@ func (linux *SystemVRecord) checkRunning() (string, bool) {
}

// Install the service
func (linux *SystemVRecord) Install() (string, error) {
func (linux *systemVRecord) Install() (string, error) {
installAction := "Install " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -76,7 +76,7 @@ func (linux *SystemVRecord) Install() (string, error) {
return installAction + failed, err
}

templ, err := template.New("sysremVConfig").Parse(sysremVConfig)
templ, err := template.New("systemVConfig").Parse(systemVConfig)
if err != nil {
return installAction + failed, err
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (linux *SystemVRecord) Install() (string, error) {
}

// Remove the service
func (linux *SystemVRecord) Remove() (string, error) {
func (linux *systemVRecord) Remove() (string, error) {
removeAction := "Removing " + linux.description + ":"

if checkPrivileges() == false {
Expand Down Expand Up @@ -139,7 +139,7 @@ func (linux *SystemVRecord) Remove() (string, error) {
}

// Start the service
func (linux *SystemVRecord) Start() (string, error) {
func (linux *systemVRecord) Start() (string, error) {
startAction := "Starting " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -162,7 +162,7 @@ func (linux *SystemVRecord) Start() (string, error) {
}

// Stop the service
func (linux *SystemVRecord) Stop() (string, error) {
func (linux *systemVRecord) Stop() (string, error) {
stopAction := "Stopping " + linux.description + ":"

if checkPrivileges() == false {
Expand All @@ -185,7 +185,7 @@ func (linux *SystemVRecord) Stop() (string, error) {
}

// Status - Get service status
func (linux *SystemVRecord) Status() (string, error) {
func (linux *systemVRecord) Status() (string, error) {

if checkPrivileges() == false {
return "", errors.New(rootPrivileges)
Expand All @@ -200,7 +200,7 @@ func (linux *SystemVRecord) Status() (string, error) {
return statusAction, nil
}

var sysremVConfig = `#! /bin/sh
var systemVConfig = `#! /bin/sh
#
# /etc/rc.d/init.d/{{.Name}}
#
Expand Down
18 changes: 9 additions & 9 deletions windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ import (
"errors"
)

// WindowsRecord - standard record (struct) for windows version of daemon package
type WindowsRecord struct {
// windowsRecord - standard record (struct) for windows version of daemon package
type windowsRecord struct {
name string
description string
}

func newDaemon(name, description string) (*WindowsRecord, error) {
func newDaemon(name, description string) (Daemon, error) {

return &WindowsRecord{name, description}, nil
return &windowsRecord{name, description}, nil
}

// Install the service
func (windows *WindowsRecord) Install() (string, error) {
func (windows *windowsRecord) Install() (string, error) {
installAction := "Install " + windows.description + ":"

return installAction + failed, errors.New("windows daemon is not supported")
}

// Remove the service
func (windows *WindowsRecord) Remove() (string, error) {
func (windows *windowsRecord) Remove() (string, error) {
removeAction := "Removing " + windows.description + ":"

return removeAction + failed, errors.New("windows daemon is not supported")
}

// Start the service
func (windows *WindowsRecord) Start() (string, error) {
func (windows *windowsRecord) Start() (string, error) {
startAction := "Starting " + windows.description + ":"

return startAction + failed, errors.New("windows daemon is not supported")
}

// Stop the service
func (windows *WindowsRecord) Stop() (string, error) {
func (windows *windowsRecord) Stop() (string, error) {
stopAction := "Stopping " + windows.description + ":"

return stopAction + failed, errors.New("windows daemon is not supported")
}

// Status - Get service status
func (windows *WindowsRecord) Status() (string, error) {
func (windows *windowsRecord) Status() (string, error) {

return "Status could not defined", errors.New("windows daemon is not supported")
}

0 comments on commit ea57136

Please sign in to comment.