本文整理汇总了Golang中github.com/coreos/go-systemd/dbus.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newSystemd
// newSystemd creates a systemd object that implements systemdInterface.
func newSystemd() (*systemd, error) {
dbusConn, err := dbus.New()
if err != nil {
return nil, err
}
return &systemd{dbusConn}, nil
}
开发者ID:Cloven,项目名称:minikube,代码行数:8,代码来源:systemd.go
示例2: NewSystemdUnitManager
func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager, error) {
var systemd *dbus.Conn
var err error
if systemdUser {
systemd, err = dbus.NewUserConnection()
} else {
systemd, err = dbus.New()
}
if err != nil {
return nil, err
}
if err := os.MkdirAll(uDir, os.FileMode(0755)); err != nil {
return nil, err
}
hashes, err := hashUnitFiles(uDir)
if err != nil {
return nil, err
}
mgr := systemdUnitManager{
systemd: systemd,
unitsDir: uDir,
hashes: hashes,
mutex: sync.RWMutex{},
}
return &mgr, nil
}
开发者ID:jonboulle,项目名称:fleet,代码行数:29,代码来源:manager.go
示例3: RunUnitCommand
func (s *systemd) RunUnitCommand(u Unit, c string) (string, error) {
conn, err := dbus.New()
if err != nil {
return "", err
}
var fn func(string, string) (string, error)
switch c {
case "start":
fn = conn.StartUnit
case "stop":
fn = conn.StopUnit
case "restart":
fn = conn.RestartUnit
case "reload":
fn = conn.ReloadUnit
case "try-restart":
fn = conn.TryRestartUnit
case "reload-or-restart":
fn = conn.ReloadOrRestartUnit
case "reload-or-try-restart":
fn = conn.ReloadOrTryRestartUnit
default:
return "", fmt.Errorf("Unsupported systemd command %q", c)
}
return fn(u.Name, "replace")
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:28,代码来源:systemd.go
示例4: Restart
// Restart behaves as `systemctl restart <unit>`
func (sdc *SystemdClient) Restart(unit string) error {
sdc.Logger.Debugf("restarting %s", unit)
conn, err := dbus.New()
if err != nil {
return maskAny(err)
}
responseChan := make(chan string, 1)
if _, err := conn.RestartUnit(unit, "replace", responseChan); err != nil {
sdc.Logger.Errorf("restarting %s failed: %#v", unit, err)
return maskAny(err)
}
select {
case res := <-responseChan:
switch res {
case "done":
return nil
case "failed":
// We need a start considered to be failed, when the unit is already running.
return nil
case "canceled", "timeout", "dependency", "skipped":
return maskAny(errgo.WithCausef(nil, SystemdError, res))
default:
// that should never happen
sdc.Logger.Errorf("unexpected systemd response: '%s'", res)
return maskAny(errgo.WithCausef(nil, SystemdError, res))
}
case <-time.After(jobTimeout):
return maskAny(errgo.WithCausef(nil, SystemdError, "job timeout"))
}
return nil
}
开发者ID:pulcy,项目名称:gluon,代码行数:36,代码来源:systemd.go
示例5: UseSystemd
func UseSystemd() bool {
if !systemd.SdBooted() {
return false
}
connLock.Lock()
defer connLock.Unlock()
if theConn == nil {
var err error
theConn, err = systemd1.New()
if err != nil {
return false
}
// Assume we have StartTransientUnit
hasStartTransientUnit = true
// But if we get UnknownMethod error we don't
if _, err := theConn.StartTransientUnit("test.scope", "invalid"); err != nil {
if dbusError, ok := err.(dbus.Error); ok {
if dbusError.Name == "org.freedesktop.DBus.Error.UnknownMethod" {
hasStartTransientUnit = false
}
}
}
}
return hasStartTransientUnit
}
开发者ID:hickeng,项目名称:docker,代码行数:29,代码来源:apply_systemd.go
示例6: New
func New(machine *machine.Machine) *Target {
name := "coreinit-" + machine.BootId
systemd := systemdDbus.New()
target := &Target{name, systemd, machine}
target.createSystemdTarget()
return target
}
开发者ID:philips,项目名称:fleet,代码行数:7,代码来源:target.go
示例7: systemd
func (nc *nspawnCluster) systemd(unitName, exec string) error {
conn, err := dbus.New()
if err != nil {
return err
}
defer conn.Close()
props := []dbus.Property{
dbus.PropExecStart(strings.Split(exec, " "), false),
}
log.Printf("Creating transient systemd unit %s", unitName)
res1 := make(chan string)
if _, err = conn.StartTransientUnit(unitName, "replace", props, res1); err != nil {
log.Printf("Failed creating transient unit %s: %v", unitName, err)
return err
}
<-res1
res2 := make(chan string)
_, err = conn.StartUnit(unitName, "replace", res2)
if err != nil {
log.Printf("Failed starting transient unit %s: %v", unitName, err)
return err
}
<-res2
return nil
}
开发者ID:jonboulle,项目名称:fleet,代码行数:30,代码来源:nspawn.go
示例8: DaemonReload
func (s *systemd) DaemonReload() error {
conn, err := dbus.New()
if err != nil {
return err
}
return conn.Reload()
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:8,代码来源:systemd.go
示例9: systemdReload
func (nc *nspawnCluster) systemdReload() error {
conn, err := dbus.New()
if err != nil {
return err
}
conn.Reload()
return nil
}
开发者ID:pulcy,项目名称:j2,代码行数:8,代码来源:nspawn.go
示例10: New
// New creates the rkt container runtime which implements the container runtime interface.
// It will test if the rkt binary is in the $PATH, and whether we can get the
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
func New(config *Config,
generator kubecontainer.RunContainerOptionsGenerator,
recorder record.EventRecorder,
containerRefManager *kubecontainer.RefManager,
readinessManager *kubecontainer.ReadinessManager,
volumeGetter volumeGetter) (kubecontainer.Runtime, error) {
systemdVersion, err := getSystemdVersion()
if err != nil {
return nil, err
}
result, err := systemdVersion.Compare(systemdMinimumVersion)
if err != nil {
return nil, err
}
if result < 0 {
return nil, fmt.Errorf("rkt: systemd version is too old, requires at least %v", systemdMinimumVersion)
}
systemd, err := dbus.New()
if err != nil {
return nil, fmt.Errorf("cannot connect to dbus: %v", err)
}
// Test if rkt binary is in $PATH.
// TODO(yifan): Use a kubelet flag to read the path.
rktBinAbsPath, err := exec.LookPath("rkt")
if err != nil {
return nil, fmt.Errorf("cannot find rkt binary: %v", err)
}
rkt := &runtime{
systemd: systemd,
rktBinAbsPath: rktBinAbsPath,
config: config,
dockerKeyring: credentialprovider.NewDockerKeyring(),
containerRefManager: containerRefManager,
generator: generator,
recorder: recorder,
readinessManager: readinessManager,
volumeGetter: volumeGetter,
}
rkt.prober = prober.New(rkt, readinessManager, containerRefManager, recorder)
// Test the rkt version.
version, err := rkt.Version()
if err != nil {
return nil, err
}
result, err = version.Compare(rktMinimumVersion)
if err != nil {
return nil, err
}
if result < 0 {
return nil, fmt.Errorf("rkt: Version is too old, requires at least %v", rktMinimumVersion)
}
return rkt, nil
}
开发者ID:nvnvrts,项目名称:kubernetes,代码行数:61,代码来源:rkt.go
示例11: daemonReload
// daemonReload instructs systemd to reload it's configuration
func (s *Service) daemonReload() error {
conn, err := dbus.New()
if err != nil {
return err
}
defer conn.Close()
return conn.Reload()
}
开发者ID:ycaille,项目名称:gru,代码行数:10,代码来源:service.go
示例12: listUnits
func (c *systemdCollector) listUnits() ([]dbus.UnitStatus, error) {
conn, err := dbus.New()
if err != nil {
return nil, fmt.Errorf("couldn't get dbus connection: %s", err)
}
units, err := conn.ListUnits()
conn.Close()
return units, err
}
开发者ID:juergenhoetzel,项目名称:node_exporter,代码行数:9,代码来源:systemd_linux.go
示例13: getSystemState
func (c *systemdCollector) getSystemState() (state string, err error) {
conn, err := dbus.New()
if err != nil {
return "", fmt.Errorf("couldn't get dbus connection: %s", err)
}
state, err = conn.GetManagerProperty("SystemState")
conn.Close()
return state, err
}
开发者ID:juergenhoetzel,项目名称:node_exporter,代码行数:9,代码来源:systemd_linux.go
示例14: StartUnit
func StartUnit(name string) error {
conn, err := dbus.New()
if err != nil {
return err
}
_, err = conn.StartUnit(name, "replace")
return err
}
开发者ID:philips,项目名称:coreos-cloudinit,代码行数:9,代码来源:systemd.go
示例15: EnableUnitFile
func (s *systemd) EnableUnitFile(u Unit) error {
conn, err := dbus.New()
if err != nil {
return err
}
units := []string{u.Name}
_, _, err = conn.EnableUnitFiles(units, u.Runtime, true)
return err
}
开发者ID:camarox53,项目名称:coreos-baremetal,代码行数:10,代码来源:systemd.go
示例16: unitProperty
// unitProperty retrieves the requested property for the service unit
func (s *Service) unitProperty(name string) (*dbus.Property, error) {
conn, err := dbus.New()
if err != nil {
return nil, err
}
defer conn.Close()
property, err := conn.GetUnitProperty(s.unit, name)
return property, err
}
开发者ID:ycaille,项目名称:gru,代码行数:12,代码来源:service.go
示例17: NewSystemdManager
func NewSystemdManager(machine *machine.Machine) *SystemdManager {
systemd := systemdDbus.New()
name := "coreinit-" + machine.BootId + ".target"
target := NewSystemdTarget(name)
mgr := &SystemdManager{systemd, target, machine, defaultSystemdRuntimePath, defaultSystemdDbusPath}
mgr.writeUnit(target.Name(), "")
return mgr
}
开发者ID:jamessharp,项目名称:coreinit,代码行数:12,代码来源:manager.go
示例18: main
func main() {
var port int
flag.IntVar(&port, "port", 3001, "server port")
flag.Parse()
fmt.Println("Port: ", port)
var connection, err = dbus.New()
if err != nil {
panic(err)
}
var handler = createHandler(connection)
http.HandleFunc("/", handler)
http.ListenAndServe(":"+strconv.Itoa(port), nil)
}
开发者ID:experimental-platform,项目名称:platform-systemd-proxy,代码行数:13,代码来源:server.go
示例19: killService
func killService(name string, signal int32) error {
conn, err := dbus.New()
if err != nil {
log.WithFields(log.Fields{
"error": err,
"func": "dbus.New",
}).Error("error creating new dbus connection")
return err
}
conn.KillUnit(name, signal)
return nil
}
开发者ID:joshie,项目名称:lochness,代码行数:13,代码来源:lock.go
示例20: NewRegistry
func NewRegistry(ttl string) (registry *Registry) {
etcdC := etcd.NewClient(nil)
mach := machine.NewMachine("")
systemd := systemdDbus.New()
if ttl == "" {
ttl = DefaultServiceTTL
}
registry = &Registry{etcdC, systemd, mach, ttl}
return registry
}
开发者ID:robryk,项目名称:coreinit,代码行数:13,代码来源:registry.go
注:本文中的github.com/coreos/go-systemd/dbus.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论