2018-11-08 12:42:13 +00:00
|
|
|
package ser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var ErrUnknownManager = errors.New("unknown service manager")
|
2018-11-10 11:37:31 +00:00
|
|
|
var ErrNotInstalled = errors.New("not candidate installed")
|
2018-11-08 12:42:13 +00:00
|
|
|
|
|
|
|
func Load(_manager string) (ServiceManager, error) {
|
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
// 1. create manager (fail if unknown)
|
2018-11-08 12:42:13 +00:00
|
|
|
var manager ServiceManager
|
|
|
|
switch _manager {
|
|
|
|
case "systemd":
|
|
|
|
manager = new(Systemd)
|
|
|
|
default:
|
|
|
|
return nil, ErrUnknownManager
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. fail if not installed
|
2018-11-10 11:37:31 +00:00
|
|
|
// if exec.Command("which", manager.Name()).Run() != nil {
|
|
|
|
// return nil, ErrNotInstalled
|
|
|
|
// }
|
2018-11-08 12:42:13 +00:00
|
|
|
|
|
|
|
return manager, nil
|
|
|
|
|
|
|
|
}
|