sysctl

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

README

Go Sysctl

GoDoc Build Status Go Report Card License

Golang wrapper around the sysctl interface.

Documentation

See Go doc.

Example

import sysctl "github.com/lorenzosaino/go-sysctl"

// Get value of a single sysctl
// This is equivalent to running "sysctl <key>"
val, err := sysctl.Get("net.ipv4.ip_forward")

// Get the values of all sysctls matching a given pattern
// This is equivalent to running "sysctl -a -r <pattern>"
vals, err := sysctl.GetPattern("net.ipv4.ipfrag")

// Get the values of all sysctls
// This is equivalent to running "sysctl -a"
vals, err = sysctl.GetAll()

// Set the value of a sysctl
// This is equivalent to running "sysctl -w <key>=<value>"
err = sysctl.Set("net.ipv4.ip_forward", "1")

// Set sysctl values from configuration file
// This is equivalent to running "sysctl -p <config-file>"
err = sysctl.LoadConfigAndApply("/etc/sysctl.conf")

Documentation

Overview

Package sysctl provides functions wrapping the sysctl interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string) (string, error)

Get returns a sysctl from a given key.

func GetAll

func GetAll() (map[string]string, error)

GetAll returns all sysctls. This is equivalent to running the command sysctl -a.

func GetPattern

func GetPattern(pattern string) (map[string]string, error)

GetPattern returns a map of sysctls matching a given pattern The pattern uses a POSIX extended regular expression syntax. This function matches the same sysctls that the command sysctl -a -r <pattern> would return.

func LoadConfig

func LoadConfig(files ...string) (map[string]string, error)

LoadConfig gets sysctl values from a list of sysctl configuration files. The values in the rightmost files take priority. If no file is specified, values are read from /etc/sysctl.conf.

func LoadConfigAndApply

func LoadConfigAndApply(files ...string) error

LoadConfigAndApply sets sysctl values from a list of sysctl configuration files. The values in the rightmost files take priority. If no file is specified, values are read from /etc/sysctl.conf.

func Set

func Set(key, value string) error

Set updates the value of a sysctl.

Types

This section is empty.

Jump to

Keyboard shortcuts

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