had to cleanup a lot in relation to optional returns

This commit is contained in:
2025-01-01 13:40:24 +01:00
parent cffd5e2f9c
commit 914e1f5073
135 changed files with 4165 additions and 3530 deletions

View File

@@ -9,7 +9,7 @@ import freeflowuniverse.herolib.installers.ulist
import os
fn installed_() !bool {
res := os.execute('${osal.profile_path_source_and()} meilisearch -V')
res := os.execute('${osal.profile_path_source_and()!} meilisearch -V')
if res.exit_code != 0 {
return false
}
@@ -28,13 +28,13 @@ fn install_() ! {
console.print_header('install meilisearch')
mut url := ''
if osal.is_linux_arm() {
if core.is_linux_arm()! {
url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-aarch64'
} else if osal.is_linux_intel() {
} else if core.is_linux_intel()! {
url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-amd64'
} else if osal.is_osx_arm() {
} else if core.is_osx_arm()! {
url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-apple-silicon'
} else if osal.is_osx_intel() {
} else if core.is_osx_intel()! {
url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-amd64'
} else {
return error('unsported platform')
@@ -62,7 +62,7 @@ fn build_() ! {
// console.print_header('compile meilisearch')
// rust.install()!
// mut dest_on_os := '${os.home_dir()}/hero/bin'
// if osal.is_linux() {
// if core.is_linux()! {
// dest_on_os = '/usr/local/bin'
// }
// console.print_debug(' - dest path for meilisearchs is on: ${dest_on_os}')

View File

@@ -1,271 +1,301 @@
module meilisearchinstaller
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.data.encoderhero
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 args := args_get(args_)
if !(args.name in meilisearchinstaller_global) {
if args.name=="default"{
if ! config_exists(args){
if default{
mut context:=base.context() or { panic("bug") }
context.hero_config_set("meilisearchinstaller",model.name,heroscript_default()!)!
}
}
load(args)!
}
}
return meilisearchinstaller_global[args.name] or {
println(meilisearchinstaller_global)
panic("could not get config for ${args.name} 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)
//set the model in mem and the config on the filesystem
pub fn set(o MeilisearchServer)! {
mut o2:=obj_init(o)!
meilisearchinstaller_global[o.name] = &o2
meilisearchinstaller_default = o.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)!
//check we find the config on the filesystem
pub fn exists(args_ ArgsGet) bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("meilisearchinstaller",model.name)
}
fn config_save(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context := base.context()!
context.hero_config_set('meilisearchinstaller', model.name, heroscript_default()!)!
//load the config error if it doesn't exist
pub fn load(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("meilisearchinstaller",model.name)!
play(heroscript:heroscript)!
}
fn set(o MeilisearchServer) ! {
mut o2 := obj_init(o)!
meilisearchinstaller_global[o.name] = &o2
meilisearchinstaller_default = o.name
//save the config to the filesystem in the context
pub fn save(o MeilisearchServer)! {
mut context:=base.context()!
heroscript := encoderhero.encode[MeilisearchServer](o)!
context.hero_config_set("meilisearchinstaller",model.name,heroscript)!
}
@[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)! }
if model.heroscript == "" {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or {
playbook.new(text: model.heroscript)!
}
mut configure_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
if configure_actions.len > 0 {
for config_action in configure_actions {
mut p := config_action.params
mycfg:=cfg_play(p)!
console.print_debug("install action meilisearchinstaller.configure\n${mycfg}")
set(mycfg)!
save(mycfg)!
}
}
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)!
}
}
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 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()!
}
}
}
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()!
}
}
//load from disk and make sure is properly intialized
pub fn (mut self MeilisearchServer) reload() ! {
switch(self.name)
self=obj_init(self)!
}
// load from disk and make sure is properly intialized
pub fn (mut self MeilisearchServer) reload() ! {
switch(self.name)
self = obj_init(self)!
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()!
}
}
}
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()!
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('meilisearchinstaller did not install properly.')
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 instance to be used for meilisearchinstaller
pub fn switch(name string) {
meilisearchinstaller_default = name
}
pub fn (mut self MeilisearchServer) install(args InstallArgs) ! {
switch(self.name)
if args.reset {
destroy_()!
}
if ! (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
pub fn switch(name string) {
meilisearchinstaller_default = name
}

View File

@@ -1,266 +1,252 @@
module postgresql
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.data.encoderhero
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 mut:
name string
//set the model in mem and the config on the filesystem
pub fn set(o Postgresql)! {
mut o2:=obj_init(o)!
postgresql_global[o.name] = &o2
postgresql_default = o.name
}
fn args_get(args_ ArgsGet) ArgsGet {
mut model := args_
if model.name == '' {
model.name = postgresql_default
}
if model.name == '' {
model.name = 'default'
}
return model
//check we find the config on the filesystem
pub fn exists(args_ ArgsGet) bool {
mut model := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("postgresql",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}')
}
//load the config error if it doesn't exist
pub fn load(args_ ArgsGet) ! {
mut model := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("postgresql",model.name)!
play(heroscript:heroscript)!
}
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)
}
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)!
}
fn config_save(args_ ArgsGet) ! {
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
//save the config to the filesystem in the context
pub fn save(o Postgresql)! {
mut context:=base.context()!
heroscript := encoderhero.encode[Postgresql](o)!
context.hero_config_set("postgresql",model.name,heroscript)!
}
@[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)! }
if model.heroscript == "" {
model.heroscript = heroscript_default()!
}
mut plbook := model.plbook or {
playbook.new(text: model.heroscript)!
}
mut configure_actions := plbook.find(filter: 'postgresql.configure')!
if configure_actions.len > 0 {
for config_action in configure_actions {
mut p := config_action.params
mycfg:=cfg_play(p)!
console.print_debug("install action postgresql.configure\n${mycfg}")
set(mycfg)!
save(mycfg)!
}
}
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)!
}
}
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 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()!
}
}
}
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()!
}
}
//load from disk and make sure is properly intialized
pub fn (mut self Postgresql) reload() ! {
switch(self.name)
self=obj_init(self)!
}
// load from disk and make sure is properly intialized
pub fn (mut self Postgresql) reload() ! {
switch(self.name)
self = obj_init(self)!
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()!
}
}
}
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()!
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('postgresql did not install properly.')
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()!
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
}
pub fn (mut self Postgresql) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
pub fn destroy() ! {
destroy_()!
}
// switch instance to be used for postgresql
pub fn switch(name string) {
postgresql_default = name
}

