Skip to content

osal.zinit #

a sal to work with zinit

Easy reliable way how to work with processes

Example

import freeflowuniverse.crystallib.osal.zinit

fn main() {
    do() or { panic(err) }
}

fn do() ! {
    mut z:=zinit.get()!

    z.destroy()!

    // name      string            @[required]
    // cmd       string            @[required]
    // cmd_file  bool  //if we wanna force to run it as a file which is given to bash -c  (not just a cmd in zinit)
    // test      string
    // test_file bool
    // after     []string
    // env       map[string]string
    // oneshot   bool
    p:=z.new(
        name:'test'
        cmd:'/bin/bash'
    )!

    output:=p.log()!
    println(output)

    p.check()! //will check the process is up and running

    p.stop()!

}

protocol defined in

sal on top of https://github.com/threefoldtech/zinit/tree/master

https://github.com/threefoldtech/zinit/blob/master/docs/protocol.md

fn check #

fn check() bool

fn destroy #

fn destroy() !

remove all know services to zinit

fn new #

fn new() !&Zinit

fn new_rpc_client #

fn new_rpc_client(args ZinitClientArgs) Client

enum ZProcessStatus #

enum ZProcessStatus {
	unknown
	init
	ok
	killed
	error
	blocked
	spawned
}

struct Client #

struct Client {
	socket_path string = '/var/run/zinit.sock'
}

these need to be all private (non pub)

struct ZProcess #

struct ZProcess {
pub:
	name string = 'default'
pub mut:
	cmd         string // command to start
	test        string // command line to test service is running
	status      ZProcessStatus
	pid         int
	after       []string // list of service we depend on
	env         map[string]string
	oneshot     bool
	start       bool = true
	restart     bool = true // whether the process should be restarted on failure
	description string // not used in zinit
}

fn (ZProcess) check #

fn (mut zp ZProcess) check() !

will check that process is running

fn (ZProcess) cmd #

fn (zp ZProcess) cmd() string

fn (ZProcess) cmdtest #

fn (zp ZProcess) cmdtest() string

fn (ZProcess) destroy #

fn (mut zp ZProcess) destroy() !

fn (ZProcess) isrunning #

fn (mut zp ZProcess) isrunning() !bool

will check that process is running

fn (ZProcess) load #

fn (mut zp ZProcess) load() !

fn (ZProcess) log #

fn (zp ZProcess) log() !string

check if process is running if yes return the log

fn (ZProcess) output_wait #

fn (mut zp ZProcess) output_wait(c_ string, timeoutsec int) !

how long to wait till the specified output shows up, timeout in sec

fn (ZProcess) start #

fn (zp ZProcess) start() !

fn (ZProcess) status #

fn (mut zp ZProcess) status() !ZProcessStatus

return status of process

 enum ZProcessStatus {
    unknown
    init
    ok
    error
    blocked
    spawned
 killed
 }

fn (ZProcess) stop #

fn (mut zp ZProcess) stop() !

struct ZProcessNewArgs #

@[params]
struct ZProcessNewArgs {
pub mut:
	name        string @[required]
	cmd         string @[required]
	test        string // command line to test service is running
	status      ZProcessStatus
	pid         int
	after       []string // list of service we depend on
	env         map[string]string
	oneshot     bool
	start       bool = true
	restart     bool = true // whether the process should be restarted on failure
	description string // not used in zinit
}

struct Zinit #

@[heap]
struct Zinit {
pub mut:
	processes map[string]ZProcess
	path      pathlib.Path
	pathcmds  pathlib.Path
	pathtests pathlib.Path
}

fn (Zinit) delete #

fn (mut zinit Zinit) delete(name string) !

fn (Zinit) exists #

fn (mut zinit Zinit) exists(name_ string) bool

fn (Zinit) get #

fn (mut zinit Zinit) get(name_ string) !ZProcess

fn (Zinit) load #

fn (mut self Zinit) load() !

fn (Zinit) new #

fn (mut zinit Zinit) new(args_ ZProcessNewArgs) !ZProcess

will delete the process if it exists while starting

fn (Zinit) start #

fn (mut zinit Zinit) start(name string) !

fn (Zinit) stop #

fn (mut zinit Zinit) stop(name string) !

fn (Zinit) systemd_start #

fn (mut self Zinit) systemd_start() !