preliminary version of enable complete
This commit is contained in:
parent
f9f44604e1
commit
2517125d98
@ -14,4 +14,7 @@ var (
|
|||||||
|
|
||||||
// ErrInsufficientPermissions means the calling executable was invoked without enough permissions to run the selected command
|
// ErrInsufficientPermissions means the calling executable was invoked without enough permissions to run the selected command
|
||||||
ErrInsufficientPermissions = errors.New("insufficient permissions for action")
|
ErrInsufficientPermissions = errors.New("insufficient permissions for action")
|
||||||
|
|
||||||
|
// ErrDoesNotExist means the unit specified doesn't exist or can't be found
|
||||||
|
ErrDoesNotExist = errors.New("Unit does not exist")
|
||||||
)
|
)
|
||||||
|
48
systemctl.go
48
systemctl.go
@ -1,68 +1,88 @@
|
|||||||
package systemctl
|
package systemctl
|
||||||
|
|
||||||
import "context"
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func IsFailed(ctx context.Context, unit string) (bool, error) {
|
func IsFailed(ctx context.Context, unit string, usermode bool) (bool, error) {
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func IsActive(ctx context.Context, unit string) (bool, error) {
|
func IsActive(ctx context.Context, unit string, usermode bool) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Status(ctx context.Context, unit string) (bool, error) {
|
func Status(ctx context.Context, unit string, usermode bool) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Restart(ctx context.Context, unit string) error {
|
func Restart(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Start(ctx context.Context, unit string) error {
|
func Start(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Stop(ctx context.Context, unit string) error {
|
func Stop(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Enable(ctx context.Context, unit string) error {
|
func Enable(ctx context.Context, unit string, usermode bool) error {
|
||||||
|
var args = []string{"enable", "--system", unit}
|
||||||
|
if usermode {
|
||||||
|
args[1] = "--user"
|
||||||
|
}
|
||||||
|
_, stderr, code, err := execute(ctx, args)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = filterErr(stderr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if code != 0 {
|
||||||
|
return errors.New("received error code " + strconv.Itoa(code))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func Disable(ctx context.Context, unit string) error {
|
func Disable(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func IsEnabled(ctx context.Context, unit string) (bool, error) {
|
func IsEnabled(ctx context.Context, unit string, usermode bool) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
func DaemonReload(ctx context.Context, unit string) error {
|
func DaemonReload(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
func Show(ctx context.Context, unit string, property string) (string, error) {
|
func Show(ctx context.Context, unit string, property string, usermode bool) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
func Mask(ctx context.Context, unit string) error {
|
func Mask(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unmask(ctx context.Context, unit string) error {
|
func Unmask(ctx context.Context, unit string, usermode bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
10
util.go
10
util.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var systemctl string
|
var systemctl string
|
||||||
@ -38,3 +39,12 @@ func execute(ctx context.Context, args []string) (string, string, int, error) {
|
|||||||
|
|
||||||
return output, warnings, code, err
|
return output, warnings, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterErr(stderr string) error {
|
||||||
|
matched, _ := regexp.MatchString(`does not exist`, stderr)
|
||||||
|
if matched {
|
||||||
|
return ErrDoesNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user