mirror of
https://github.com/taigrr/systemctl.git
synced 2026-04-13 15:58:01 -07:00
Compare commits
1 Commits
master
...
cd/update-
| Author | SHA1 | Date | |
|---|---|---|---|
| d9d3887e81 |
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: ["1.26"]
|
go-version: ["1.26", "1.26.2"]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
run: sudo go test -race -coverprofile=coverage-root.out -covermode=atomic ./...
|
run: sudo go test -race -coverprofile=coverage-root.out -covermode=atomic ./...
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
if: matrix.go-version == '1.26'
|
if: matrix.go-version == '1.26.2'
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v5
|
||||||
with:
|
with:
|
||||||
files: coverage-user.out,coverage-root.out
|
files: coverage-user.out,coverage-root.out
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ If your system isn't running (or targeting another system running) `systemctl`,
|
|||||||
- [x] Get current memory in bytes (`MemoryCurrent`) as an int
|
- [x] Get current memory in bytes (`MemoryCurrent`) as an int
|
||||||
- [x] Get the PID of the main process (`MainPID`) as an int
|
- [x] Get the PID of the main process (`MainPID`) as an int
|
||||||
- [x] Get the restart count of a unit (`NRestarts`) as an int
|
- [x] Get the restart count of a unit (`NRestarts`) as an int
|
||||||
|
- [x] List all loaded units and their states (`list-units`)
|
||||||
|
- [x] List masked units (`list-unit-files --state=masked`)
|
||||||
|
- [x] Get sockets associated with a service unit (`list-sockets`)
|
||||||
|
- [x] Check if a unit is masked
|
||||||
|
- [x] Check if a unit is running (sub-state)
|
||||||
|
- [x] Check if systemd is the init system (`/proc/1/comm`)
|
||||||
|
- [x] Validate unit name suffixes against known systemd unit types
|
||||||
|
|
||||||
|
|
||||||
## Useful errors
|
## Useful errors
|
||||||
@@ -55,7 +62,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module github.com/taigrr/systemctl
|
module github.com/taigrr/systemctl
|
||||||
|
|
||||||
go 1.26.1
|
go 1.26.2
|
||||||
|
|||||||
15
helpers.go
15
helpers.go
@@ -74,10 +74,7 @@ func GetPID(ctx context.Context, unit string, opts Options) (int, error) {
|
|||||||
|
|
||||||
// GetSocketsForServiceUnit returns the socket units associated with a given service unit.
|
// GetSocketsForServiceUnit returns the socket units associated with a given service unit.
|
||||||
func GetSocketsForServiceUnit(ctx context.Context, unit string, opts Options) ([]string, error) {
|
func GetSocketsForServiceUnit(ctx context.Context, unit string, opts Options) ([]string, error) {
|
||||||
args := []string{"list-sockets", "--all", "--no-legend", "--no-pager"}
|
args := prepareArgs("list-sockets", opts, "--all", "--no-legend", "--no-pager")
|
||||||
if opts.UserMode {
|
|
||||||
args = append(args, "--user")
|
|
||||||
}
|
|
||||||
stdout, _, _, err := execute(ctx, args)
|
stdout, _, _, err := execute(ctx, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, err
|
return []string{}, err
|
||||||
@@ -100,10 +97,7 @@ func GetSocketsForServiceUnit(ctx context.Context, unit string, opts Options) ([
|
|||||||
|
|
||||||
// GetUnits returns a list of all loaded units and their states.
|
// GetUnits returns a list of all loaded units and their states.
|
||||||
func GetUnits(ctx context.Context, opts Options) ([]Unit, error) {
|
func GetUnits(ctx context.Context, opts Options) ([]Unit, error) {
|
||||||
args := []string{"list-units", "--all", "--no-legend", "--full", "--no-pager"}
|
args := prepareArgs("list-units", opts, "--all", "--no-legend", "--full", "--no-pager")
|
||||||
if opts.UserMode {
|
|
||||||
args = append(args, "--user")
|
|
||||||
}
|
|
||||||
stdout, stderr, _, err := execute(ctx, args)
|
stdout, stderr, _, err := execute(ctx, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []Unit{}, errors.Join(err, filterErr(stderr))
|
return []Unit{}, errors.Join(err, filterErr(stderr))
|
||||||
@@ -129,10 +123,7 @@ func GetUnits(ctx context.Context, opts Options) ([]Unit, error) {
|
|||||||
|
|
||||||
// GetMaskedUnits returns a list of all masked unit names.
|
// GetMaskedUnits returns a list of all masked unit names.
|
||||||
func GetMaskedUnits(ctx context.Context, opts Options) ([]string, error) {
|
func GetMaskedUnits(ctx context.Context, opts Options) ([]string, error) {
|
||||||
args := []string{"list-unit-files", "--state=masked"}
|
args := prepareArgs("list-unit-files", opts, "--state=masked")
|
||||||
if opts.UserMode {
|
|
||||||
args = append(args, "--user")
|
|
||||||
}
|
|
||||||
stdout, stderr, _, err := execute(ctx, args)
|
stdout, stderr, _, err := execute(ctx, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, errors.Join(err, filterErr(stderr))
|
return []string{}, errors.Join(err, filterErr(stderr))
|
||||||
|
|||||||
Reference in New Issue
Block a user