From c157c866008824abd5c282535c5213197bb95243 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Mon, 10 Feb 2025 09:00:49 +0000 Subject: [PATCH] refactor: move zinit installer to infra - Move the zinit installer from `sysadmintools` to `infra`. - This change improves the organization of the codebase and - makes it easier to find and manage installers. The old - `zinit` module was a factory only and is removed. The - `zinit_installer` is now a normal installer. The code is - significantly refactored. --- examples/installers/zinit_installer.vsh | 3 +- lib/installers/infra/zinit/zinit_factory_.v | 221 ------------------ lib/installers/infra/zinit/zinit_model.v | 26 --- .../{zinit => zinit_installer}/.heroscript | 4 +- .../{zinit => zinit_installer}/readme.md | 0 .../zinit_actions.v | 94 ++++---- .../zinit_installer}/zinit_factory_.v | 5 +- .../infra/zinit_installer/zinit_model.v | 36 +++ lib/installers/install_multi.v | 10 +- lib/installers/lang/golang/golang_factory_.v | 131 +++++------ lib/installers/lang/nodejs/nodejs_factory_.v | 128 +++++----- lib/installers/lang/python/python_factory_.v | 128 +++++----- lib/installers/lang/rust/rust_factory_.v | 128 +++++----- .../sysadmintools/zinit/.heroscript | 13 -- lib/installers/sysadmintools/zinit/readme.md | 17 -- .../sysadmintools/zinit/zinit_actions.v | 133 ----------- .../sysadmintools/zinit/zinit_model.v | 26 --- lib/lang/python/python.v | 2 +- 18 files changed, 331 insertions(+), 774 deletions(-) delete mode 100644 lib/installers/infra/zinit/zinit_factory_.v delete mode 100644 lib/installers/infra/zinit/zinit_model.v rename lib/installers/infra/{zinit => zinit_installer}/.heroscript (70%) rename lib/installers/infra/{zinit => zinit_installer}/readme.md (100%) rename lib/installers/infra/{zinit => zinit_installer}/zinit_actions.v (78%) rename lib/installers/{sysadmintools/zinit => infra/zinit_installer}/zinit_factory_.v (97%) create mode 100644 lib/installers/infra/zinit_installer/zinit_model.v delete mode 100644 lib/installers/sysadmintools/zinit/.heroscript delete mode 100644 lib/installers/sysadmintools/zinit/readme.md delete mode 100644 lib/installers/sysadmintools/zinit/zinit_actions.v delete mode 100644 lib/installers/sysadmintools/zinit/zinit_model.v diff --git a/examples/installers/zinit_installer.vsh b/examples/installers/zinit_installer.vsh index 43f09971..418a176d 100755 --- a/examples/installers/zinit_installer.vsh +++ b/examples/installers/zinit_installer.vsh @@ -1,6 +1,7 @@ #!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run -import freeflowuniverse.herolib.installers.sysadmintools.zinit as zinit_installer +import freeflowuniverse.herolib.installers.infra.zinit_installer mut installer := zinit_installer.get()! +// installer.install()! installer.start()! diff --git a/lib/installers/infra/zinit/zinit_factory_.v b/lib/installers/infra/zinit/zinit_factory_.v deleted file mode 100644 index 8b7269a0..00000000 --- a/lib/installers/infra/zinit/zinit_factory_.v +++ /dev/null @@ -1,221 +0,0 @@ -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 time - -__global ( - zinit_global map[string]&Zinit - zinit_default string -) - -/////////FACTORY - -@[params] -pub struct ArgsGet{ -pub mut: - name string -} - -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()! - } - } -} - - -pub fn (mut self Zinit) start() ! { - switch(self.name) - if self.running()!{ - return - } - - console.print_header('zinit start') - - if ! installed()!{ - install()! - } - - configure()! - - start_pre()! - - for zprocess in startupcmd()!{ - mut sm:=startupmanager_get(zprocess.startuptype)! - - console.print_debug('starting zinit 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('zinit did not install properly.') - -} - -pub fn (mut self Zinit) install_start(args InstallArgs) ! { - 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()! -} - -pub fn (mut self Zinit) restart() ! { - switch(self.name) - self.stop()! - self.start()! -} - -pub fn (mut self Zinit) running() !bool { - 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()! -} - -@[params] -pub struct InstallArgs{ -pub mut: - reset bool -} - -pub fn (mut self Zinit) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } -} - -pub fn (mut self Zinit) build() ! { - switch(self.name) - build()! -} - -pub fn (mut self Zinit) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! -} - - - -//switch instance to be used for zinit -pub fn switch(name string) { - zinit_default = name -} - - -//helpers - -@[params] -pub struct DefaultConfigArgs{ - instance string = 'default' -} diff --git a/lib/installers/infra/zinit/zinit_model.v b/lib/installers/infra/zinit/zinit_model.v deleted file mode 100644 index 62b15229..00000000 --- a/lib/installers/infra/zinit/zinit_model.v +++ /dev/null @@ -1,26 +0,0 @@ -module zinit - -import freeflowuniverse.herolib.data.paramsparser -import os - -pub const version = '0.2.14' -const singleton = true -const default = true - -// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED - -pub struct Zinit { -pub mut: - name string = 'default' -} - -fn obj_init(obj_ Zinit) !Zinit { - // never call get here, only thing we can do here is work on object itself - mut obj := obj_ - return obj -} - -// called before start if done -fn configure() ! { - // mut installer := get()! -} diff --git a/lib/installers/infra/zinit/.heroscript b/lib/installers/infra/zinit_installer/.heroscript similarity index 70% rename from lib/installers/infra/zinit/.heroscript rename to lib/installers/infra/zinit_installer/.heroscript index dc494a72..97725c84 100644 --- a/lib/installers/infra/zinit/.heroscript +++ b/lib/installers/infra/zinit_installer/.heroscript @@ -1,7 +1,7 @@ !!hero_code.generate_installer - name:'zinit' - classname:'Zinit' + name:'zinit_installer' + classname:'ZinitInstaller' singleton:1 templates:0 default:1 diff --git a/lib/installers/infra/zinit/readme.md b/lib/installers/infra/zinit_installer/readme.md similarity index 100% rename from lib/installers/infra/zinit/readme.md rename to lib/installers/infra/zinit_installer/readme.md diff --git a/lib/installers/infra/zinit/zinit_actions.v b/lib/installers/infra/zinit_installer/zinit_actions.v similarity index 78% rename from lib/installers/infra/zinit/zinit_actions.v rename to lib/installers/infra/zinit_installer/zinit_actions.v index a4b2ddc1..524349cc 100644 --- a/lib/installers/infra/zinit/zinit_actions.v +++ b/lib/installers/infra/zinit_installer/zinit_actions.v @@ -1,16 +1,50 @@ -module zinit +module zinit_installer import freeflowuniverse.herolib.osal -import freeflowuniverse.herolib.core import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.osal.zinit -import freeflowuniverse.herolib.installers.ulist -import freeflowuniverse.herolib.installers.lang.rust import freeflowuniverse.herolib.develop.gittools +import freeflowuniverse.herolib.core import freeflowuniverse.herolib.osal.systemd +import freeflowuniverse.herolib.osal.zinit as zinit_module +import freeflowuniverse.herolib.installers.ulist +// import freeflowuniverse.herolib.core.pathlib +// import freeflowuniverse.herolib.installers.lang.golang +// import freeflowuniverse.herolib.installers.lang.rust +// import freeflowuniverse.herolib.installers.lang.python import os +fn startupcmd() ![]zinit_module.ZProcessNewArgs { + mut res := []zinit_module.ZProcessNewArgs{} + res << zinit_module.ZProcessNewArgs{ + name: 'zinit' + cmd: '/usr/local/bin/zinit init' + startuptype: .zinit + start: true + restart: true + } + return res +} + +fn running() !bool { + cmd := 'zinit list' + return osal.execute_ok(cmd) +} + +fn start_pre() ! { +} + +fn start_post() ! { +} + +fn stop_pre() ! { +} + +fn stop_post() ! { +} + +//////////////////// following actions are not specific to instance of the object + // checks if a certain version or above is installed fn installed() !bool { cmd := 'zinit --version' @@ -29,6 +63,15 @@ fn installed() !bool { 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() ! {} + fn install() ! { console.print_header('install zinit') if !core.is_linux()! { @@ -49,7 +92,6 @@ fn install() ! { )! osal.dir_ensure('/etc/zinit')! - console.print_header('install zinit done') } @@ -58,7 +100,7 @@ fn build() ! { return error('only support linux for now') } - rust.install()! + // rust.install() // install zinit if it was already done will return true console.print_header('build zinit') @@ -86,44 +128,6 @@ fn build() ! { )! } -// get the Upload List of the files -fn ulist_get() !ulist.UList { - return ulist.UList{} -} - -// uploads to S3 server if configured -fn upload() ! { -} - -fn startupcmd() ![]zinit.ZProcessNewArgs { - mut res := []zinit.ZProcessNewArgs{} - res << zinit.ZProcessNewArgs{ - name: 'zinit' - cmd: '/usr/local/bin/zinit init' - startuptype: .systemd - start: true - restart: true - } - return res -} - -fn running() !bool { - cmd := 'zinit list' - return osal.execute_ok(cmd) -} - -fn start_pre() ! { -} - -fn start_post() ! { -} - -fn stop_pre() ! { -} - -fn stop_post() ! { -} - fn destroy() ! { mut systemdfactory := systemd.new()! systemdfactory.destroy('zinit')! diff --git a/lib/installers/sysadmintools/zinit/zinit_factory_.v b/lib/installers/infra/zinit_installer/zinit_factory_.v similarity index 97% rename from lib/installers/sysadmintools/zinit/zinit_factory_.v rename to lib/installers/infra/zinit_installer/zinit_factory_.v index ea93bf65..9250fcf7 100644 --- a/lib/installers/sysadmintools/zinit/zinit_factory_.v +++ b/lib/installers/infra/zinit_installer/zinit_factory_.v @@ -1,9 +1,7 @@ -module zinit +module zinit_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 @@ -105,6 +103,7 @@ pub fn (mut self Zinit) start() ! { if self.running()! { return } + println('Here...') console.print_header('zinit start') diff --git a/lib/installers/infra/zinit_installer/zinit_model.v b/lib/installers/infra/zinit_installer/zinit_model.v new file mode 100644 index 00000000..74fcbb0f --- /dev/null +++ b/lib/installers/infra/zinit_installer/zinit_model.v @@ -0,0 +1,36 @@ +module zinit_installer + +import freeflowuniverse.herolib.data.encoderhero + +pub const version = '0.0.0' +const singleton = true +const default = true + +// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED +@[heap] +pub struct Zinit { +pub mut: + name string = 'default' +} + +// your checking & initialization code if needed +fn obj_init(mycfg_ Zinit) !Zinit { + mut mycfg := mycfg_ + return mycfg +} + +// called before start if done +fn configure() ! { + // mut installer := get()! +} + +/////////////NORMALLY NO NEED TO TOUCH + +pub fn heroscript_dumps(obj Zinit) !string { + return encoderhero.encode[Zinit](obj)! +} + +pub fn heroscript_loads(heroscript string) !Zinit { + mut obj := encoderhero.decode[Zinit](heroscript)! + return obj +} diff --git a/lib/installers/install_multi.v b/lib/installers/install_multi.v index 14e1169d..6ee89983 100644 --- a/lib/installers/install_multi.v +++ b/lib/installers/install_multi.v @@ -24,7 +24,7 @@ import freeflowuniverse.herolib.installers.sysadmintools.rclone // import freeflowuniverse.herolib.installers.sysadmintools.grafana // import freeflowuniverse.herolib.installers.sysadmintools.fungistor import freeflowuniverse.herolib.installers.sysadmintools.garage_s3 -import freeflowuniverse.herolib.installers.infra.zinit +import freeflowuniverse.herolib.installers.infra.zinit_installer @[params] pub struct InstallArgs { @@ -92,7 +92,7 @@ pub fn install_multi(args_ InstallArgs) ! { rc.install(reset: args.reset)! } 'rust' { - mut i:=rust.get()! + mut i := rust.get()! i.install(reset: args.reset)! } 'golang' { @@ -153,11 +153,11 @@ pub fn install_multi(args_ InstallArgs) ! { vscode.install(reset: args.reset)! } 'nodejs' { - mut i:=nodejs.get()! + mut i := nodejs.get()! i.install(reset: args.reset)! } 'python' { - mut i:=python.get()! + mut i := python.get()! i.install()! } // 'herodev' { @@ -182,7 +182,7 @@ pub fn install_multi(args_ InstallArgs) ! { i.install()! } 'zinit' { - mut i := zinit.get()! + mut i := zinit_installer.get()! i.install()! } else { diff --git a/lib/installers/lang/golang/golang_factory_.v b/lib/installers/lang/golang/golang_factory_.v index e8f2113a..c3896d57 100644 --- a/lib/installers/lang/golang/golang_factory_.v +++ b/lib/installers/lang/golang/golang_factory_.v @@ -4,125 +4,114 @@ 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 ( - 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 + 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 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()! - } - } - } + 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 +// helpers @[params] -pub struct DefaultConfigArgs{ - instance string = 'default' +pub struct DefaultConfigArgs { + instance string = 'default' } diff --git a/lib/installers/lang/nodejs/nodejs_factory_.v b/lib/installers/lang/nodejs/nodejs_factory_.v index fb25912e..89e1f052 100644 --- a/lib/installers/lang/nodejs/nodejs_factory_.v +++ b/lib/installers/lang/nodejs/nodejs_factory_.v @@ -4,121 +4,109 @@ 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 struct ArgsGet { pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&NodeJS { - return &NodeJS{} +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 + 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 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()! - } - } - } + 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()! - } - } + // 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 NodeJS) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + // if args.reset || (!installed()!) { + // install()! + // } } - pub fn (mut self NodeJS) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + // destroy()! } - - -//switch instance to be used for nodejs +// switch instance to be used for nodejs pub fn switch(name string) { - nodejs_default = name + nodejs_default = name } - -//helpers +// helpers @[params] -pub struct DefaultConfigArgs{ - instance string = 'default' +pub struct DefaultConfigArgs { + instance string = 'default' } diff --git a/lib/installers/lang/python/python_factory_.v b/lib/installers/lang/python/python_factory_.v index badf2c00..32845da9 100644 --- a/lib/installers/lang/python/python_factory_.v +++ b/lib/installers/lang/python/python_factory_.v @@ -4,121 +4,109 @@ 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 struct ArgsGet { pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&Python { - return &Python{} +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 + 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 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()! - } - } - } + 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()! - } - } + // 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 Python) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + // if args.reset || (!installed()!) { + // install()! + // } } - pub fn (mut self Python) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + // destroy()! } - - -//switch instance to be used for python +// switch instance to be used for python pub fn switch(name string) { - python_default = name + python_default = name } - -//helpers +// helpers @[params] -pub struct DefaultConfigArgs{ - instance string = 'default' +pub struct DefaultConfigArgs { + instance string = 'default' } diff --git a/lib/installers/lang/rust/rust_factory_.v b/lib/installers/lang/rust/rust_factory_.v index c976f71f..db4434c4 100644 --- a/lib/installers/lang/rust/rust_factory_.v +++ b/lib/installers/lang/rust/rust_factory_.v @@ -4,121 +4,109 @@ 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 struct ArgsGet { pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&RustInstaller { - return &RustInstaller{} +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 + 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 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()! - } - } - } + 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()! - } - } + // 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 RustInstaller) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + // if args.reset || (!installed()!) { + // install()! + // } } - pub fn (mut self RustInstaller) destroy() ! { - switch(self.name) - destroy()! + switch(self.name) + // destroy()! } - - -//switch instance to be used for rust +// switch instance to be used for rust pub fn switch(name string) { - rust_default = name + rust_default = name } - -//helpers +// helpers @[params] -pub struct DefaultConfigArgs{ - instance string = 'default' +pub struct DefaultConfigArgs { + instance string = 'default' } diff --git a/lib/installers/sysadmintools/zinit/.heroscript b/lib/installers/sysadmintools/zinit/.heroscript deleted file mode 100644 index dc494a72..00000000 --- a/lib/installers/sysadmintools/zinit/.heroscript +++ /dev/null @@ -1,13 +0,0 @@ - -!!hero_code.generate_installer - name:'zinit' - classname:'Zinit' - singleton:1 - templates:0 - default:1 - title:'' - supported_platforms:'' - reset:0 - startupmanager:1 - hasconfig:0 - build:1 \ No newline at end of file diff --git a/lib/installers/sysadmintools/zinit/readme.md b/lib/installers/sysadmintools/zinit/readme.md deleted file mode 100644 index 0d397590..00000000 --- a/lib/installers/sysadmintools/zinit/readme.md +++ /dev/null @@ -1,17 +0,0 @@ -# zinit - -Zinit is threefold startup manager, in linux will be launched inside systemd - -```v - - -#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run - -import freeflowuniverse.herolib.installers.sysadmintools.zinit as zinit_installer - -mut installer:=zinit_installer.get()! -installer.start()! - - -``` - diff --git a/lib/installers/sysadmintools/zinit/zinit_actions.v b/lib/installers/sysadmintools/zinit/zinit_actions.v deleted file mode 100644 index 2a1f9267..00000000 --- a/lib/installers/sysadmintools/zinit/zinit_actions.v +++ /dev/null @@ -1,133 +0,0 @@ -module zinit - -import freeflowuniverse.herolib.osal -import freeflowuniverse.herolib.ui.console -import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.core -import freeflowuniverse.herolib.osal.zinit -import freeflowuniverse.herolib.installers.ulist -import freeflowuniverse.herolib.installers.lang.rust -import freeflowuniverse.herolib.develop.gittools -import freeflowuniverse.herolib.osal.systemd -import os - -// checks if a certain version or above is installed -fn installed() !bool { - cmd := 'zinit --version' - // console.print_debug(cmd) - res := os.execute(cmd) - if res.exit_code == 0 { - r := res.output.split_into_lines().filter(it.trim_space().starts_with('zinit v')) - if r.len != 1 { - return error("couldn't parse zinit version.\n${res.output}") - } - if texttools.version(version) == texttools.version(r[0].all_after_first('zinit v')) { - return true - } - } - console.print_debug(res.str()) - return false -} - -fn install() ! { - console.print_header('install zinit') - if !core.is_linux()! { - return error('only support linux for now') - } - - release_url := 'https://github.com/threefoldtech/zinit/releases/download/v0.2.14/zinit' - - mut dest := osal.download( - url: release_url - minsize_kb: 2000 - reset: true - )! - - osal.cmd_add( - cmdname: 'zinit' - source: dest.path - )! - - osal.dir_ensure('/etc/zinit')! - - console.print_header('install zinit done') -} - -fn build() ! { - if !core.is_linux()! { - return error('only support linux for now') - } - - rust.install()! - - // install zinit if it was already done will return true - console.print_header('build zinit') - - mut gs := gittools.get(coderoot: '/tmp/builder')! - mut repo := gs.get_repo( - url: 'https://github.com/threefoldtech/zinit' - reset: true - pull: true - )! - gitpath := repo.path() - - // source ${osal.profile_path()!} - - cmd := ' - source ~/.cargo/env - cd ${gitpath} - make release - ' - osal.execute_stdout(cmd)! - - osal.cmd_add( - cmdname: 'zinit' - source: '/tmp/builder/github/threefoldtech/zinit/target/x86_64-unknown-linux-musl/release/zinit' - )! -} - -// get the Upload List of the files -fn ulist_get() !ulist.UList { - return ulist.UList{} -} - -// uploads to S3 server if configured -fn upload() ! { -} - -fn startupcmd() ![]zinit.ZProcessNewArgs { - mut res := []zinit.ZProcessNewArgs{} - res << zinit.ZProcessNewArgs{ - name: 'zinit' - cmd: '/usr/local/bin/zinit init' - startuptype: .systemd - start: true - restart: true - } - return res -} - -fn running() !bool { - cmd := 'zinit list' - return osal.execute_ok(cmd) -} - -fn start_pre() ! { -} - -fn start_post() ! { -} - -fn stop_pre() ! { -} - -fn stop_post() ! { -} - -fn destroy() ! { - mut systemdfactory := systemd.new()! - systemdfactory.destroy('zinit')! - - osal.process_kill_recursive(name: 'zinit')! - osal.cmd_delete('zinit')! -} diff --git a/lib/installers/sysadmintools/zinit/zinit_model.v b/lib/installers/sysadmintools/zinit/zinit_model.v deleted file mode 100644 index 62b15229..00000000 --- a/lib/installers/sysadmintools/zinit/zinit_model.v +++ /dev/null @@ -1,26 +0,0 @@ -module zinit - -import freeflowuniverse.herolib.data.paramsparser -import os - -pub const version = '0.2.14' -const singleton = true -const default = true - -// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED - -pub struct Zinit { -pub mut: - name string = 'default' -} - -fn obj_init(obj_ Zinit) !Zinit { - // never call get here, only thing we can do here is work on object itself - mut obj := obj_ - return obj -} - -// called before start if done -fn configure() ! { - // mut installer := get()! -} diff --git a/lib/lang/python/python.v b/lib/lang/python/python.v index 047b2254..9227c845 100644 --- a/lib/lang/python/python.v +++ b/lib/lang/python/python.v @@ -54,7 +54,7 @@ pub fn new(args_ PythonEnvArgs) !PythonEnv { toinstall := !py.db.exists(key: key_install)! if toinstall { console.print_debug('Installing Python environment') - python.install()! + // python.install()! py.init_env()! py.db.set(key: key_install, value: 'done')! console.print_debug('Python environment setup complete')