diff --git a/lib/core/generator/generic/model.v b/lib/core/generator/generic/model.v index d2bd0148..6464e31e 100644 --- a/lib/core/generator/generic/model.v +++ b/lib/core/generator/generic/model.v @@ -47,7 +47,7 @@ fn args_get(path string) !GeneratorArgs { classname: p.get('classname')! title: p.get_default('title', '')! default: p.get_default_true('default') - supported_platforms: p.get_list('supported_platforms')! + supported_platforms: p.get_list_default('supported_platforms',[])! singleton: p.get_default_false('singleton') templates: p.get_default_false('templates') reset: p.get_default_false('reset') diff --git a/lib/installers/db/postgresql/postgresql_factory_.v b/lib/installers/db/postgresql/postgresql_factory_.v index 37e09e5d..4c23c67f 100644 --- a/lib/installers/db/postgresql/postgresql_factory_.v +++ b/lib/installers/db/postgresql/postgresql_factory_.v @@ -2,231 +2,286 @@ module postgresql import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit -import freeflowuniverse.herolib.ui.console 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 = 'default' + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = postgresql_default - } - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut args:=args_ + if args.name == ""{ + args.name = "default" + } + return args } -pub fn get(args_ ArgsGet) !&Postgresql { - mut args := args_get(args_) - if args.name !in postgresql_global { - if !config_exists() { - if default { - config_save()! - } - } - config_load()! - } - return postgresql_global[args.name] or { panic('bug in get from factory: ') } +pub fn get(args_ ArgsGet) !&Postgresql { + mut context:=base.context()! + mut args := args_get(args_) + mut obj := Postgresql{} + if !(args.name in postgresql_global) { + if ! exists(args)!{ + set(obj)! + }else{ + heroscript := context.hero_config_get("postgresql",args.name)! + mut obj_:=heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return postgresql_global[args.name] or { + println(postgresql_global) + //bug if we get here because should be in globals + panic("could not get config for postgresql with name, is bug:${args.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut args := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('postgresql', args.name) +//register the config for the future +pub fn set(o Postgresql)! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set("postgresql", o.name, heroscript)! } -fn config_load(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('postgresql', args.name)! - play(heroscript: heroscript)! +//does the config exists? +pub fn exists(args_ ArgsGet)! bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists("postgresql", args.name) } -fn config_save(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_set('postgresql', args.name, heroscript_default()!)! +pub fn delete(args_ ArgsGet)! { + mut args := args_get(args_) + mut context:=base.context()! + context.hero_config_delete("postgresql",args.name)! + if args.name in postgresql_global { + //del postgresql_global[args.name] + } } -fn set(o Postgresql) ! { - mut o2 := obj_init(o)! - postgresql_global['default'] = &o2 +//only sets in mem, does not set as config +fn set_in_mem(o Postgresql)! { + mut o2:=obj_init(o)! + postgresql_global[o.name] = &o2 + postgresql_default = o.name } + @[params] pub struct PlayArgs { pub mut: - name string = 'default' - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool - - start bool - stop bool - restart bool - delete bool - configure bool // make sure there is at least one installed + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut args := args_ + + mut args:=args_ - if args.heroscript == '' { - args.heroscript = heroscript_default()! - } - mut plbook := args.plbook or { playbook.new(text: args.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)! - set(mycfg)! - } - } + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + mut install_actions := plbook.find(filter: 'postgresql.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript:=install_action.heroscript() + mut obj2:=heroscript_loads(heroscript)! + set(obj2)! + } + } + + 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()! + 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(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + switch(self.name) + self.install(args)! + 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(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed_()!) { - install_()! - } + switch(self.name) + if args.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 +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/db/zerodb/.heroscript b/lib/installers/db/zerodb/.heroscript index e3dd40ac..63f693bc 100644 --- a/lib/installers/db/zerodb/.heroscript +++ b/lib/installers/db/zerodb/.heroscript @@ -8,4 +8,5 @@ templates: false build: true startupmanager: true + supported_platforms: "" diff --git a/lib/installers/db/zerodb/zerodb_factory_.v b/lib/installers/db/zerodb/zerodb_factory_.v index e2164966..f2dde44e 100644 --- a/lib/installers/db/zerodb/zerodb_factory_.v +++ b/lib/installers/db/zerodb/zerodb_factory_.v @@ -3,135 +3,219 @@ module zerodb import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + 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{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'zerodb.')! + 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 zerodb.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action zerodb.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut zerodb_obj:=get(name:name)! + console.print_debug("action object:\n${zerodb_obj}") + if other_action.name == "start"{ + console.print_debug("install action zerodb.${other_action.name}") + zerodb_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action zerodb.${other_action.name}") + zerodb_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action zerodb.${other_action.name}") + zerodb_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()! + } + } } + 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()! +pub fn (mut self ZeroDB) install_start(args InstallArgs) ! { + switch(self.name) + self.install(args)! + 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 install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self ZeroDB) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! +pub fn (mut self ZeroDB) build() ! { + switch(self.name) + build()! } -pub fn build() ! { - build_()! +pub fn (mut self ZeroDB) destroy() ! { + switch(self.name) + self.stop() or {} + destroy()! +} + + + +//switch instance to be used for zerodb +pub fn switch(name string) { + zerodb_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/db/zerofs/.heroscript b/lib/installers/db/zerofs/.heroscript index 8d7b820c..55ae3ec3 100644 --- a/lib/installers/db/zerofs/.heroscript +++ b/lib/installers/db/zerofs/.heroscript @@ -8,4 +8,4 @@ templates: false build: true startupmanager: true - + supported_platforms: "" diff --git a/lib/installers/db/zerofs/zerofs_factory_.v b/lib/installers/db/zerofs/zerofs_factory_.v index 594389c6..c60f1fb1 100644 --- a/lib/installers/db/zerofs/zerofs_factory_.v +++ b/lib/installers/db/zerofs/zerofs_factory_.v @@ -3,135 +3,219 @@ module zerofs import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + 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{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'zerofs.')! + 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 zerofs.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action zerofs.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut zerofs_obj:=get(name:name)! + console.print_debug("action object:\n${zerofs_obj}") + if other_action.name == "start"{ + console.print_debug("install action zerofs.${other_action.name}") + zerofs_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action zerofs.${other_action.name}") + zerofs_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action zerofs.${other_action.name}") + zerofs_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()! + } + } } + 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()! +pub fn (mut self ZeroFS) install_start(args InstallArgs) ! { + switch(self.name) + self.install(args)! + 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 install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self ZeroFS) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! +pub fn (mut self ZeroFS) build() ! { + switch(self.name) + build()! } -pub fn build() ! { - build_()! +pub fn (mut self ZeroFS) destroy() ! { + switch(self.name) + self.stop() or {} + destroy()! +} + + + +//switch instance to be used for zerofs +pub fn switch(name string) { + zerofs_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/infra/coredns/coredns_factory_.v b/lib/installers/infra/coredns/coredns_factory_.v index 4ece5417..d39772bf 100644 --- a/lib/installers/infra/coredns/coredns_factory_.v +++ b/lib/installers/infra/coredns/coredns_factory_.v @@ -4,277 +4,288 @@ import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - coredns_global map[string]&CoreDNS - coredns_default string + coredns_global map[string]&CoreDNS + coredns_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut args:=args_ + if args.name == ""{ + args.name = "default" + } + return args } -pub fn get(args_ ArgsGet) !&CoreDNS { - mut context := base.context()! - mut args := args_get(args_) - mut obj := CoreDNS{} - if args.name !in coredns_global { - if !exists(args)! { - set(obj)! - } else { - heroscript := context.hero_config_get('coredns', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! - } - } - return coredns_global[args.name] or { - println(coredns_global) - // bug if we get here because should be in globals - panic('could not get config for coredns with name, is bug:${args.name}') - } +pub fn get(args_ ArgsGet) !&CoreDNS { + mut context:=base.context()! + mut args := args_get(args_) + mut obj := CoreDNS{} + if !(args.name in coredns_global) { + if ! exists(args)!{ + set(obj)! + }else{ + heroscript := context.hero_config_get("coredns",args.name)! + mut obj_:=heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return coredns_global[args.name] or { + println(coredns_global) + //bug if we get here because should be in globals + panic("could not get config for coredns with name, is bug:${args.name}") + } } -// register the config for the future -pub fn set(o CoreDNS) ! { - set_in_mem(o)! - mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('coredns', o.name, heroscript)! +//register the config for the future +pub fn set(o CoreDNS)! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set("coredns", o.name, heroscript)! } -// does the config exists? -pub fn exists(args_ ArgsGet) !bool { - mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('coredns', args.name) +//does the config exists? +pub fn exists(args_ ArgsGet)! bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists("coredns", args.name) } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_delete('coredns', args.name)! - if args.name in coredns_global { - // del coredns_global[args.name] - } +pub fn delete(args_ ArgsGet)! { + mut args := args_get(args_) + mut context:=base.context()! + context.hero_config_delete("coredns",args.name)! + if args.name in coredns_global { + //del coredns_global[args.name] + } } -// only sets in mem, does not set as config -fn set_in_mem(o CoreDNS) ! { - mut o2 := obj_init(o)! - coredns_global[o.name] = &o2 - coredns_default = o.name +//only sets in mem, does not set as config +fn set_in_mem(o CoreDNS)! { + mut o2:=obj_init(o)! + coredns_global[o.name] = &o2 + coredns_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 args := args_ + + mut args:=args_ - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } - mut install_actions := plbook.find(filter: 'coredns.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - heroscript := install_action.heroscript() - mut obj2 := heroscript_loads(heroscript)! - set(obj2)! - } - } + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + mut install_actions := plbook.find(filter: 'coredns.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript:=install_action.heroscript() + mut obj2:=heroscript_loads(heroscript)! + set(obj2)! + } + } - mut other_actions := plbook.find(filter: 'coredns.')! - 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 coredns.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action coredns.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut coredns_obj := get(name: name)! - console.print_debug('action object:\n${coredns_obj}') - if other_action.name == 'start' { - console.print_debug('install action coredns.${other_action.name}') - coredns_obj.start()! - } + mut other_actions := plbook.find(filter: 'coredns.')! + 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 coredns.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action coredns.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut coredns_obj:=get(name:name)! + console.print_debug("action object:\n${coredns_obj}") + if other_action.name == "start"{ + console.print_debug("install action coredns.${other_action.name}") + coredns_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action coredns.${other_action.name}") + coredns_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action coredns.${other_action.name}") + coredns_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action coredns.${other_action.name}') - coredns_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action coredns.${other_action.name}') - coredns_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 CoreDNS) reload() ! { - switch(self.name) - self = obj_init(self)! + switch(self.name) + self=obj_init(self)! } pub fn (mut self CoreDNS) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('coredns start') + console.print_header('coredns 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 coredns with ${zprocess.startuptype}...') + console.print_debug('starting coredns 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('coredns did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('coredns did not install properly.') } pub fn (mut self CoreDNS) install_start(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self CoreDNS) 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 CoreDNS) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self CoreDNS) 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 CoreDNS) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self CoreDNS) build() ! { - switch(self.name) - build()! + switch(self.name) + build()! } pub fn (mut self CoreDNS) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } -// switch instance to be used for coredns + + +//switch instance to be used for coredns pub fn switch(name string) { - coredns_default = name + coredns_default = name } -// helpers + +//helpers @[params] -pub struct DefaultConfigArgs { - instance string = 'default' +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/infra/gitea/gitea_factory_.v b/lib/installers/infra/gitea/gitea_factory_.v index c0fd64d5..55014dd2 100644 --- a/lib/installers/infra/gitea/gitea_factory_.v +++ b/lib/installers/infra/gitea/gitea_factory_.v @@ -4,277 +4,288 @@ import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - gitea_global map[string]&GiteaServer - gitea_default string + gitea_global map[string]&GiteaServer + gitea_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut args:=args_ + if args.name == ""{ + args.name = "default" + } + return args } -pub fn get(args_ ArgsGet) !&GiteaServer { - mut context := base.context()! - mut args := args_get(args_) - mut obj := GiteaServer{} - if args.name !in gitea_global { - if !exists(args)! { - set(obj)! - } else { - heroscript := context.hero_config_get('gitea', args.name)! - mut obj2 := heroscript_loads(heroscript)! - set_in_mem(obj2)! - } - } - return gitea_global[args.name] or { - println(gitea_global) - // bug if we get here because should be in globals - panic('could not get config for gitea with name, is bug:${args.name}') - } +pub fn get(args_ ArgsGet) !&GiteaServer { + mut context:=base.context()! + mut args := args_get(args_) + mut obj := GiteaServer{} + if !(args.name in gitea_global) { + if ! exists(args)!{ + set(obj)! + }else{ + heroscript := context.hero_config_get("gitea",args.name)! + mut obj_:=heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return gitea_global[args.name] or { + println(gitea_global) + //bug if we get here because should be in globals + panic("could not get config for gitea with name, is bug:${args.name}") + } } -// register the config for the future -pub fn set(o GiteaServer) ! { - set_in_mem(o)! - mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('gitea', o.name, heroscript)! +//register the config for the future +pub fn set(o GiteaServer)! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set("gitea", o.name, heroscript)! } -// does the config exists? -pub fn exists(args_ ArgsGet) !bool { - mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('gitea', args.name) +//does the config exists? +pub fn exists(args_ ArgsGet)! bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists("gitea", args.name) } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_delete('gitea', args.name)! - if args.name in gitea_global { - // del gitea_global[args.name] - } +pub fn delete(args_ ArgsGet)! { + mut args := args_get(args_) + mut context:=base.context()! + context.hero_config_delete("gitea",args.name)! + if args.name in gitea_global { + //del gitea_global[args.name] + } } -// only sets in mem, does not set as config -fn set_in_mem(o GiteaServer) ! { - mut o2 := obj_init(o)! - gitea_global[o.name] = &o2 - gitea_default = o.name +//only sets in mem, does not set as config +fn set_in_mem(o GiteaServer)! { + mut o2:=obj_init(o)! + gitea_global[o.name] = &o2 + gitea_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 args := args_ + + mut args:=args_ - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } - mut install_actions := plbook.find(filter: 'gitea.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - heroscript := install_action.heroscript() - mut obj := heroscript_loads(heroscript)! - set(obj)! - } - } + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + mut install_actions := plbook.find(filter: 'gitea.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript:=install_action.heroscript() + mut obj2:=heroscript_loads(heroscript)! + set(obj2)! + } + } - mut other_actions := plbook.find(filter: 'gitea.')! - 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 gitea.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action gitea.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut gitea_obj := get(name: name)! - console.print_debug('action object:\n${gitea_obj}') - if other_action.name == 'start' { - console.print_debug('install action gitea.${other_action.name}') - gitea_obj.start()! - } + mut other_actions := plbook.find(filter: 'gitea.')! + 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 gitea.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action gitea.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut gitea_obj:=get(name:name)! + console.print_debug("action object:\n${gitea_obj}") + if other_action.name == "start"{ + console.print_debug("install action gitea.${other_action.name}") + gitea_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action gitea.${other_action.name}") + gitea_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action gitea.${other_action.name}") + gitea_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action gitea.${other_action.name}') - gitea_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action gitea.${other_action.name}') - gitea_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 GiteaServer) reload() ! { - switch(self.name) - self = obj_init(self)! + switch(self.name) + self=obj_init(self)! } pub fn (mut self GiteaServer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('gitea start') + console.print_header('gitea 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 gitea with ${zprocess.startuptype}...') + console.print_debug('starting gitea 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('gitea did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('gitea did not install properly.') } pub fn (mut self GiteaServer) install_start(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self GiteaServer) 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 GiteaServer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self GiteaServer) 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 GiteaServer) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self GiteaServer) build() ! { - switch(self.name) - build()! + switch(self.name) + build()! } pub fn (mut self GiteaServer) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } -// switch instance to be used for gitea + + +//switch instance to be used for gitea pub fn switch(name string) { - gitea_default = name + gitea_default = name } -// helpers + +//helpers @[params] -pub struct DefaultConfigArgs { - instance string = 'default' +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/infra/livekit/livekit_factory_.v b/lib/installers/infra/livekit/livekit_factory_.v index 208797a5..5454ae41 100644 --- a/lib/installers/infra/livekit/livekit_factory_.v +++ b/lib/installers/infra/livekit/livekit_factory_.v @@ -2,203 +2,286 @@ module livekit import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - livekit_global map[string]&LivekitServer - livekit_default string + livekit_global map[string]&LivekitServer + livekit_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string = 'default' + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = livekit_default - } - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut args:=args_ + if args.name == ""{ + args.name = "default" + } + return args } -pub fn get(args_ ArgsGet) !&LivekitServer { - mut args := args_get(args_) - if args.name !in livekit_global { - if !config_exists() { - if default { - config_save()! - } - } - config_load()! - } - return livekit_global[args.name] or { - println(livekit_global) - panic('bug in get from factory: ') - } +pub fn get(args_ ArgsGet) !&LivekitServer { + mut context:=base.context()! + mut args := args_get(args_) + mut obj := LivekitServer{} + if !(args.name in livekit_global) { + if ! exists(args)!{ + set(obj)! + }else{ + heroscript := context.hero_config_get("livekit",args.name)! + mut obj_:=heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return livekit_global[args.name] or { + println(livekit_global) + //bug if we get here because should be in globals + panic("could not get config for livekit with name, is bug:${args.name}") + } } -fn config_exists(args_ ArgsGet) bool { - mut args := args_get(args_) - mut context := base.context() or { panic('bug') } - return context.hero_config_exists('livekit', args.name) +//register the config for the future +pub fn set(o LivekitServer)! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set("livekit", o.name, heroscript)! } -fn config_load(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - mut heroscript := context.hero_config_get('livekit', args.name)! - play(heroscript: heroscript)! +//does the config exists? +pub fn exists(args_ ArgsGet)! bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists("livekit", args.name) } -fn config_save(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_set('livekit', args.name, heroscript_default()!)! +pub fn delete(args_ ArgsGet)! { + mut args := args_get(args_) + mut context:=base.context()! + context.hero_config_delete("livekit",args.name)! + if args.name in livekit_global { + //del livekit_global[args.name] + } } -fn set(o LivekitServer) ! { - mut o2 := obj_init(o)! - livekit_global['default'] = &o2 +//only sets in mem, does not set as config +fn set_in_mem(o LivekitServer)! { + mut o2:=obj_init(o)! + livekit_global[o.name] = &o2 + livekit_default = o.name } + @[params] pub struct PlayArgs { pub mut: - name string = 'default' - heroscript string // if filled in then plbook will be made out of it - plbook ?playbook.PlayBook - reset bool - - start bool - stop bool - restart bool - delete bool - configure bool // make sure there is at least one installed + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool } pub fn play(args_ PlayArgs) ! { - mut args := args_ + + mut args:=args_ - if args.heroscript == '' { - args.heroscript = heroscript_default()! - } - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } - mut install_actions := plbook.find(filter: 'livekit.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - mut p := install_action.params - mycfg := cfg_play(p)! - set(mycfg)! - } - } + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + mut install_actions := plbook.find(filter: 'livekit.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript:=install_action.heroscript() + mut obj2:=heroscript_loads(heroscript)! + set(obj2)! + } + } + + mut other_actions := plbook.find(filter: 'livekit.')! + 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 livekit.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action livekit.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut livekit_obj:=get(name:name)! + console.print_debug("action object:\n${livekit_obj}") + if other_action.name == "start"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action livekit.${other_action.name}") + livekit_obj.restart()! + } + } + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// -// load from disk and make sure is properly intialized +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 LivekitServer) reload() ! { - switch(self.name) - self = obj_init(self)! + switch(self.name) + self=obj_init(self)! } pub fn (mut self LivekitServer) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('livekit start') + console.print_header('livekit start') - configure()! + if ! installed()!{ + install()! + } - start_pre()! + configure()! - mut sm := startupmanager.get()! + start_pre()! - for zprocess in startupcmd()! { - sm.start(zprocess.name)! - } + for zprocess in startupcmd()!{ + mut sm:=startupmanager_get(zprocess.startuptype)! - start_post()! + console.print_debug('starting livekit with ${zprocess.startuptype}...') + + sm.new(zprocess)! + + sm.start(zprocess.name)! + } + + start_post()! + + for _ in 0 .. 50 { + if self.running()! { + return + } + time.sleep(100 * time.millisecond) + } + return error('livekit did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('livekit did not install properly.') } -pub fn (mut self LivekitServer) install_start(args RestartArgs) ! { - switch(self.name) - self.install(args)! - self.start()! +pub fn (mut self LivekitServer) install_start(args InstallArgs) ! { + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self LivekitServer) stop() ! { - switch(self.name) - stop_pre()! - mut sm := startupmanager.get()! - for zprocess in startupcmd()! { - 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 LivekitServer) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self LivekitServer) running() !bool { - switch(self.name) - mut sm := startupmanager.get()! + switch(self.name) - // walk over the generic processes, if not running return - for zprocess in startupcmd()! { - 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 LivekitServer) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } + pub fn (mut self LivekitServer) destroy() ! { - switch(self.name) - - self.stop()! - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } -// switch instance to be used for livekit + + +//switch instance to be used for livekit pub fn switch(name string) { - livekit_default = name + livekit_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/infra/screen/screen_factory_.v b/lib/installers/infra/screen/screen_factory_.v index fff3aaa7..4b3a06fb 100644 --- a/lib/installers/infra/screen/screen_factory_.v +++ b/lib/installers/infra/screen/screen_factory_.v @@ -1,71 +1,124 @@ module screen +import freeflowuniverse.herolib.core.base +import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit +import time __global ( - screen_global map[string]&Screen - screen_default string + screen_global map[string]&Screen + screen_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&Screen { - return &Screen{} +pub fn get(args_ ArgsGet) !&Screen { + return &Screen{} } +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'screen.')! + 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 screen.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action screen.install") + install()! + } + } + } + +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# 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()! + } + } } + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } pub fn (mut self Screen) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } + pub fn (mut self Screen) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + destroy()! } -// switch instance to be used for screen + + +//switch instance to be used for screen pub fn switch(name string) { - screen_default = name + screen_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/infra/zinit/zinit_factory_.v b/lib/installers/infra/zinit/zinit_factory_.v index 49e9cf6b..8b7269a0 100644 --- a/lib/installers/infra/zinit/zinit_factory_.v +++ b/lib/installers/infra/zinit/zinit_factory_.v @@ -2,152 +2,220 @@ module zinit import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit -import freeflowuniverse.herolib.ui.console import time __global ( - zinit_global map[string]&Zinit - zinit_default string + zinit_global map[string]&Zinit + zinit_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&Zinit { - return &Zinit{} +pub fn get(args_ ArgsGet) !&Zinit { + return &Zinit{} } +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'zinit.')! + 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 zinit.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action zinit.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut zinit_obj:=get(name:name)! + console.print_debug("action object:\n${zinit_obj}") + if other_action.name == "start"{ + console.print_debug("install action zinit.${other_action.name}") + zinit_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action zinit.${other_action.name}") + zinit_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action zinit.${other_action.name}") + zinit_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()! + } + } } + pub fn (mut self Zinit) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('zinit start') + console.print_header('zinit 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 zinit with ${zprocess.startuptype}...') + console.print_debug('starting zinit 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('zinit did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('zinit did not install properly.') } pub fn (mut self Zinit) install_start(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self Zinit) 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 Zinit) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self Zinit) 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 Zinit) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self Zinit) build() ! { - switch(self.name) - build()! + switch(self.name) + build()! } pub fn (mut self Zinit) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } -// switch instance to be used for zinit + + +//switch instance to be used for zinit pub fn switch(name string) { - zinit_default = name + zinit_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/install_multi.v b/lib/installers/install_multi.v index f1fdc192..14e1169d 100644 --- a/lib/installers/install_multi.v +++ b/lib/installers/install_multi.v @@ -92,7 +92,8 @@ pub fn install_multi(args_ InstallArgs) ! { rc.install(reset: args.reset)! } 'rust' { - rust.install(reset: args.reset)! + mut i:=rust.get()! + i.install(reset: args.reset)! } 'golang' { mut g := golang.get()! @@ -152,10 +153,12 @@ pub fn install_multi(args_ InstallArgs) ! { vscode.install(reset: args.reset)! } 'nodejs' { - nodejs.install(reset: args.reset)! + mut i:=nodejs.get()! + i.install(reset: args.reset)! } 'python' { - python.install()! + mut i:=python.get()! + i.install()! } // 'herodev' { // herodev.install()! diff --git a/lib/installers/lang/golang/golang_factory_.v b/lib/installers/lang/golang/golang_factory_.v index 01e1c464..e8f2113a 100644 --- a/lib/installers/lang/golang/golang_factory_.v +++ b/lib/installers/lang/golang/golang_factory_.v @@ -1,76 +1,128 @@ module golang +import freeflowuniverse.herolib.core.base +import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit -import freeflowuniverse.herolib.ui.console +import time __global ( - golang_global map[string]&GolangInstaller - golang_default string + golang_global map[string]&GolangInstaller + golang_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&GolangInstaller { - return &GolangInstaller{} +pub fn get(args_ ArgsGet) !&GolangInstaller { + return &GolangInstaller{} } +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'golang.')! + 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 golang.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action golang.install") + install()! + } + } + } + +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# 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()! + } + } } + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } pub fn (mut self GolangInstaller) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed_()!) { - install_()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self GolangInstaller) build() ! { - switch(self.name) - build_()! + switch(self.name) + build()! } pub fn (mut self GolangInstaller) destroy() ! { - switch(self.name) - destroy_()! + switch(self.name) + destroy()! } -// switch instance to be used for golang + + +//switch instance to be used for golang pub fn switch(name string) { - golang_default = name + golang_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/lang/nodejs/.heroscript b/lib/installers/lang/nodejs/.heroscript index a381e30a..78c781fc 100644 --- a/lib/installers/lang/nodejs/.heroscript +++ b/lib/installers/lang/nodejs/.heroscript @@ -8,4 +8,5 @@ templates: false build: false startupmanager: false + supported_platforms: "" diff --git a/lib/installers/lang/nodejs/nodejs_factory_.v b/lib/installers/lang/nodejs/nodejs_factory_.v index 5c069bf2..fb25912e 100644 --- a/lib/installers/lang/nodejs/nodejs_factory_.v +++ b/lib/installers/lang/nodejs/nodejs_factory_.v @@ -3,36 +3,122 @@ module nodejs import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - nodejs_global map[string]&NodeJS - nodejs_default string + nodejs_global map[string]&NodeJS + nodejs_default string ) /////////FACTORY +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&NodeJS { + return &NodeJS{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'nodejs.')! + 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 nodejs.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action nodejs.install") + install()! + } + } + } + +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# 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()! + } + } +} + + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self NodeJS) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! + +pub fn (mut self NodeJS) destroy() ! { + switch(self.name) + destroy()! +} + + + +//switch instance to be used for nodejs +pub fn switch(name string) { + nodejs_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/lang/python/.heroscript b/lib/installers/lang/python/.heroscript index 7d1dbd1a..2e712c7a 100644 --- a/lib/installers/lang/python/.heroscript +++ b/lib/installers/lang/python/.heroscript @@ -8,4 +8,5 @@ templates: false build: false startupmanager: false + supported_platforms: "" diff --git a/lib/installers/lang/python/python_factory_.v b/lib/installers/lang/python/python_factory_.v index 2a8072eb..badf2c00 100644 --- a/lib/installers/lang/python/python_factory_.v +++ b/lib/installers/lang/python/python_factory_.v @@ -3,36 +3,122 @@ module python import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - python_global map[string]&Python - python_default string + python_global map[string]&Python + python_default string ) /////////FACTORY +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&Python { + return &Python{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'python.')! + 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 python.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action python.install") + install()! + } + } + } + +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# 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()! + } + } +} + + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self Python) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! + +pub fn (mut self Python) destroy() ! { + switch(self.name) + destroy()! +} + + + +//switch instance to be used for python +pub fn switch(name string) { + python_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/lang/rust/.heroscript b/lib/installers/lang/rust/.heroscript index 70cd6a4c..b3ee0386 100644 --- a/lib/installers/lang/rust/.heroscript +++ b/lib/installers/lang/rust/.heroscript @@ -8,4 +8,4 @@ templates: false build: false startupmanager: false - + supported_platforms: "" diff --git a/lib/installers/lang/rust/rust_factory_.v b/lib/installers/lang/rust/rust_factory_.v index 5a50ff54..c976f71f 100644 --- a/lib/installers/lang/rust/rust_factory_.v +++ b/lib/installers/lang/rust/rust_factory_.v @@ -3,36 +3,122 @@ module rust import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - rust_global map[string]&RustInstaller - rust_default string + rust_global map[string]&RustInstaller + rust_default string ) /////////FACTORY +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&RustInstaller { + return &RustInstaller{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'rust.')! + 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 rust.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action rust.install") + install()! + } + } + } + +} + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////# 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()! + } + } +} + + + @[params] -pub struct InstallArgs { +pub struct InstallArgs{ pub mut: - reset bool + reset bool } -pub fn install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self RustInstaller) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! + +pub fn (mut self RustInstaller) destroy() ! { + switch(self.name) + destroy()! +} + + + +//switch instance to be used for rust +pub fn switch(name string) { + rust_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/net/mycelium/mycelium_factory_.v b/lib/installers/net/mycelium/mycelium_factory_.v index 3030a224..fefa2188 100644 --- a/lib/installers/net/mycelium/mycelium_factory_.v +++ b/lib/installers/net/mycelium/mycelium_factory_.v @@ -4,277 +4,288 @@ import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - mycelium_installer_global map[string]&MyceliumInstaller - mycelium_installer_default string + mycelium_global map[string]&MyceliumInstaller + mycelium_default string ) /////////FACTORY @[params] -pub struct ArgsGet { +pub struct ArgsGet{ pub mut: - name string + name string } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args +fn args_get (args_ ArgsGet) ArgsGet { + mut args:=args_ + if args.name == ""{ + args.name = "default" + } + return args } -pub fn get(args_ ArgsGet) !&MyceliumInstaller { - mut context := base.context()! - mut args := args_get(args_) - mut obj := MyceliumInstaller{} - if args.name !in mycelium_installer_global { - if !exists(args)! { - set(obj)! - } else { - heroscript := context.hero_config_get('mycelium', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! - } - } - return mycelium_installer_global[args.name] or { - println(mycelium_installer_global) - // bug if we get here because should be in globals - panic('could not get config for mycelium with name, is bug:${args.name}') - } +pub fn get(args_ ArgsGet) !&MyceliumInstaller { + mut context:=base.context()! + mut args := args_get(args_) + mut obj := MyceliumInstaller{} + if !(args.name in mycelium_global) { + if ! exists(args)!{ + set(obj)! + }else{ + heroscript := context.hero_config_get("mycelium",args.name)! + mut obj_:=heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return mycelium_global[args.name] or { + println(mycelium_global) + //bug if we get here because should be in globals + panic("could not get config for mycelium with name, is bug:${args.name}") + } } -// register the config for the future -pub fn set(o MyceliumInstaller) ! { - set_in_mem(o)! - mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('mycelium', o.name, heroscript)! +//register the config for the future +pub fn set(o MyceliumInstaller)! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set("mycelium", o.name, heroscript)! } -// does the config exists? -pub fn exists(args_ ArgsGet) !bool { - mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('mycelium', args.name) +//does the config exists? +pub fn exists(args_ ArgsGet)! bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists("mycelium", args.name) } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) - mut context := base.context()! - context.hero_config_delete('mycelium', args.name)! - if args.name in mycelium_installer_global { - // del mycelium_installer_global[args.name] - } +pub fn delete(args_ ArgsGet)! { + mut args := args_get(args_) + mut context:=base.context()! + context.hero_config_delete("mycelium",args.name)! + if args.name in mycelium_global { + //del mycelium_global[args.name] + } } -// only sets in mem, does not set as config -fn set_in_mem(o MyceliumInstaller) ! { - mut o2 := obj_init(o)! - mycelium_installer_global[o.name] = &o2 - mycelium_installer_default = o.name +//only sets in mem, does not set as config +fn set_in_mem(o MyceliumInstaller)! { + mut o2:=obj_init(o)! + mycelium_global[o.name] = &o2 + mycelium_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 args := args_ + + mut args:=args_ - mut plbook := args.plbook or { playbook.new(text: args.heroscript)! } - mut install_actions := plbook.find(filter: 'mycelium.configure')! - if install_actions.len > 0 { - for install_action in install_actions { - heroscript := install_action.heroscript() - mut obj2 := heroscript_loads(heroscript)! - set(obj2)! - } - } + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + mut install_actions := plbook.find(filter: 'mycelium.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript:=install_action.heroscript() + mut obj2:=heroscript_loads(heroscript)! + set(obj2)! + } + } - mut other_actions := plbook.find(filter: 'mycelium.')! - 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 mycelium.destroy') - destroy()! - } - if other_action.name == 'install' { - console.print_debug('install action mycelium.install') - install()! - } - } - if other_action.name in ['start', 'stop', 'restart'] { - mut p := other_action.params - name := p.get('name')! - mut mycelium_obj := get(name: name)! - console.print_debug('action object:\n${mycelium_obj}') - if other_action.name == 'start' { - console.print_debug('install action mycelium.${other_action.name}') - mycelium_obj.start()! - } + mut other_actions := plbook.find(filter: 'mycelium.')! + 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 mycelium.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action mycelium.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut mycelium_obj:=get(name:name)! + console.print_debug("action object:\n${mycelium_obj}") + if other_action.name == "start"{ + console.print_debug("install action mycelium.${other_action.name}") + mycelium_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action mycelium.${other_action.name}") + mycelium_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action mycelium.${other_action.name}") + mycelium_obj.restart()! + } + } + } - if other_action.name == 'stop' { - console.print_debug('install action mycelium.${other_action.name}') - mycelium_obj.stop()! - } - if other_action.name == 'restart' { - console.print_debug('install action mycelium.${other_action.name}') - mycelium_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 MyceliumInstaller) reload() ! { - switch(self.name) - self = obj_init(self)! + switch(self.name) + self=obj_init(self)! } pub fn (mut self MyceliumInstaller) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('mycelium start') + console.print_header('mycelium 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 mycelium with ${zprocess.startuptype}...') + console.print_debug('starting mycelium 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('mycelium did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('mycelium did not install properly.') } pub fn (mut self MyceliumInstaller) install_start(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self MyceliumInstaller) 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 MyceliumInstaller) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self MyceliumInstaller) 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 MyceliumInstaller) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self MyceliumInstaller) build() ! { - switch(self.name) - build()! + switch(self.name) + build()! } pub fn (mut self MyceliumInstaller) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } -// switch instance to be used for mycelium + + +//switch instance to be used for mycelium pub fn switch(name string) { - mycelium_installer_default = name + mycelium_default = name } -// helpers + +//helpers @[params] -pub struct DefaultConfigArgs { - instance string = 'default' +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/net/wireguard/wireguard_installer_actions.v b/lib/installers/net/wireguard/wireguard_installer_actions.v new file mode 100644 index 00000000..d2848a89 --- /dev/null +++ b/lib/installers/net/wireguard/wireguard_installer_actions.v @@ -0,0 +1,114 @@ +module wireguard_installer + +import freeflowuniverse.herolib.osal +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.core.texttools +import freeflowuniverse.herolib.core.pathlib + +import freeflowuniverse.herolib.installers.ulist + + +import os + + +//////////////////// 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()!} wireguard_installer 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 wireguard_installer version.\n${res.output}") + // } + // if texttools.version(version) == texttools.version(r[0]) { + // return true + // } + return false +} + +//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{} +} + +//uploads to S3 server if configured +fn upload() ! { + // installers.upload( + // cmdname: 'wireguard_installer' + // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/wireguard_installer' + // )! + +} + +fn install() ! { + console.print_header('install wireguard_installer') + //THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED + // mut url := '' + // if core.is_linux_arm() { + // url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_linux_arm64.tar.gz' + // } else if core.is_linux_intel() { + // url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_linux_amd64.tar.gz' + // } else if core.is_osx_arm() { + // url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_darwin_arm64.tar.gz' + // } else if osal.is_osx_intel() { + // url = 'https://github.com/wireguard_installer-dev/wireguard_installer/releases/download/v${version}/wireguard_installer_${version}_darwin_amd64.tar.gz' + // } else { + // return error('unsported platform') + // } + + // mut dest := osal.download( + // url: url + // minsize_kb: 9000 + // expand_dir: '/tmp/wireguard_installer' + // )! + + // //dest.moveup_single_subdir()! + + // mut binpath := dest.file_get('wireguard_installer')! + // osal.cmd_add( + // cmdname: 'wireguard_installer' + // source: binpath.path + // )! +} + + +fn destroy() ! { + + // mut systemdfactory := systemd.new()! + // systemdfactory.destroy("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 + // ")! + + +} + diff --git a/lib/installers/net/wireguard/wireguard_installer_factory_.v b/lib/installers/net/wireguard/wireguard_installer_factory_.v new file mode 100644 index 00000000..46c99b94 --- /dev/null +++ b/lib/installers/net/wireguard/wireguard_installer_factory_.v @@ -0,0 +1,124 @@ +module wireguard_installer + +import freeflowuniverse.herolib.core.base +import freeflowuniverse.herolib.core.playbook +import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + +import freeflowuniverse.herolib.sysadmin.startupmanager +import freeflowuniverse.herolib.osal.zinit +import time + +__global ( + wireguard_installer_global map[string]&WireGuard + wireguard_installer_default string +) + +/////////FACTORY + +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&WireGuard { + return &WireGuard{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'wireguard_installer.')! + 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 wireguard_installer.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action wireguard_installer.install") + install()! + } + } + } + +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////# 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()! + } + } +} + + + +@[params] +pub struct InstallArgs{ +pub mut: + reset bool +} + +pub fn (mut self WireGuard) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } +} + + +pub fn (mut self WireGuard) destroy() ! { + switch(self.name) + destroy()! +} + + + +//switch instance to be used for wireguard_installer +pub fn switch(name string) { + wireguard_installer_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' +} diff --git a/lib/installers/net/wireguard/wireguard_installer_model.v b/lib/installers/net/wireguard/wireguard_installer_model.v new file mode 100644 index 00000000..a0ea9121 --- /dev/null +++ b/lib/installers/net/wireguard/wireguard_installer_model.v @@ -0,0 +1,43 @@ +module wireguard_installer +import freeflowuniverse.herolib.data.paramsparser +import freeflowuniverse.herolib.data.encoderhero +import os + +pub const version = '0.0.0' +const singleton = false +const default = true + +//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED +@[heap] +pub struct WireGuard { +pub mut: + name string = 'default' +} + + + +//your checking & initialization code if needed +fn obj_init(mycfg_ WireGuard)!WireGuard{ + mut mycfg:=mycfg_ + if mycfg.password == '' && mycfg.secret == '' { + return error('password or secret needs to be filled in for ${mycfg.name}') + } + return mycfg +} + +//called before start if done +fn configure() ! { + //mut installer := get()! +} + + +/////////////NORMALLY NO NEED TO TOUCH + +pub fn heroscript_dumps(obj WireGuard) !string { + return encoderhero.encode[WireGuard ](obj)! +} + +pub fn heroscript_loads(heroscript string) !WireGuard { + mut obj := encoderhero.decode[WireGuard](heroscript)! + return obj +} diff --git a/lib/installers/net/yggdrasil/.heroscript b/lib/installers/net/yggdrasil/.heroscript index 418e748e..be54967a 100644 --- a/lib/installers/net/yggdrasil/.heroscript +++ b/lib/installers/net/yggdrasil/.heroscript @@ -8,4 +8,4 @@ templates: false build: true startupmanager: true - + supported_platforms: "" diff --git a/lib/installers/net/yggdrasil/yggdrasil_factory_.v b/lib/installers/net/yggdrasil/yggdrasil_factory_.v index e65fc8c1..0bc63030 100644 --- a/lib/installers/net/yggdrasil/yggdrasil_factory_.v +++ b/lib/installers/net/yggdrasil/yggdrasil_factory_.v @@ -3,135 +3,219 @@ module yggdrasil import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - yggdrasil_global map[string]&YggdrasilInstaller - yggdrasil_default string + yggdrasil_global map[string]&YggdrasilInstaller + yggdrasil_default string ) /////////FACTORY +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&YggdrasilInstaller { + return &YggdrasilInstaller{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'yggdrasil.')! + 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 yggdrasil.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action yggdrasil.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut yggdrasil_obj:=get(name:name)! + console.print_debug("action object:\n${yggdrasil_obj}") + if other_action.name == "start"{ + console.print_debug("install action yggdrasil.${other_action.name}") + yggdrasil_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action yggdrasil.${other_action.name}") + yggdrasil_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action yggdrasil.${other_action.name}") + yggdrasil_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()! + } + } } + pub fn (mut self YggdrasilInstaller) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('yggdrasil start') + console.print_header('yggdrasil 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 yggdrasil with ${zprocess.startuptype}...') + console.print_debug('starting yggdrasil 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('yggdrasil did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('yggdrasil did not install properly.') } -pub fn (mut self YggdrasilInstaller) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! +pub fn (mut self YggdrasilInstaller) install_start(args InstallArgs) ! { + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self YggdrasilInstaller) 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 YggdrasilInstaller) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self YggdrasilInstaller) 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 install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self YggdrasilInstaller) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! +pub fn (mut self YggdrasilInstaller) build() ! { + switch(self.name) + build()! } -pub fn build() ! { - build_()! +pub fn (mut self YggdrasilInstaller) destroy() ! { + switch(self.name) + self.stop() or {} + destroy()! +} + + + +//switch instance to be used for yggdrasil +pub fn switch(name string) { + yggdrasil_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' } diff --git a/lib/installers/sysadmintools/actrunner/.heroscript b/lib/installers/sysadmintools/actrunner/.heroscript index b461c70a..8a02e772 100644 --- a/lib/installers/sysadmintools/actrunner/.heroscript +++ b/lib/installers/sysadmintools/actrunner/.heroscript @@ -8,4 +8,4 @@ templates: false build: true startupmanager: true - + supported_platforms: "" diff --git a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v index 46b25c83..1fdca952 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v @@ -3,135 +3,219 @@ module actrunner import freeflowuniverse.herolib.core.base import freeflowuniverse.herolib.core.playbook import freeflowuniverse.herolib.ui.console +import freeflowuniverse.herolib.data.paramsparser + import freeflowuniverse.herolib.sysadmin.startupmanager import freeflowuniverse.herolib.osal.zinit import time __global ( - actrunner_global map[string]&ActRunner - actrunner_default string + actrunner_global map[string]&ActRunner + actrunner_default string ) /////////FACTORY +@[params] +pub struct ArgsGet{ +pub mut: + name string +} + +pub fn get(args_ ArgsGet) !&ActRunner { + return &ActRunner{} +} + +@[params] +pub struct PlayArgs { +pub mut: + heroscript string //if filled in then plbook will be made out of it + plbook ?playbook.PlayBook + reset bool +} + +pub fn play(args_ PlayArgs) ! { + + mut args:=args_ + + mut plbook := args.plbook or { + playbook.new(text: args.heroscript)! + } + + + mut other_actions := plbook.find(filter: 'actrunner.')! + 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 actrunner.destroy") + destroy()! + } + if other_action.name == "install"{ + console.print_debug("install action actrunner.install") + install()! + } + } + if other_action.name in ["start","stop","restart"]{ + mut p := other_action.params + name := p.get('name')! + mut actrunner_obj:=get(name:name)! + console.print_debug("action object:\n${actrunner_obj}") + if other_action.name == "start"{ + console.print_debug("install action actrunner.${other_action.name}") + actrunner_obj.start()! + } + + if other_action.name == "stop"{ + console.print_debug("install action actrunner.${other_action.name}") + actrunner_obj.stop()! + } + if other_action.name == "restart"{ + console.print_debug("install action actrunner.${other_action.name}") + actrunner_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()! + } + } } + pub fn (mut self ActRunner) start() ! { - switch(self.name) - if self.running()! { - return - } + switch(self.name) + if self.running()!{ + return + } - console.print_header('actrunner start') + console.print_header('actrunner 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 actrunner with ${zprocess.startuptype}...') + console.print_debug('starting actrunner 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('actrunner did not install properly.') - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('actrunner did not install properly.') } -pub fn (mut self ActRunner) install_start(model InstallArgs) ! { - switch(self.name) - self.install(model)! - self.start()! +pub fn (mut self ActRunner) install_start(args InstallArgs) ! { + switch(self.name) + self.install(args)! + self.start()! } pub fn (mut self ActRunner) 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 ActRunner) restart() ! { - switch(self.name) - self.stop()! - self.start()! + switch(self.name) + self.stop()! + self.start()! } pub fn (mut self ActRunner) 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 install(args InstallArgs) ! { - if args.reset { - destroy()! - } - if !(installed_()!) { - install_()! - } +pub fn (mut self ActRunner) install(args InstallArgs) ! { + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } -pub fn destroy() ! { - destroy_()! +pub fn (mut self ActRunner) build() ! { + switch(self.name) + build()! } -pub fn build() ! { - build_()! +pub fn (mut self ActRunner) destroy() ! { + switch(self.name) + self.stop() or {} + destroy()! +} + + + +//switch instance to be used for actrunner +pub fn switch(name string) { + actrunner_default = name +} + + +//helpers + +@[params] +pub struct DefaultConfigArgs{ + instance string = 'default' }