osal.systemd #
a sal to work with systemd
only basics implemented as we need for our installers
example see crystallib/examples/...
fn check #
fn check() !bool
check if systemd is on system, returns True if yes
fn journalctl #
fn journalctl(args JournalArgs) !string
fn new #
fn new() !Systemd
fn process_list #
fn process_list() ![]SystemdProcessInfo
enum ActiveState #
enum ActiveState {
active // The unit has been started successfully and is running as expected.
inactive // The unit is not running.
activating // The unit is in the process of being started.
deactivating // The unit is in the process of being stopped.
failed // The unit tried to start but failed.
}
enum LoadState #
enum LoadState {
loaded // The unit's configuration file has been successfully loaded into memory.
not_found // The unit's configuration file could not be found.
error // There was an error loading the unit's configuration file.
masked // The unit has been masked, which means it has been explicitly disabled and cannot be started.
}
enum SubState #
enum SubState {
unknown
start
running // The service is currently running.
exited // The service has completed its process and exited. For services that do something at startup and then exit (oneshot services), this is a normal state.
failed // The service has failed after starting.
waiting // The service is waiting for some condition to be met.
autorestart
dead
}
This provides more detailed information about the unit's state, often referred to as the "sub-state". This can vary significantly between different types of units (services, sockets, timers, etc.)
struct JournalArgs #
struct JournalArgs {
pub:
service string // name of service for which logs will be retrieved
limit int = 100 // number of last log lines to be shown
}
struct Systemd #
@[heap]
struct Systemd {
pub mut:
processes []&SystemdProcess
path pathlib.Path
path_cmd pathlib.Path
}
import freeflowuniverse.crystallib.clients.redisclient
fn (Systemd) new #
fn (mut systemd Systemd) new(args_ SystemdProcessNewArgs) !SystemdProcess
name string @[required]
cmd string @[required]
description string @[required]
fn (Systemd) names #
fn (mut systemd Systemd) names() []string
fn (Systemd) get #
fn (mut systemd Systemd) get(name_ string) !&SystemdProcess
fn (Systemd) exists #
fn (mut systemd Systemd) exists(name_ string) bool
struct SystemdProcess #
@[heap]
struct SystemdProcess {
pub mut:
name string
unit string // as generated or used by systemd
cmd string
pid int
env map[string]string
systemd &Systemd @[skip; str: skip]
description string
info SystemdProcessInfo
restart bool = true // whether process will be restarted upon failure
}
fn (SystemdProcess) servicefile_path #
fn (mut self SystemdProcess) servicefile_path() string
fn (SystemdProcess) write #
fn (mut self SystemdProcess) write() !
fn (SystemdProcess) start #
fn (mut self SystemdProcess) start() !
fn (SystemdProcess) refresh #
fn (mut self SystemdProcess) refresh() !
get status from system
fn (SystemdProcess) delete #
fn (mut self SystemdProcess) delete() !
fn (SystemdProcess) stop #
fn (mut self SystemdProcess) stop() !
fn (SystemdProcess) restart #
fn (mut self SystemdProcess) restart() !
fn (SystemdProcess) status #
fn (self SystemdProcess) status() !SystemdStatus
struct SystemdProcessInfo #
struct SystemdProcessInfo {
pub mut:
unit string
load_state LoadState
active_state ActiveState
sub_state SubState
description string
}
struct SystemdProcessNewArgs #
@[params]
struct SystemdProcessNewArgs {
pub mut:
name string @[required]
cmd string @[required]
description string
env map[string]string
start bool = true
restart bool = true
}