35 lines
853 B
Go
35 lines
853 B
Go
package ser
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
// 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) (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
|
|
// }
|
|
|
|
return manager, nil
|
|
|
|
}
|