37 lines
943 B
Go
37 lines
943 B
Go
package ser
|
|
|
|
import (
|
|
"errors"
|
|
"git.xdrm.io/go/nix-amer/internal/exec"
|
|
)
|
|
|
|
// ErrUnknownManager is raised when the asked manager does not exist
|
|
var ErrUnknownManager = errors.New("unknown service manager")
|
|
|
|
// ErrNotInstalled is raised when the candidate service manager is not installed
|
|
// on the host system (use command-line -dry-run to avoid execution errors and just
|
|
// check your buildfile syntax)
|
|
var ErrNotInstalled = errors.New("no candidate installed")
|
|
|
|
// Load a specific service-manager by its name
|
|
func Load(_manager string, _exec exec.Executor) (ServiceManager, error) {
|
|
|
|
// 1. create manager (fail if unknown)
|
|
var manager ServiceManager
|
|
switch _manager {
|
|
case "systemd":
|
|
manager = new(systemd)
|
|
default:
|
|
return nil, ErrUnknownManager
|
|
}
|
|
|
|
// 2. fail if not installed
|
|
// if exec.Command("which", manager.Name()).Run() != nil {
|
|
// return nil, ErrNotInstalled
|
|
// }
|
|
|
|
manager.SetExecutor(_exec)
|
|
return manager, nil
|
|
|
|
}
|