go - 重启单元文件时的模式和 channel 应该是什么

标签 go restart systemd

go-systemd ,重启设备的第二个和第三个参数应该是什么。

// RestartUnit restarts a service.  If a service is restarted that isn't
// running it will be started.
func (c *Conn) RestartUnit(name string, mode string, ch chan<- string)    (int, error) {
return c.startJob(ch, "org.freedesktop.systemd1.Manager.RestartUnit", name, mode)
}

最佳答案

PR 203 中,您可以看到 that method used/tested 为:

// Restart the unit
reschan = make(chan string)
_, err = conn.RestartUnit(target, "replace", reschan)
if err != nil {
    t.Fatal(err)
}

job = <-reschan
if job != "done" {
    t.Fatal("Job is not done:", job)
}

所以你必须创建自己的标签和 channel 。

来自dbus/methods.go

// Takes the unit to activate, plus a **mode string**. 

The mode needs to be one of:

  • replace (the call will start the unit and its dependencies, possibly replacing already queued jobs that conflict with this),
  • fail (the call will start the unit and its dependencies, but will fail if this would change an already queued job),
  • isolate (the call will start the unit in question and terminate all units that aren't dependencies of it),
  • ignore-dependencies (it will start a unit but ignore all its dependencies),
  • ignore-requirements (it will start a unit but only ignore the requirement dependencies).

It is not recommended to make use of the latter two options.

关于go - 重启单元文件时的模式和 channel 应该是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47747001/

相关文章:

linux - 防止在 Redhat 7 中停止 auditd 服务

templates - Golang 从文件中嵌入 html

go - 为 GOOGLE_APPLICATION_CREDENTIALS 设置凭据的替代方法

bash - 将命令作为输入并在终端中运行的程序

windows - 如何编写看门狗定时器以重新启动 Windows 服务?

.net - 在 WiX 中重启后继续安装

python - python 中 os.execl() 和 os.execv() 的区别

gunicorn - 如何在没有 WSGI 的情况下为 Gunicorn 配置 ExecStart?

c - g_dbus_proxy_new_for_bus_sync : assertion 'g_variant_is_object_path (object_path)' failed

使用构建的 GO 语言依赖项