commit e3bcf1f2396c80411334ac5c7107468a9a97d750 Author: Tai Groot Date: Fri May 14 14:27:29 2021 -0700 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..eca6ef1 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# systemctl + +This library aims at providing idiomatic `systemctl` bindings for go developers, in order to make it easier to write system tooling using golang. + +## What is systemctl + +systemctl is a command-line program which grants the user control over the systemd system and service manager. + +systemctl may be used to introspect and control the state of the "systemd" system and service manager. Please refer to systemd(1) for an introduction into the basic concepts and functionality this tool manages. + +## Supported functions + +- [ ] `systemctl is-failed` +- [ ] `systemctl is-active` +- [ ] `systemctl status` +- [ ] `systemctl restart` +- [ ] `systemctl start` +- [ ] `systemctl stop` +- [ ] `systemctl enable` +- [ ] `systemctl disable` +- [ ] `systemctl is-enabled` +- [ ] `systemctl daemon-reload` +- [ ] `systemctl show` + +## TODO + +- [ ] Add additional bindings for systemctl options I (the author) don't use frequently (or ever) for others to use. +- [ ] Set up `go test` testing + +## Simple example + +```go +package main + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/taigrr/systemctl/v1" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + // Equivalent to `systemctl enable dhcpd` with a 10 second timeout + err := systemctl.Enable("dhcpd", ctx) + if err != nil { + log.Fatalf("unable to enable unit %s: %v", "dhcpd", err) + } +} +``` + +## External resources + +- [Official systemctl documentation](https://www.man7.org/linux/man-pages/man1/systemctl.1.html) +- [Inspiration for this repo](https://github.com/Ullaakut/nmap/) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9c23437 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/taigrr/systemctl + +go 1.16 diff --git a/systemctl.go b/systemctl.go new file mode 100644 index 0000000..ec94ff6 --- /dev/null +++ b/systemctl.go @@ -0,0 +1,54 @@ +package systemctl + +// TODO +func IsFailed(unit string) (bool, error) { + return false, nil +} + +// TODO +func IsActive(unit string) (bool, error) { + return false, nil +} + +// TODO +func Status(unit string) (bool, error) { + return false, nil +} + +// TODO +func Restart(unit string) error { + return nil +} + +// TODO +func Start(unit string) error { + return nil +} + +// TODO +func Stop(unit string) error { + return nil +} + +// TODO +func Enable(unit string) error { + return nil +} + +// TODO +func Disable(unit string) error { + return nil +} + +// TODO +func IsEnabled(unit string) (bool, error) { + return false, nil +} + +// TODO +func DaemonReload(unit string) error { + return nil +} +func Show(unit string, property string) (string, error) { + return "", nil +}