Go API Documentation

github.com/caddyserver/caddy/v2/notify

Package notify provides facilities for notifying process managers of state changes, mainly for when running as a system service.

Package

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Vars

var socketPath, _ = os.LookupEnv("NOTIFY_SOCKET")

Functions

func Error

Error is like Status, but sends systemd an error message instead, with an optional errno-style error number.

func Error(err error, errno int) error {
	collapsedErr := strings.ReplaceAll(err.Error(), "\n", " ")
	msg := fmt.Sprintf("STATUS=%s", collapsedErr)
	if errno > 0 {
		msg += fmt.Sprintf("\nERRNO=%d", errno)
	}
	return sdNotify(msg)
}

Cognitive complexity: 2, Cyclomatic complexity: 2

Uses: fmt.Sprintf, strings.ReplaceAll.

func Ready

Ready notifies systemd that caddy has finished its initialization routines.

func Ready() error {
	return sdNotify("READY=1")
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func Reloading

Reloading notifies systemd that caddy is reloading its config.

func Reloading() error {
	return sdNotify("RELOADING=1")
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func Status

Status sends systemd an updated status message.

func Status(msg string) error {
	return sdNotify("STATUS=" + msg)
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func Stopping

Stopping notifies systemd that caddy is stopping.

func Stopping() error {
	return sdNotify("STOPPING=1")
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func sdNotify

sdNotify (payload string) error
References: net.DialUnix, net.UnixAddr.