重启单元文件时应该是什么模式和通道

时间:2017-12-11 05:36:25

标签: 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)
}

1 个答案:

答案 0 :(得分:3)

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)
}

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

来自dbus/methods.go

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

该模式必须是以下之一:

     
      
  • 替换(调用将启动单元及其依赖项,可能会替换与此冲突的已排队作业),
  •   
  • 失败(调用将启动设备及其依赖项,但如果这会更改已排队的作业,则会失败),
  •   
  • 隔离(调用将启动相关单元并终止所有与其无关的单位),
  •   
  • 忽略依赖(它将启动一个单元但忽略其所有依赖项),
  •   
  • ignore-requirements (它将启动一个单元,但只忽略需求依赖项)。
  •   
     

不建议使用后两种选择。