[`sysctl(8)`](https://man7.org/linux/man-pages/man8/sysctl.8.html) is a utility on Unix-like operating systems that is used to read and modify the attributes of the kernel such as its version number, maximum limits, and security settings[\*](https://en.wikipedia.org/wiki/Sysctl). **systeroid** is "_sysctl on steroids_". It can do everything that sysctl does and even more. It provides a safer, more performant, and user-friendly CLI/TUI for managing the kernel parameters at runtime.
**systeroid** is implemented using [procfs](https://en.wikipedia.org/wiki/Procfs) which is the virtual file system that is typically mapped to a mount point named `/proc` at boot time. This means checking the value of some kernel parameter requires opening a file in this virtual filesystem, reading its contents, parsing them, and closing the file. In [Linux](https://en.wikipedia.org/wiki/Linux), these dynamically configurable kernel options are available under `/proc/sys` which contains directories representing the sections of the kernel and readable/writable virtual files. For example, to enable/disable IP forwarding, `1` or `0` could be written in `/proc/sys/net/ipv4/ip_forward` or `systeroid ip_forward=1` command can be used to change the value of the parameter.
<ahref="assets/systeroid-demo.gif">
<imgsrc="assets/systeroid-demo.gif"width="800">
</a>
Although **systeroid** does not need the parameter section to be specified explicitly, it is important to know the sections and their areas of impact. Here are the available kernel sections according to the [Linux kernel documentation](https://www.kernel.org/doc/html/latest/admin-guide/sysctl/index.html):
**systeroid** can be installed from the [community repository](https://archlinux.org/packages/community/x86_64/systeroid/) using [pacman](https://wiki.archlinux.org/title/Pacman):
See available [releases](https://github.com/orhun/systeroid/releases) that are automated by [Continuous Deployment](.github/workflows/cd.yml) workflow.
### Building from source
```sh
# clone the repository
git clone https://github.com/orhun/systeroid && cd systeroid/
# binaries will be located at:
# - target/release/systeroid
# - target/release/systeroid-tui
CARGO_TARGET_DIR=target cargo build --release
```
Also see [requirements](#requirements).
### Docker
#### Images
Docker builds are [automated](./.github/workflows/docker.yml) and images are available in the following registries:
The following command can be used to interactively view the documentation of selected parameters:
```sh
docker run --rm -it "orhunp/systeroid:${TAG:-latest}" --tui
```
Docker containers share the host system's kernel and its settings thus access to `/proc` and `/sys` are restricted for security. That is why it is not possible (and not recommended) to tweak the kernel parameters within a container. [\*](https://stackoverflow.com/questions/54845095/cannot-run-sysctl-command-in-dockerfile)
#### Building
Custom Docker images can be built from the [Dockerfile](./Dockerfile):
**systeroid** can dump the parameter information from the kernel documentation. This is useful if you don't know what a parameter is used for.
```sh
# show information about a parameter
systeroid --explain oom_dump_tasks
```
Kernel documentation should be present in one of the following paths for parsing upon first launch:
-`/usr/share/doc/linux`
-`/usr/share/doc/linux-doc`
-`/usr/share/doc/linux-docs`
-`/usr/share/doc/kernel-doc-*/Documentation`
Then the parsed data is cached in `$HOME/.cache/systeroid-core` and used from there as long as the documentation is not updated. The caching mechanism can be disabled via setting the `NO_CACHE` environment variable.
This is a design choice due to the fact that different versions of kernels might be installed on different systems so the documentation might be too new or old if **systeroid** was to be shipped with a fixed set of parameter descriptions bundled in. With the parsing approach, documentation is always kept up-to-date.
However, this means you need to:
- either install the kernel documentation package (based on your distribution)
- or explicitly specify the path of the [kernel documentation](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide).
```sh
# specify the kernel documentation path explicitly
# (not needed if you have the kernel documentation installed as a package)
| <kbd>enter</kbd> | select / set parameter value |
| <kbd>c</kbd> | copy to clipboard |
| <kbd>r</kbd>, <kbd>f5</kbd> | refresh |
| <kbd>esc</kbd> | cancel / exit |
| <kbd>q</kbd>, <kbd>ctrl-c/ctrl-d</kbd> | exit |
### Examples
#### Launching
Simply run `systeroid-tui` to launch the terminal user interface. Alternatively, you can use `systeroid --tui` command (which runs `systeroid-tui` under the hood if it is found in [`PATH`](<https://en.wikipedia.org/wiki/PATH_(variable)>)).
#### Showing help
Help menu and key bindings can be shown via pressing <kbd>?</kbd>:
![Help](assets/systeroid-tui-help.gif)
#### Scrolling
Use <kbd>up/down</kbd> keys to scroll the parameter list. Alternatively, use <kbd>t/b</kbd> to scroll to the top/bottom.
| `:select` | Select the current parameter in the list |
| `:set <name> <value>` | Set parameter value |
| `:scroll [area] [direction] <amount>` | Scroll the list or text<br>- areas: `list`, `docs`, `section`<br>- directions: `up`, `down`, `top`, `bottom`, `right`, `left` |
| `:copy` | Copy to clipboard |
| `:refresh` | Refresh values |
| `:quit`, `:q` | Quit |
#### Copying to clipboard
Press <kbd>c</kbd> to show the options menu for copying the name, value, or documentation of the selected parameter.
![Copy to clipboard](assets/systeroid-tui-copy.gif)
\* **systeroid-tui** should be built with `clipboard` feature for enabling the clipboard support.
#### Changing the colors
Use `--bg-color` and `--fg-color` arguments to customize the colors of the terminal user interface.
```sh
# use a color name for setting the foreground color
systeroid-tui --fg-color blue
# use hexadecimal values for setting foreground/background colors
systeroid-tui --bg-color ffff99 --fg-color 003366
```
![Change colors](assets/systeroid-tui-colors.gif)
#### Viewing the parameter documentation
To view the documentation as parameters are being selected on the list, kernel documentation should be parsed as explained in the "[Showing information about parameters](#showing-information-about-parameters)" section. A specific path for kernel documentation can be given via `--docs` argument or `KERNEL_DOCS` environment variable if it is not found in one of the locations that are checked as default.
To disable this feature altogether, use `--no-docs` flag.
#### Setting the refresh rate
It is possible to specify a value in milliseconds via `--tick-rate` argument for tweaking the refresh rate of the terminal which might be necessary in some cases where better performance is desired.
**systeroid** logo was originally painted by [Ryan Tippery](https://ryantippery.com) as a part of the [Compositions](https://ryantippery.com/art/compositions) art collection and it is put together by me using the [Filled Spots](https://www.fontspace.com/filled-spots-font-f30755) font. Shout out to Ryan for letting me use his painting for the logo! **<3**Kudos!
If you find **systeroid** and/or other projects on my [GitHub profile](https://github.com/orhun/) useful, consider [becoming a patron](https://www.patreon.com/join/orhunp)!
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dorhunp%26type%3Dpatrons&style=flat&logo=Patreon&labelColor=000000&color=CECDCB&logoColor=CECDCB)](https://patreon.com/join/orhunp)
[![Support me on Patreon](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dorhunp%26type%3Dpledges&style=flat&logo=Patreon&labelColor=000000&color=CECDCB&logoColor=CECDCB&label=)](https://patreon.com/join/orhunp)
## Contributing
See our [Contribution Guide](./CONTRIBUTING.md) and please follow the [Code of Conduct](./CODE_OF_CONDUCT.md) in all your interactions with the project.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache 2.0 License, shall be dual licensed as above, without any additional terms or conditions.
## License
Licensed under either of [Apache License Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or [The MIT License](http://opensource.org/licenses/MIT) at your option.