module

package
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	SystemdScopeSystem = "system"
	SystemdScopeUser   = "user"
	SystemdScopeGlobal = "global"
)

scope can be either "system", "user" or "global"

View Source
const (

	// UserActionAdd
	UserActionAdd = "add"
	UserActionDel = "del"
)
View Source
const (
	// DefaultSystemdSleepTime unit: seconds
	DefaultSystemdSleepTime = 1
	// DefaultSystemdExecuteTimeout unit: seconds
	DefaultSystemdExecuteTimeout = 60
)

Variables

View Source
var (
	ErrUserAddFailed    = errNSUser.NewType("user_add_failed")
	ErrUserDeleteFailed = errNSUser.NewType("user_delete_failed")
)

Functions

func Retry

func Retry(doFunc func() error, opts ...RetryOption) error

Retry retries the func until it returns no error or reaches attempts limit or timed out, either one is earlier

Types

type LaunchdModule

type LaunchdModule struct {
	// contains filtered or unexported fields
}

LaunchdModule is the module used to control systemd units

func NewLaunchdModule

func NewLaunchdModule(config LaunchdModuleConfig) *LaunchdModule

NewLaunchdModule builds and returns a LaunchdModule object base on given config.

func (*LaunchdModule) Execute

func (mod *LaunchdModule) Execute(ctx context.Context, exec executor.Executor) ([]byte, []byte, error)

Execute passes the command to executor and returns its results, the executor should be already initialized.

type LaunchdModuleConfig

type LaunchdModuleConfig struct {
	Unit        string        // the name of systemd unit(s)
	Action      string        // the action to perform with the unit
	Timeout     time.Duration // timeout to execute the command
	SystemdMode string
}

LaunchdModuleConfig is the configurations used to initialize a LaunchdModule

type RetryOption

type RetryOption struct {
	Attempts int64
	Delay    time.Duration
	Timeout  time.Duration
}

RetryOption is options for Retry()

type ShellModule

type ShellModule struct {
	// contains filtered or unexported fields
}

ShellModule is the module used to control systemd units

func NewShellModule

func NewShellModule(config ShellModuleConfig) *ShellModule

NewShellModule builds and returns a ShellModule object base on given config.

func (*ShellModule) Execute

func (mod *ShellModule) Execute(ctx context.Context, exec executor.Executor) ([]byte, []byte, error)

Execute passes the command to executor and returns its results, the executor should be already initialized.

type ShellModuleConfig

type ShellModuleConfig struct {
	Command  string // the command to run
	Sudo     bool   // whether use root privilege to run the command
	Chdir    string // change working directory before running the command
	UseShell bool   // whether use shell to invoke the command
}

ShellModuleConfig is the configurations used to initialize

type SystemdModule

type SystemdModule struct {
	// contains filtered or unexported fields
}

SystemdModule is the module used to control systemd units

func NewSystemdModule

func NewSystemdModule(config SystemdModuleConfig) *SystemdModule

NewSystemdModule builds and returns a SystemdModule object base on given config.

func (*SystemdModule) Execute

func (mod *SystemdModule) Execute(ctx context.Context, exec executor.Executor) ([]byte, []byte, error)

Execute passes the command to executor and returns its results, the executor should be already initialized.

type SystemdModuleConfig

type SystemdModuleConfig struct {
	Unit         string        // the name of systemd unit(s)
	Action       string        // the action to perform with the unit
	ReloadDaemon bool          // run daemon-reload before other actions
	CheckActive  bool          // run is-active before action
	Scope        string        // user, system or global
	Force        bool          // add the `--force` arg to systemctl command
	Signal       string        // specify the signal to send to process
	Timeout      time.Duration // timeout to execute the command
	SystemdMode  string
}

SystemdModuleConfig is the configurations used to initialize a SystemdModule

type UserModule

type UserModule struct {
	// contains filtered or unexported fields
}

UserModule is the module used to control systemd units

func NewUserModule

func NewUserModule(config UserModuleConfig) *UserModule

func (*UserModule) Execute

func (mod *UserModule) Execute(ctx context.Context, exec executor.Executor) ([]byte, []byte, error)

Execute passes the command to the executor and returns its result. The executor should have been initialized

type UserModuleConfig

type UserModuleConfig struct {
	OS     string // OS Version
	Action string // Create, delete or change users
	Name   string // username
	Group  string // user group
	Home   string // user home
	Shell  string // user login shell
	Sudoer bool   // When true, the user will be added to the sudoers list
}

UserModuleConfig is the configuration used to initialize UserModule

type WaitFor

type WaitFor struct {
	// contains filtered or unexported fields
}

WaitFor is the module used to wait for some condition.

func NewWaitFor

func NewWaitFor(c WaitForConfig) *WaitFor

NewWaitFor create a WaitFor instance.

func (*WaitFor) Execute

func (w *WaitFor) Execute(ctx context.Context, e executor.Executor) (err error)

Execute the module return nil if successfully wait for the event.

type WaitForConfig

type WaitForConfig struct {
	OS    string        // OS version
	Port  int           // Port number to poll.
	Sleep time.Duration // Duration to sleep between checks, default 1 second.
	// Choices:
	// started
	// stopped
	// When checking a port started will ensure the port is open, stopped will check that it is closed
	State   string
	Timeout time.Duration // Maximum duration to wait for.
}

WaitForConfig is the configurations of WaitFor module.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL