英文:
Managing systemd services with Go
问题
在标准库中,除了os.exec调用外,是否有其他用于管理systemd服务的内容?我看到了一些第三方库,它们与dbus进行连接或与systemd集成,但我在这种情况下尽量想利用标准库。
英文:
Outside of os.exec calling something, is there anything in the standard library for managing systemd services? I have seen a few 3rd party libraries that hook into dbus or integrate with systemd but I was trying to leverage the standard library as much as possible in this case.
答案1
得分: 1
这是没有标准库,但可能会有用的代码:
https://github.com/coreos/go-systemd
我已经测试过它可以列出所有的单元。
package main
import (
"fmt"
"github.com/coreos/go-systemd/dbus"
)
func main() {
systemdConnection, _ := dbus.NewSystemdConnection()
listOfUnits, _ := systemdConnection.ListUnits()
for _, unit := range listOfUnits {
fmt.Println(unit.Name)
}
systemdConnection.Close()
}
请注意,这是一个用于与 systemd 交互的 Go 语言库。
英文:
There is no standard library but maybe this can be useful
https://github.com/coreos/go-systemd
I've tested it to just list all units.
package main
import (
"fmt"
"github.com/coreos/go-systemd/dbus"
)
func main() {
systemdConnection, _ := dbus.NewSystemdConnection()
listOfUnits, _ := systemdConnection.ListUnits()
for _, unit := range listOfUnits {
fmt.Println(unit.Name)
}
systemdConnection.Close()
}
答案2
得分: 0
没有,标准库中没有针对systemd的特定API。
英文:
No, there is no systemd-specific API in standard library.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论