bugfix service name handling
This commit is contained in:
parent
d610b8cb61
commit
7035ede0b9
|
@ -36,13 +36,11 @@ func start(system bool, home string, name string) error {
|
|||
if nil != err {
|
||||
return err
|
||||
}
|
||||
service = filepath.Join(srvSysPath, service)
|
||||
} else {
|
||||
service, err = getOneUserSrv(home, sys, user, name)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
service = filepath.Join(home, srvUserPath, service)
|
||||
}
|
||||
|
||||
cmds := []Runnable{
|
||||
|
@ -55,6 +53,7 @@ func start(system bool, home string, name string) error {
|
|||
Exec: "launchctl",
|
||||
Args: []string{"load", "-w", service},
|
||||
Must: true,
|
||||
Badwords: []string{"No such file or directory", "service already loaded"},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -35,19 +35,17 @@ func start(system bool, home string, name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var service string
|
||||
// var service string
|
||||
if system {
|
||||
service, err = getOneSysSrv(sys, user, name)
|
||||
_, err = getOneSysSrv(sys, user, name)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
service = filepath.Join(srvSysPath, service)
|
||||
} else {
|
||||
service, err = getOneUserSrv(home, sys, user, name)
|
||||
_, err = getOneUserSrv(home, sys, user, name)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
service = filepath.Join(home, srvUserPath, service)
|
||||
}
|
||||
|
||||
var cmds []Runnable
|
||||
|
|
|
@ -99,10 +99,10 @@ func getSystemSrvs() ([]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 {
|
||||
filtered := []string{}
|
||||
|
||||
|
@ -148,59 +148,45 @@ func getExactSrvMatch(srvs []string, name string) string {
|
|||
}
|
||||
|
||||
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)
|
||||
switch {
|
||||
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) {
|
||||
errstr += fmt.Sprintf("Did you intend to run a user service instead?\n\t%s\n", strings.Join(user, "\n\t"))
|
||||
}
|
||||
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 {
|
||||
return "", fmt.Errorf(errstr)
|
||||
case n > 1:
|
||||
errstr := fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(sys, "\n\t"))
|
||||
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) {
|
||||
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)
|
||||
switch {
|
||||
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) {
|
||||
errstr += fmt.Sprintf("Did you intend to run a system service instead?\n\t%s\n", strings.Join(sys, "\n\t"))
|
||||
}
|
||||
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 {
|
||||
return "", fmt.Errorf(errstr)
|
||||
case n > 1:
|
||||
errstr := fmt.Sprintf("Found more than one matching service:\n\t%s\n", strings.Join(user, "\n\t"))
|
||||
return "", fmt.Errorf(errstr)
|
||||
default:
|
||||
return filepath.Join(home, srvUserPath, user[0]), nil
|
||||
}
|
||||
|
||||
return service, nil
|
||||
}
|
||||
|
||||
func adjustPrivs(system bool, cmds []Runnable) []Runnable {
|
||||
|
|
Loading…
Reference in New Issue