god

package module
v0.0.0-...-ab8191b Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Latest release GitHub go.mod Go version of a Go module GoDoc reference example GitHub license

Go-d

Caution: This is a work in progress.

This package is a wrapper for the systemd and launchd services manager.

It uses golang build contraints to automatically determine which manager to use.

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"

	"github.com/holyhope/god"
	_ "github.com/holyhope/god/launchd"
)

func main() {
	unit, err := god.New(
		context.Background(),
		god.Opts().
			WithName("com.github.holyhope.test.god_example").
			WithProgram("/bin/bash").
			WithArguments("-c", `echo "Hello, world!"`).
			WithScope(god.ScopeUser),
	)
	if err != nil {
		panic(err)
	}

	// Install the unit to the system
	_ = unit.Create(context.Background())

	fmt.Println("Unit installed")

	// Enable the unit
	_ = unit.Enable(context.Background())

	fmt.Println("Unit enabled")

	// Delete the unit to the system
	_ = unit.Delete(context.Background())

	fmt.Println("Unit uninstalled")

}
Output:

Unit installed
Unit enabled
Unit uninstalled

Index

Examples

Constants

This section is empty.

Variables

Functions

func NewMissingOptionError

func NewMissingOptionError(key string) error

Types

type DarwinLimitLoadToSessionType

type DarwinLimitLoadToSessionType uint8

https://developer.apple.com/library/archive/technotes/tn2083/_index.html#//apple_ref/doc/uid/DTS10003794-CH1-SUBSUBSECTION5

const (
	DarwinLimitLoadToSessionAqua DarwinLimitLoadToSessionType = iota
	DarwinLimitLoadToSessionStandardIO
	DarwinLimitLoadToSessionBackground
	DarwinLimitLoadToSessionLoginWindow
)

func (DarwinLimitLoadToSessionType) String

type DarwinOptions

type DarwinOptions interface {
	// contains filtered or unexported methods
}

type InvalidOptionError

type InvalidOptionError struct {
	Key   string
	Value interface{}
}

func (*InvalidOptionError) Error

func (err *InvalidOptionError) Error() string

func (*InvalidOptionError) Is

func (err *InvalidOptionError) Is(err2 error) bool

type MissingOptionError

type MissingOptionError InvalidOptionError

func (*MissingOptionError) Error

func (err *MissingOptionError) Error() string

type Options

type Options interface {
	DarwinOptions
	// contains filtered or unexported methods
}
Example
package main

import (
	"context"

	"github.com/holyhope/god"
	_ "github.com/holyhope/god/launchd"
)

func main() {
	u, _ := god.New(
		context.Background(),
		god.Opts().
			WithName("my-unit").
			WithScope(god.ScopeUser),
	)

	_ = u.Create(context.Background())
	_ = u.Enable(context.Background())

	// Cleanup filesystem
	_ = u.Delete(context.Background())
}
Output:

func Opts

func Opts() Options

type Scope

type Scope uint8

ScopeValue is the scope of the unit.

const (
	ScopeUser Scope = iota
	ScopeSystem
)

func (Scope) String

func (i Scope) String() string

type State

type State uint8

ScopeValue is the scope of the unit.

const (
	StateEnable State = iota
	StateDisable
)

func (State) String

func (i State) String() string

type Unit

type Unit interface {
	// Create the unit to the system.
	Create(ctx context.Context) error
	// Enable the unit.
	Enable(ctx context.Context) error
	// Delete the unit from the system.
	Delete(ctx context.Context) error
	// Disable the unit.
	Disable(ctx context.Context) error
	// Status the status of the unit.
	Status(ctx context.Context) (UnitStatus, error)
}

Unit represents single service managed by either systemd or launchd.

func New

func New(_ context.Context, _ ...FactoryOpts) (Unit, error)

New creates a new Unit.

Example
package main

import (
	"context"
	"fmt"

	"github.com/holyhope/god"
	_ "github.com/holyhope/god/launchd"
)

func main() {
	god.New(context.Background(), god.Opts().WithName("test"))

	fmt.Printf("New god object created")

}
Output:

New god object created

type UnitStatus

type UnitStatus interface {
	// Exists returns true if the unit is on the filesystem.
	Exists(ctx context.Context) bool
	// IsEnabled returns true if the unit is enable.
	IsEnabled(ctx context.Context) bool
}

func NewUnitStatus

func NewUnitStatus(exists bool, enabled bool) UnitStatus

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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