fixes for docu

This commit is contained in:
2024-12-25 21:48:03 +01:00
parent df86792bf0
commit 958daaa697
107 changed files with 5400 additions and 8589 deletions

View File

@@ -1,285 +1,271 @@
module meilisearchinstaller
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
meilisearchinstaller_global map[string]&MeilisearchServer
meilisearchinstaller_default string
meilisearchinstaller_global map[string]&MeilisearchServer
meilisearchinstaller_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = meilisearchinstaller_default
}
if model.name == ""{
model.name = "default"
}
return model
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = meilisearchinstaller_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
pub fn get(args_ ArgsGet) !&MeilisearchServer {
mut model := args_get(args_)
if !(model.name in meilisearchinstaller_global) {
if model.name=="default"{
if ! config_exists(model){
if default{
config_save(model)!
}
}
config_load(model)!
}
}
return meilisearchinstaller_global[model.name] or {
println(meilisearchinstaller_global)
panic("could not get config for meilisearchinstaller with name:${model.name}")
}
pub fn get(args_ ArgsGet) !&MeilisearchServer {
mut model := args_get(args_)
if model.name !in meilisearchinstaller_global {
if model.name == 'default' {
if !config_exists(model) {
if default {
config_save(model)!
}
}
config_load(model)!
}
}
return meilisearchinstaller_global[model.name] or {
println(meilisearchinstaller_global)
panic('could not get config for meilisearchinstaller with name:${model.name}')
}
}
fn config_exists(args_ ArgsGet) bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("meilisearchinstaller",model.name)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('meilisearchinstaller', model.name)
}
fn config_load(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("meilisearchinstaller",model.name)!
play(heroscript:heroscript)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('meilisearchinstaller', model.name)!
play(heroscript: heroscript)!
}
fn config_save(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
context.hero_config_set("meilisearchinstaller",model.name,heroscript_default()!)!
mut model := args_get(args_)
mut context := base.context()!
context.hero_config_set('meilisearchinstaller', model.name, heroscript_default()!)!
}
fn set(o MeilisearchServer)! {
mut o2:=obj_init(o)!
meilisearchinstaller_global[o.name] = &o2
meilisearchinstaller_default = o.name
fn set(o MeilisearchServer) ! {
mut o2 := obj_init(o)!
meilisearchinstaller_global[o.name] = &o2
meilisearchinstaller_default = o.name
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string //if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut model:=args_
mut model := args_
if model.heroscript == "" {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or {
playbook.new(text: model.heroscript)!
}
mut install_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
mycfg:=cfg_play(p)!
console.print_debug("install action meilisearchinstaller.configure\n${mycfg}")
set(mycfg)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
for other_action in other_actions {
if other_action.name in ["destroy","install","build"]{
mut p := other_action.params
reset:=p.get_default_false("reset")
if other_action.name == "destroy" || reset{
console.print_debug("install action meilisearchinstaller.destroy")
destroy()!
}
if other_action.name == "install"{
console.print_debug("install action meilisearchinstaller.install")
install()!
}
}
if other_action.name in ["start","stop","restart"]{
mut p := other_action.params
name := p.get('name')!
mut meilisearchinstaller_obj:=get(name:name)!
console.print_debug("action object:\n${meilisearchinstaller_obj}")
if other_action.name == "start"{
console.print_debug("install action meilisearchinstaller.${other_action.name}")
meilisearchinstaller_obj.start()!
}
mut install_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
mycfg := cfg_play(p)!
console.print_debug('install action meilisearchinstaller.configure\n${mycfg}')
set(mycfg)!
}
}
if other_action.name == "stop"{
console.print_debug("install action meilisearchinstaller.${other_action.name}")
meilisearchinstaller_obj.stop()!
}
if other_action.name == "restart"{
console.print_debug("install action meilisearchinstaller.${other_action.name}")
meilisearchinstaller_obj.restart()!
}
}
}
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action meilisearchinstaller.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action meilisearchinstaller.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut meilisearchinstaller_obj := get(name: name)!
console.print_debug('action object:\n${meilisearchinstaller_obj}')
if other_action.name == 'start' {
console.print_debug('install action meilisearchinstaller.${other_action.name}')
meilisearchinstaller_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action meilisearchinstaller.${other_action.name}')
meilisearchinstaller_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action meilisearchinstaller.${other_action.name}')
meilisearchinstaller_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
//load from disk and make sure is properly intialized
// load from disk and make sure is properly intialized
pub fn (mut self MeilisearchServer) reload() ! {
switch(self.name)
self=obj_init(self)!
switch(self.name)
self = obj_init(self)!
}
pub fn (mut self MeilisearchServer) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('meilisearchinstaller start')
console.print_header('meilisearchinstaller start')
if ! installed()!{
install()!
}
if !installed()! {
install()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...')
console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('meilisearchinstaller did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('meilisearchinstaller did not install properly.')
}
pub fn (mut self MeilisearchServer) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self MeilisearchServer) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self MeilisearchServer) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self MeilisearchServer) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn (mut self MeilisearchServer) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self MeilisearchServer) build() ! {
switch(self.name)
build()!
switch(self.name)
build()!
}
pub fn (mut self MeilisearchServer) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for meilisearchinstaller
// switch instance to be used for meilisearchinstaller
pub fn switch(name string) {
meilisearchinstaller_default = name
meilisearchinstaller_default = name
}

