{"id":27253444,"url":"https://github.com/marselester/systemd","last_synced_at":"2025-07-04T21:36:03.593Z","repository":{"id":79214575,"uuid":"603979023","full_name":"marselester/systemd","owner":"marselester","description":"Client to access systemd services via D-Bus.","archived":false,"fork":false,"pushed_at":"2023-04-03T23:57:19.000Z","size":357,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T01:36:32.726Z","etag":null,"topics":["dbus","systemd"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marselester.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-20T04:20:54.000Z","updated_at":"2023-05-05T21:50:57.000Z","dependencies_parsed_at":"2024-02-06T03:15:20.941Z","dependency_job_id":null,"html_url":"https://github.com/marselester/systemd","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/marselester/systemd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Fsystemd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Fsystemd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Fsystemd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Fsystemd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marselester","download_url":"https://codeload.github.com/marselester/systemd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marselester%2Fsystemd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263624868,"owners_count":23490570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dbus","systemd"],"created_at":"2025-04-11T01:27:39.433Z","updated_at":"2025-07-04T21:36:03.552Z","avatar_url":"https://github.com/marselester.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# systemd\n\n[![Documentation](https://godoc.org/github.com/marselester/systemd?status.svg)](https://pkg.go.dev/github.com/marselester/systemd)\n[![Go Report Card](https://goreportcard.com/badge/github.com/marselester/systemd)](https://goreportcard.com/report/github.com/marselester/systemd)\n\nThis package provides an access to systemd via D-Bus\nto list services (think `systemctl list-units`) with a low overhead for a caller.\nIf you find the API too limiting or missing some of functionality,\nperhaps https://github.com/coreos/go-systemd might suit you better.\n\n```go\nc, err := systemd.New()\nif err != nil {\n    log.Fatal(err)\n}\ndefer c.Close()\n\nerr = c.ListUnits(systemd.IsService, func(u *systemd.Unit) {\n    fmt.Printf(\"%s %s\\n\", u.Name, u.ActiveState)\n})\nif err != nil {\n    log.Fatal(err)\n}\n// Output:\n// dirmngr.service inactive\n// dbus.service active\n// snapd.session-agent.service inactive\n// gpg-agent.service inactive\n// pk-debconf-helper.service inactive\n```\n\nCheck out [units](cmd/units/main.go) program to see how to get PIDs of services.\n\n```sh\n$ go run ./cmd/units -svc\n0 dirmngr.service inactive\n2375 dbus.service active\n0 snapd.session-agent.service inactive\n0 gpg-agent.service inactive\n0 pk-debconf-helper.service inactive\n```\n\nYou can get the same results with `dbus-send`.\n\n```sh\n$ dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.ListUnits\n$ dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/dbus_2eservice org.freedesktop.DBus.Properties.Get string:'org.freedesktop.systemd1.Service' string:'MainPID'\n```\n\n## Testing\n\nRun tests and linters.\n\n```sh\n$ go test -v -count=1 .\n$ golangci-lint run\n```\n\nBenchmarks help to spot performance changes\nand troubleshoot performance issues.\nFor example, you can see where and how much memory gets allocated\nwhen a 35KB D-Bus ListUnits reply is decoded into 157 Unit structs.\n\n```sh\n$ go test -run=^$ -bench=^BenchmarkDecodeListUnits$ -benchmem -memprofile list_units.allocs\n$ go tool pprof list_units.allocs\n```\n\nIt is recommended to run benchmarks multiple times and check\nhow stable they are using [Benchstat](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat) tool.\n\n```sh\n$ go test -timeout 20m -bench=. -benchmem -count=50 . | tee bench-new.txt\n$ benchstat bench-new.txt\n```\n\n[The old](bench-old.txt) and new stats are compared as follows.\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\n\n```sh\n$ benchstat bench-old.txt bench-new.txt\n```\n\n\u003c/summary\u003e\n\n```\nname               old time/op    new time/op    delta\nAuthExternal-2        475ns ± 2%     467ns ± 2%    -1.72%  (p=0.000 n=46+45)\nDecodeString-2       54.3ns ± 3%    53.4ns ± 4%    -1.67%  (p=0.000 n=49+50)\nEscapeBusLabel-2     43.8ns ± 2%    43.2ns ± 2%    -1.35%  (p=0.000 n=48+50)\nDecodeHeader-2        340ns ± 4%     340ns ±12%    -0.17%  (p=0.017 n=48+45)\nEncodeHeader-2        185ns ± 1%     187ns ± 3%    +1.28%  (p=0.000 n=48+49)\nEncodeHello-2         224ns ± 2%     221ns ± 3%    -1.03%  (p=0.000 n=46+50)\nDecodeHello-2         122ns ± 4%      84ns ±11%   -31.21%  (p=0.000 n=49+49)\nEncodeMainPID-2       383ns ± 4%     383ns ± 3%      ~     (p=0.548 n=43+48)\nDecodeMainPID-2       140ns ± 2%      96ns ± 3%   -31.63%  (p=0.000 n=48+50)\nEncodeListUnits-2     234ns ± 2%     236ns ± 2%    +0.61%  (p=0.001 n=41+47)\nDecodeListUnits-2    92.9µs ± 2%    92.5µs ± 5%    -0.39%  (p=0.028 n=48+45)\n\nname               old alloc/op   new alloc/op   delta\nAuthExternal-2        80.0B ± 0%     80.0B ± 0%      ~     (all equal)\nDecodeString-2        0.00B          0.00B           ~     (all equal)\nEscapeBusLabel-2      0.00B          0.00B           ~     (all equal)\nDecodeHeader-2        15.0B ± 0%     15.0B ± 0%      ~     (all equal)\nEncodeHeader-2        0.00B          0.00B           ~     (all equal)\nEncodeHello-2         0.00B          0.00B           ~     (all equal)\nDecodeHello-2         29.0B ± 0%      5.0B ± 0%   -82.76%  (p=0.000 n=50+50)\nEncodeMainPID-2       45.0B ± 0%     45.0B ± 0%      ~     (all equal)\nDecodeMainPID-2       24.0B ± 0%      0.0B       -100.00%  (p=0.000 n=50+50)\nEncodeListUnits-2     0.00B          0.00B           ~     (all equal)\nDecodeListUnits-2    21.0kB ± 0%    20.9kB ± 0%    -0.11%  (p=0.000 n=50+50)\n\nname               old allocs/op  new allocs/op  delta\nAuthExternal-2         3.00 ± 0%      3.00 ± 0%      ~     (all equal)\nDecodeString-2         0.00           0.00           ~     (all equal)\nEscapeBusLabel-2       0.00           0.00           ~     (all equal)\nDecodeHeader-2         0.00           0.00           ~     (all equal)\nEncodeHeader-2         0.00           0.00           ~     (all equal)\nEncodeHello-2          0.00           0.00           ~     (all equal)\nDecodeHello-2          1.00 ± 0%      0.00       -100.00%  (p=0.000 n=50+50)\nEncodeMainPID-2        0.00           0.00           ~     (all equal)\nDecodeMainPID-2        1.00 ± 0%      0.00       -100.00%  (p=0.000 n=50+50)\nEncodeListUnits-2      0.00           0.00           ~     (all equal)\nDecodeListUnits-2      6.00 ± 0%      5.00 ± 0%   -16.67%  (p=0.000 n=50+50)\n```\n\n\u003c/details\u003e\n\nWhen there is a statistically significant improvement,\nplease update [bench-old.txt](bench-old.txt) and the benchmark results above.\n\n```sh\n$ cp bench-new.txt bench-old.txt\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarselester%2Fsystemd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarselester%2Fsystemd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarselester%2Fsystemd/lists"}