View File

@@ -39,7 +39,7 @@ fn cfg_play(p paramsparser.Params) !Postgresql {
fn obj_init(obj_ Postgresql) !Postgresql {
mut obj := obj_
if obj.path == '' {
if osal.is_linux() {
if core.is_linux()! {
obj.path = '/data/postgresql/${obj.name}'
} else {
obj.path = '${os.home_dir()}/hero/var/postgresql/${obj.name}'

View File

@@ -28,7 +28,7 @@ pub fn install_(args_ InstallArgs) ! {
mut args := args_
version := '2.0.7'
res := os.execute('${osal.profile_path_source_and()} zdb --version')
res := os.execute('${osal.profile_path_source_and()!} zdb --version')
if res.exit_code == 0 {
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
if r.len != 3 {
@@ -46,7 +46,7 @@ pub fn install_(args_ InstallArgs) ! {
console.print_header('install zdb')
mut url := ''
if osal.is_linux_intel() {
if core.is_linux_intel()! {
url = 'https://github.com/threefoldtech/0-db/releases/download/v${version}/zdb-${version}-linux-amd64-static'
} else {
return error('unsported platform, only linux 64 for zdb for now')

View File

@@ -66,7 +66,7 @@ fn stop_post() ! {
// 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')
// res := os.execute('${osal.profile_path_source_and()!} zerodb version')
// if res.exit_code != 0 {
// return false
// }
@@ -98,13 +98,13 @@ fn install_() ! {
console.print_header('install zerodb')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// if core.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() {
// } else if core.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() {
// } else if core.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() {
// } else if core.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')
@@ -129,7 +129,7 @@ fn build_() ! {
// url := 'https://github.com/threefoldtech/zerodb'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// if core.platform()!= .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!

View File

@@ -1,153 +1,152 @@
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 mut:
name string
}
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()!
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerodb did not install properly.')
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()!
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
}
pub fn (mut self ZeroDB) build() ! {
switch(self.name)
build()!
pub fn destroy() ! {
destroy_()!
}
pub fn (mut self ZeroDB) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
pub fn build() ! {
build_()!
}
// switch instance to be used for zerodb
pub fn switch(name string) {
zerodb_default = name
}

View File

@@ -66,7 +66,7 @@ fn stop_post() ! {
// 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')
// res := os.execute('${osal.profile_path_source_and()!} zerofs version')
// if res.exit_code != 0 {
// return false
// }
@@ -98,13 +98,13 @@ fn install_() ! {
console.print_header('install zerofs')
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// if core.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() {
// } else if core.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() {
// } else if core.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() {
// } else if core.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')
@@ -129,7 +129,7 @@ fn build_() ! {
// url := 'https://github.com/threefoldtech/zerofs'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// if core.platform()!= .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!

View File

@@ -1,153 +1,152 @@
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 mut:
name string
}
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()!
start_post()!
for _ in 0 .. 50 {
if self.running()! {
return
}
time.sleep(100 * time.millisecond)
}
return error('zerofs did not install properly.')
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()!
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if ! (installed_()!){
install_()!
}
}
pub fn (mut self ZeroFS) build() ! {
switch(self.name)
build()!
pub fn destroy() ! {
destroy_()!
}
pub fn (mut self ZeroFS) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
pub fn build() ! {
build_()!
}
// switch instance to be used for zerofs
pub fn switch(name string) {
zerofs_default = name
}