View File

@@ -1,281 +1,266 @@
module postgresql
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
postgresql_global map[string]&Postgresql
postgresql_default string
postgresql_global map[string]&Postgresql
postgresql_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
fn args_get (args_ ArgsGet) ArgsGet {
mut model:=args_
if model.name == ""{
model.name = postgresql_default
}
if model.name == ""{
model.name = "default"
}
return model
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = postgresql_default
}
if model.name == '' {
model.name = 'default'
}
return model
}
pub fn get(args_ ArgsGet) !&Postgresql {
mut model := args_get(args_)
if !(model.name in postgresql_global) {
if model.name=="default"{
if ! config_exists(model){
if default{
config_save(model)!
}
}
config_load(model)!
}
}
return postgresql_global[model.name] or {
println(postgresql_global)
panic("could not get config for postgresql with name:${model.name}")
}
pub fn get(args_ ArgsGet) !&Postgresql {
mut model := args_get(args_)
if model.name !in postgresql_global {
if model.name == 'default' {
if !config_exists(model) {
if default {
config_save(model)!
}
}
config_load(model)!
}
}
return postgresql_global[model.name] or {
println(postgresql_global)
panic('could not get config for postgresql with name:${model.name}')
}
}
fn config_exists(args_ ArgsGet) bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("postgresql",model.name)
mut model := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('postgresql', model.name)
}
fn config_load(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("postgresql",model.name)!
play(heroscript:heroscript)!
mut model := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('postgresql', model.name)!
play(heroscript: heroscript)!
}
fn config_save(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
context.hero_config_set("postgresql",model.name,heroscript_default()!)!
mut model := args_get(args_)
mut context := base.context()!
context.hero_config_set('postgresql', model.name, heroscript_default()!)!
}
fn set(o Postgresql)! {
mut o2:=obj_init(o)!
postgresql_global[o.name] = &o2
postgresql_default = o.name
fn set(o Postgresql) ! {
mut o2 := obj_init(o)!
postgresql_global[o.name] = &o2
postgresql_default = o.name
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string //if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut model:=args_
mut model := args_
if model.heroscript == "" {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or {
playbook.new(text: model.heroscript)!
}
mut install_actions := plbook.find(filter: 'postgresql.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
mycfg:=cfg_play(p)!
console.print_debug("install action postgresql.configure\n${mycfg}")
set(mycfg)!
}
}
if model.heroscript == '' {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
mut other_actions := plbook.find(filter: 'postgresql.')!
for other_action in other_actions {
if other_action.name in ["destroy","install","build"]{
mut p := other_action.params
reset:=p.get_default_false("reset")
if other_action.name == "destroy" || reset{
console.print_debug("install action postgresql.destroy")
destroy()!
}
if other_action.name == "install"{
console.print_debug("install action postgresql.install")
install()!
}
}
if other_action.name in ["start","stop","restart"]{
mut p := other_action.params
name := p.get('name')!
mut postgresql_obj:=get(name:name)!
console.print_debug("action object:\n${postgresql_obj}")
if other_action.name == "start"{
console.print_debug("install action postgresql.${other_action.name}")
postgresql_obj.start()!
}
mut install_actions := plbook.find(filter: 'postgresql.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
mycfg := cfg_play(p)!
console.print_debug('install action postgresql.configure\n${mycfg}')
set(mycfg)!
}
}
if other_action.name == "stop"{
console.print_debug("install action postgresql.${other_action.name}")
postgresql_obj.stop()!
}
if other_action.name == "restart"{
console.print_debug("install action postgresql.${other_action.name}")
postgresql_obj.restart()!
}
}
}
mut other_actions := plbook.find(filter: 'postgresql.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action postgresql.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action postgresql.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut postgresql_obj := get(name: name)!
console.print_debug('action object:\n${postgresql_obj}')
if other_action.name == 'start' {
console.print_debug('install action postgresql.${other_action.name}')
postgresql_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action postgresql.${other_action.name}')
postgresql_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action postgresql.${other_action.name}')
postgresql_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
//load from disk and make sure is properly intialized
// load from disk and make sure is properly intialized
pub fn (mut self Postgresql) reload() ! {
switch(self.name)
self=obj_init(self)!
switch(self.name)
self = obj_init(self)!
}
pub fn (mut self Postgresql) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('postgresql start')
console.print_header('postgresql start')
if ! installed()!{
install()!
}
if !installed()! {
install()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting postgresql with ${zprocess.startuptype}...')
console.print_debug('starting postgresql with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('postgresql did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('postgresql did not install properly.')
}
pub fn (mut self Postgresql) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self Postgresql) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self Postgresql) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self Postgresql) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn (mut self Postgresql) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self Postgresql) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for postgresql
// switch instance to be used for postgresql
pub fn switch(name string) {
postgresql_default = name
postgresql_default = name
}

View File

@@ -4,199 +4,184 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.osal.systemd
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'zerodb'
// cmd: 'zerodb server'
// env: {
// 'HOME': '/root'
// }
// }
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'zerodb'
// cmd: 'zerodb server'
// env: {
// 'HOME': '/root'
// }
// }
return res
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerodb
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'zerodb', url: url)!
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerodb
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'zerodb', url: url)!
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('zerodb is answering.')
return false
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('zerodb is answering.')
return false
}
fn start_pre()!{
fn start_pre() ! {
}
fn start_post()!{
fn start_post() ! {
}
fn stop_pre()!{
fn stop_pre() ! {
}
fn stop_post()!{
fn stop_post() ! {
}
//////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed
fn installed() !bool {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerodb version')
// if res.exit_code != 0 {
// return false
// }
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// if r.len != 1 {
// return error("couldn't parse zerodb version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerodb version')
// if res.exit_code != 0 {
// return false
// }
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// if r.len != 1 {
// return error("couldn't parse zerodb version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
}
//get the Upload List of the files
// get the Upload List of the files
fn ulist_get() !ulist.UList {
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
//uploads to S3 server if configured
// uploads to S3 server if configured
fn upload() ! {
// installers.upload(
// cmdname: 'zerodb'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerodb'
// )!
// installers.upload(
// cmdname: 'zerodb'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerodb'
// )!
}
fn install() ! {
console.print_header('install zerodb')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
console.print_header('install zerodb')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/zerodb-dev/zerodb/releases/download/v${version}/zerodb_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/zerodb'
// )!
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/zerodb'
// )!
// //dest.moveup_single_subdir()!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('zerodb')!
// osal.cmd_add(
// cmdname: 'zerodb'
// source: binpath.path
// )!
// mut binpath := dest.file_get('zerodb')!
// osal.cmd_add(
// cmdname: 'zerodb'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/zerodb'
// url := 'https://github.com/threefoldtech/zerodb'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build zerodb')
// console.print_header('build zerodb')
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// source: binpath.path
// )!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// source: binpath.path
// )!
}
fn destroy() ! {
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
// osal.package_remove('
// podman
// conmon
// buildah
// skopeo
// runc
// ')!
// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!
// osal.rm("
// podman
// conmon
// buildah
// skopeo
// runc
// /var/lib/containers
// /var/lib/podman
// /var/lib/buildah
// /tmp/podman
// /tmp/conmon
// ")!
// osal.package_remove('
// podman
// conmon
// buildah
// skopeo
// runc
// ')!
// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!
// osal.rm("
// podman
// conmon
// buildah
// skopeo
// runc
// /var/lib/containers
// /var/lib/podman
// /var/lib/buildah
// /tmp/podman
// /tmp/conmon
// ")!
}

View File

@@ -1,160 +1,153 @@
module zerodb
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
zerodb_global map[string]&ZeroDB
zerodb_default string
zerodb_global map[string]&ZeroDB
zerodb_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
pub fn get(args_ ArgsGet) !&ZeroDB {
return &ZeroDB{}
pub fn get(args_ ArgsGet) !&ZeroDB {
return &ZeroDB{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
pub fn (mut self ZeroDB) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('zerodb start')
console.print_header('zerodb start')
if ! installed()!{
install()!
}
if !installed()! {
install()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting zerodb with ${zprocess.startuptype}...')
console.print_debug('starting zerodb with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerodb did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerodb did not install properly.')
}
pub fn (mut self ZeroDB) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self ZeroDB) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self ZeroDB) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self ZeroDB) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn (mut self ZeroDB) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self ZeroDB) build() ! {
switch(self.name)
build()!
switch(self.name)
build()!
}
pub fn (mut self ZeroDB) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for zerodb
// switch instance to be used for zerodb
pub fn switch(name string) {
zerodb_default = name
zerodb_default = name
}

View File

@@ -1,4 +1,5 @@
module zerodb
import freeflowuniverse.herolib.data.paramsparser
import os
@@ -6,25 +7,21 @@ pub const version = '0.0.0'
const singleton = true
const default = true
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
$[heap]
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct ZeroDB {
pub mut:
name string = 'default'
name string = 'default'
}
fn obj_init(obj_ ZeroDB)!ZeroDB{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
fn obj_init(obj_ ZeroDB) !ZeroDB {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
panic('implement')
return obj
}
//called before start if done
// called before start if done
fn configure() ! {
//mut installer := get()!
// mut installer := get()!
}

View File

@@ -4,199 +4,184 @@ import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.osal.systemd
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.installers.ulist
import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.installers.lang.rust
import freeflowuniverse.herolib.installers.lang.python
import os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'zerofs'
// cmd: 'zerofs server'
// env: {
// 'HOME': '/root'
// }
// }
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'zerofs'
// cmd: 'zerofs server'
// env: {
// 'HOME': '/root'
// }
// }
return res
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerofs
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'zerofs', url: url)!
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of zerofs
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
// url:='http://127.0.0.1:${cfg.port}/api/v1'
// mut conn := httpconnection.new(name: 'zerofs', url: url)!
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('zerofs is answering.')
return false
// if cfg.secret.len > 0 {
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
// }
// conn.default_header.add(.content_type, 'application/json')
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
// println(r)
// if true{panic("ssss")}
// tags := r['Tags'] or { return false }
// console.print_debug(tags)
// console.print_debug('zerofs is answering.')
return false
}
fn start_pre()!{
fn start_pre() ! {
}
fn start_post()!{
fn start_post() ! {
}
fn stop_pre()!{
fn stop_pre() ! {
}
fn stop_post()!{
fn stop_post() ! {
}
//////////////////// following actions are not specific to instance of the object
// checks if a certain version or above is installed
fn installed() !bool {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerofs version')
// if res.exit_code != 0 {
// return false
// }
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// if r.len != 1 {
// return error("couldn't parse zerofs version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} zerofs version')
// if res.exit_code != 0 {
// return false
// }
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
// if r.len != 1 {
// return error("couldn't parse zerofs version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
}
//get the Upload List of the files
// get the Upload List of the files
fn ulist_get() !ulist.UList {
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
return ulist.UList{}
}
//uploads to S3 server if configured
// uploads to S3 server if configured
fn upload() ! {
// installers.upload(
// cmdname: 'zerofs'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerofs'
// )!
// installers.upload(
// cmdname: 'zerofs'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/zerofs'
// )!
}
fn install() ! {
console.print_header('install zerofs')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
console.print_header('install zerofs')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/zerofs-dev/zerofs/releases/download/v${version}/zerofs_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/zerofs'
// )!
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/zerofs'
// )!
// //dest.moveup_single_subdir()!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('zerofs')!
// osal.cmd_add(
// cmdname: 'zerofs'
// source: binpath.path
// )!
// mut binpath := dest.file_get('zerofs')!
// osal.cmd_add(
// cmdname: 'zerofs'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/zerofs'
// url := 'https://github.com/threefoldtech/zerofs'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build zerofs')
// console.print_header('build zerofs')
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// source: binpath.path
// )!
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
// cmd := '
// cd ${gitpath}
// source ~/.cargo/env
// exit 1 #todo
// '
// osal.execute_stdout(cmd)!
//
// //now copy to the default bin path
// mut binpath := dest.file_get('...')!
// adds it to path
// osal.cmd_add(
// cmdname: 'griddriver2'
// source: binpath.path
// )!
}
fn destroy() ! {
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
// osal.process_kill_recursive(name:'zinit')!
// osal.cmd_delete('zinit')!
// osal.package_remove('
// podman
// conmon
// buildah
// skopeo
// runc
// ')!
// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!
// osal.rm("
// podman
// conmon
// buildah
// skopeo
// runc
// /var/lib/containers
// /var/lib/podman
// /var/lib/buildah
// /tmp/podman
// /tmp/conmon
// ")!
// osal.package_remove('
// podman
// conmon
// buildah
// skopeo
// runc
// ')!
// //will remove all paths where go/bin is found
// osal.profile_path_add_remove(paths2delete:"go/bin")!
// osal.rm("
// podman
// conmon
// buildah
// skopeo
// runc
// /var/lib/containers
// /var/lib/podman
// /var/lib/buildah
// /tmp/podman
// /tmp/conmon
// ")!
}

View File

@@ -1,160 +1,153 @@
module zerofs
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
zerofs_global map[string]&ZeroFS
zerofs_default string
zerofs_global map[string]&ZeroFS
zerofs_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub struct ArgsGet {
pub mut:
name string
name string
}
pub fn get(args_ ArgsGet) !&ZeroFS {
return &ZeroFS{}
pub fn get(args_ ArgsGet) !&ZeroFS {
return &ZeroFS{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat{
.zinit{
console.print_debug("startupmanager: zinit")
return startupmanager.get(cat:.zinit)!
}
.systemd{
console.print_debug("startupmanager: systemd")
return startupmanager.get(cat:.systemd)!
}else{
console.print_debug("startupmanager: auto")
return startupmanager.get()!
}
}
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
pub fn (mut self ZeroFS) start() ! {
switch(self.name)
if self.running()!{
return
}
switch(self.name)
if self.running()! {
return
}
console.print_header('zerofs start')
console.print_header('zerofs start')
if ! installed()!{
install()!
}
if !installed()! {
install()!
}
configure()!
configure()!
start_pre()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting zerofs with ${zprocess.startuptype}...')
console.print_debug('starting zerofs with ${zprocess.startuptype}...')
sm.new(zprocess)!
sm.new(zprocess)!
sm.start(zprocess.name)!
}
sm.start(zprocess.name)!
}
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerofs did not install properly.')
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerofs did not install properly.')
}
pub fn (mut self ZeroFS) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self ZeroFS) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self ZeroFS) restart() ! {
switch(self.name)
self.stop()!
self.start()!
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self ZeroFS) running() !bool {
switch(self.name)
switch(self.name)
//walk over the generic processes, if not running return
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
r:=sm.running(zprocess.name)!
if r==false{
return false
}
}
return running()!
// walk over the generic processes, if not running return
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
r := sm.running(zprocess.name)!
if r == false {
return false
}
}
return running()!
}
@[params]
pub struct InstallArgs{
pub struct InstallArgs {
pub mut:
reset bool
reset bool
}
pub fn (mut self ZeroFS) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self ZeroFS) build() ! {
switch(self.name)
build()!
switch(self.name)
build()!
}
pub fn (mut self ZeroFS) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for zerofs
// switch instance to be used for zerofs
pub fn switch(name string) {
zerofs_default = name
zerofs_default = name
}

View File

@@ -1,4 +1,5 @@
module zerofs
import freeflowuniverse.herolib.data.paramsparser
import os
@@ -6,25 +7,21 @@ pub const version = '0.0.0'
const singleton = true
const default = true
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
$[heap]
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
@[heap]
pub struct ZeroFS {
pub mut:
name string = 'default'
name string = 'default'
}
fn obj_init(obj_ ZeroFS)!ZeroFS{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
fn obj_init(obj_ ZeroFS) !ZeroFS {
// never call get here, only thing we can do here is work on object itself
mut obj := obj_
panic('implement')
return obj
}
//called before start if done
// called before start if done
fn configure() ! {
//mut installer := get()!
// mut installer := get()!
}