Browse Source

bugfix service name handling

smaller-size v0.2.10
AJ ONeal 5 years ago
parent
commit
7035ede0b9
  1. 9
      manager/install_darwin.go
  2. 8
      manager/install_linux.go
  3. 46
      manager/start.go

9
manager/install_darwin.go

@ -36,13 +36,11 @@ func start(system bool, home string, name string) error {
if nil != err { if nil != err {
return err return err
} }
service = filepath.Join(srvSysPath, service)
} else { } else {
service, err = getOneUserSrv(home, sys, user, name) service, err = getOneUserSrv(home, sys, user, name)
if nil != err { if nil != err {
return err return err
} }
service = filepath.Join(home, srvUserPath, service)
} }
cmds := []Runnable{ cmds := []Runnable{
@ -52,9 +50,10 @@ func start(system bool, home string, name string) error {
Must: false, Must: false,
}, },
Runnable{ Runnable{
Exec: "launchctl",
Args: []string{"load", "-w", service},
Must: true,
Exec: "launchctl",
Args: []string{"load", "-w", service},
Must: true,
Badwords: []string{"No such file or directory", "service already loaded"},
}, },
} }

8
manager/install_linux.go

@ -35,19 +35,17 @@ func start(system bool, home string, name string) error {
return err return err
} }
var service string
// var service string
if system { if system {
service, err = getOneSysSrv(sys, user, name)
_, err = getOneSysSrv(sys, user, name)
if nil != err { if nil != err {
return err return err
} }
service = filepath.Join(srvSysPath, service)
} else { } else {
service, err = getOneUserSrv(home, sys, user, name)
_, err = getOneUserSrv(home, sys, user, name)
if nil != err { if nil != err {
return err return err
} }
service = filepath.Join(home, srvUserPath, service)
} }
var cmds []Runnable var cmds []Runnable

46
manager/start.go

@ -99,10 +99,10 @@ func getSystemSrvs() ([]string, error) {
} }
func getUserSrvs(home string) ([]string, error) { func getUserSrvs(home string) ([]string, error) {
dir := filepath.Join(home, srvUserPath)
return getSrvs(dir)
return getSrvs(filepath.Join(home, srvUserPath))
} }
// "come.example.foo.plist" matches "foo"
func filterMatchingSrvs(plists []string, name string) []string { func filterMatchingSrvs(plists []string, name string) []string {
filtered := []string{} filtered := []string{}
@ -148,59 +148,45 @@ func getExactSrvMatch(srvs []string, name string) string {
} }
func getOneSysSrv(sys []string, user []string, name string) (string, error) { func getOneSysSrv(sys []string, user []string, name string) (string, error) {
service := getExactSrvMatch(user, name)
if "" != service {
return service, nil
if service := getExactSrvMatch(user, name); "" != service {
return filepath.Join(srvSysPath, service), nil
} }
var errstr string
// system service was wanted
n := len(sys) n := len(sys)
switch { switch {
case 0 == n: case 0 == n:
errstr += fmt.Sprintf("Didn't find user service matching %q\n", name)
errstr := fmt.Sprintf("Didn't find user service matching %q\n", name)
if 0 != len(user) { if 0 != len(user) {
errstr += fmt.Sprintf("Did you intend to run a user service instead?\n\t%s\n", strings.Join(user, "\n\t")) errstr += fmt.Sprintf("Did you intend to run a user service instead?\n\t%s\n", strings.Join(user, "\n\t"))
} }
return "", fmt.Errorf(errstr)
case n > 1: case n > 1:
errstr += fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(sys, "\n\t"))
default:
service = filepath.Join(srvSysPath, sys[0])
}
if "" != errstr {
errstr := fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(sys, "\n\t"))
return "", fmt.Errorf(errstr) return "", fmt.Errorf(errstr)
default:
return filepath.Join(srvSysPath, sys[0]), nil
} }
return service, nil
} }
func getOneUserSrv(home string, sys []string, user []string, name string) (string, error) { func getOneUserSrv(home string, sys []string, user []string, name string) (string, error) {
service := getExactSrvMatch(user, name)
if "" != service {
return service, nil
if service := getExactSrvMatch(user, name); "" != service {
return filepath.Join(home, srvUserPath, service), nil
} }
var errstr string
// user service was wanted
n := len(user) n := len(user)
switch { switch {
case 0 == n: case 0 == n:
errstr += fmt.Sprintf("Didn't find user service matching %q\n", name)
errstr := fmt.Sprintf("Didn't find user service matching %q\n", name)
if 0 != len(sys) { if 0 != len(sys) {
errstr += fmt.Sprintf("Did you intend to run a system service instead?\n\t%s\n", strings.Join(sys, "\n\t")) errstr += fmt.Sprintf("Did you intend to run a system service instead?\n\t%s\n", strings.Join(sys, "\n\t"))
} }
return "", fmt.Errorf(errstr)
case n > 1: case n > 1:
errstr += fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(user, "\n\t"))
default:
service = filepath.Join(home, srvUserPath, user[0]+srvExt)
}
if "" != errstr {
errstr := fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(user, "\n\t"))
return "", fmt.Errorf(errstr) return "", fmt.Errorf(errstr)
default:
return filepath.Join(home, srvUserPath, user[0]), nil
} }
return service, nil
} }
func adjustPrivs(system bool, cmds []Runnable) []Runnable { func adjustPrivs(system bool, cmds []Runnable) []Runnable {

Loading…
Cancel
Save