diff --git a/examples/installers/sysadmintools/actrunner.vsh b/examples/installers/sysadmintools/actrunner.vsh index 449736b1..3b5e250f 100755 --- a/examples/installers/sysadmintools/actrunner.vsh +++ b/examples/installers/sysadmintools/actrunner.vsh @@ -1,7 +1,8 @@ #!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run import freeflowuniverse.herolib.installers.sysadmintools.actrunner -import freeflowuniverse.herolib.installers.virt.herocontainers +// import freeflowuniverse.herolib.installers.virt.herocontainers -actrunner.install()! +mut actrunner_ := actrunner.get()! +actrunner_.install()! // herocontainers.start()! diff --git a/lib/installers/sysadmintools/actrunner/actrunner_actions.v b/lib/installers/sysadmintools/actrunner/actrunner_actions.v index c8bf2cba..83d18214 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_actions.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_actions.v @@ -1,51 +1,34 @@ module actrunner -import freeflowuniverse.herolib.osal import freeflowuniverse.herolib.ui.console import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.core.pathlib -import freeflowuniverse.herolib.osal.systemd import freeflowuniverse.herolib.osal.zinit import freeflowuniverse.herolib.installers.ulist -import freeflowuniverse.herolib.installers.lang.golang -import freeflowuniverse.herolib.installers.lang.rust -import freeflowuniverse.herolib.installers.lang.python +import freeflowuniverse.herolib.osal +import freeflowuniverse.herolib.core import os fn startupcmd() ![]zinit.ZProcessNewArgs { - mut installer := get()! mut res := []zinit.ZProcessNewArgs{} - // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res << zinit.ZProcessNewArgs{ - // name: 'actrunner' - // cmd: 'actrunner server' - // env: { - // 'HOME': '/root' - // } - // } + res << zinit.ZProcessNewArgs{ + name: 'actrunner' + cmd: 'actrunner daemon' + startuptype: .zinit + env: { + 'HOME': '/root' + } + } return res } -fn running_() !bool { - mut installer := get()! - // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // this checks health of actrunner - // curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works - // url:='http://127.0.0.1:${cfg.port}/api/v1' - // mut conn := httpconnection.new(name: 'actrunner', url: url)! - - // if cfg.secret.len > 0 { - // conn.default_header.add(.authorization, 'Bearer ${cfg.secret}') - // } - // conn.default_header.add(.content_type, 'application/json') - // console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}") - // r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false} - // println(r) - // if true{panic("ssss")} - // tags := r['Tags'] or { return false } - // console.print_debug(tags) - // console.print_debug('actrunner is answering.') +fn running() !bool { + mut zinit_factory := zinit.new()! + if zinit_factory.exists('actrunner') { + is_running := zinit_factory.get('actrunner')! + println('is_running: ${is_running}') + return true + } return false } @@ -64,19 +47,19 @@ 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 { +fn installed() !bool { // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // res := os.execute('${osal.profile_path_source_and()!} actrunner 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 actrunner version.\n${res.output}") - // } - // if texttools.version(version) == texttools.version(r[0]) { - // return true - // } + res := os.execute('actrunner --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 actrunner version.\n${res.output}") + } + if texttools.version(version) == texttools.version(r[0]) { + return true + } return false } @@ -87,101 +70,55 @@ fn ulist_get() !ulist.UList { } // uploads to S3 server if configured -fn upload_() ! { - // installers.upload( - // cmdname: 'actrunner' - // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/actrunner' - // )! -} +fn upload() ! {} -fn install_() ! { +fn install() ! { console.print_header('install actrunner') // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED - // mut url := '' - // if core.is_linux_arm()! { - // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_arm64.tar.gz' - // } else if core.is_linux_intel()! { - // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_amd64.tar.gz' - // } else if core.is_osx_arm()! { - // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_darwin_arm64.tar.gz' - // } else if core.is_osx_intel()! { - // url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_darwin_amd64.tar.gz' - // } else { - // return error('unsported platform') - // } + mut url := '' + if core.is_linux_arm()! { + url = 'https://gitea.com/gitea/act_runner/releases/download/v${version}/act_runner-${version}-linux-arm64' + } else if core.is_linux_intel()! { + url = 'https://gitea.com/gitea/act_runner/releases/download/v${version}/act_runner-${version}-linux-amd64' + } else if core.is_osx_arm()! { + url = 'https://gitea.com/gitea/act_runner/releases/download/v${version}/act_runner-${version}-darwin-arm64' + } else if core.is_osx_intel()! { + url = 'https://gitea.com/gitea/act_runner/releases/download/v${version}/act_runner-${version}-darwin-amd64' + } else { + return error('unsported platform') + } - // mut dest := osal.download( - // url: url - // minsize_kb: 9000 - // expand_dir: '/tmp/actrunner' - // )! + osal.package_install('wget') or { return error('Could not install wget due to: ${err}') } - // //dest.moveup_single_subdir()! + mut res := os.execute('sudo wget -O /usr/local/bin/actrunner ${url}') + if res.exit_code != 0 { + return error('failed to install actrunner: ${res.output}') + } - // mut binpath := dest.file_get('actrunner')! - // osal.cmd_add( - // cmdname: 'actrunner' - // source: binpath.path - // )! + res = os.execute('sudo chmod +x /usr/local/bin/actrunner') + if res.exit_code != 0 { + return error('failed to install actrunner: ${res.output}') + } } -fn build_() ! { - // url := 'https://github.com/threefoldtech/actrunner' +fn build() ! {} - // make sure we install base on the node - // if core.platform()!= .ubuntu { - // return error('only support ubuntu for now') - // } - // golang.install()! +fn destroy() ! { + console.print_header('uninstall actrunner') + mut zinit_factory := zinit.new()! - // console.print_header('build actrunner') + if zinit_factory.exists('actrunner') { + zinit_factory.stop('actrunner') or { + return error('Could not stop actrunner service due to: ${err}') + } + zinit_factory.delete('actrunner') or { + return error('Could not delete actrunner service due to: ${err}') + } + } - // gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)! - - // cmd := ' - // cd ${gitpath} - // source ~/.cargo/env - // exit 1 #todo - // ' - // osal.execute_stdout(cmd)! - // - // //now copy to the default bin path - // mut binpath := dest.file_get('...')! - // adds it to path - // osal.cmd_add( - // cmdname: 'griddriver2' - // source: binpath.path - // )! -} - -fn destroy_() ! { - // mut systemdfactory := systemd.new()! - // systemdfactory.destroy("zinit")! - - // 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 - // ")! + res := os.execute('sudo rm -rf /usr/local/bin/actrunner') + if res.exit_code != 0 { + return error('failed to uninstall actrunner: ${res.output}') + } + console.print_header('actrunner is uninstalled') } diff --git a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v index 1fdca952..2fc6ce0a 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_factory_.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_factory_.v @@ -1,221 +1,208 @@ 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 struct ArgsGet { pub mut: - name string + name string } -pub fn get(args_ ArgsGet) !&ActRunner { - return &ActRunner{} +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 + 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 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()! - } - } - } + 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()! - - for _ in 0 .. 50 { - if self.running()! { - return - } - time.sleep(100 * time.millisecond) - } - return error('actrunner did not install properly.') + start_post()! + 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(args InstallArgs) ! { - switch(self.name) - self.install(args)! - self.start()! + 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 (mut self ActRunner) install(args InstallArgs) ! { - switch(self.name) - if args.reset || (!installed()!) { - install()! - } + switch(self.name) + if args.reset || (!installed()!) { + install()! + } } pub fn (mut self ActRunner) build() ! { - switch(self.name) - build()! + switch(self.name) + build()! } pub fn (mut self ActRunner) destroy() ! { - switch(self.name) - self.stop() or {} - destroy()! + switch(self.name) + self.stop() or {} + destroy()! } - - -//switch instance to be used for actrunner +// switch instance to be used for actrunner pub fn switch(name string) { - actrunner_default = name + actrunner_default = name } - -//helpers +// helpers @[params] -pub struct DefaultConfigArgs{ - instance string = 'default' +pub struct DefaultConfigArgs { + instance string = 'default' } diff --git a/lib/installers/sysadmintools/actrunner/actrunner_model.v b/lib/installers/sysadmintools/actrunner/actrunner_model.v index b38e162a..a0c97e01 100644 --- a/lib/installers/sysadmintools/actrunner/actrunner_model.v +++ b/lib/installers/sysadmintools/actrunner/actrunner_model.v @@ -1,9 +1,8 @@ module actrunner -import freeflowuniverse.herolib.data.paramsparser -import os +import freeflowuniverse.herolib.data.encoderhero -pub const version = '0.0.0' +pub const version = '0.2.11' const singleton = true const default = true @@ -14,14 +13,24 @@ pub mut: name string = 'default' } -fn obj_init(obj_ ActRunner) !ActRunner { - // never call get here, only thing we can do here is work on object itself - mut obj := obj_ - panic('implement') - return obj +// your checking & initialization code if needed +fn obj_init(mycfg_ ActRunner) !ActRunner { + 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 ActRunner) !string { + return encoderhero.encode[ActRunner](obj)! +} + +pub fn heroscript_loads(heroscript string) !ActRunner { + mut obj := encoderhero.decode[ActRunner](heroscript)! + return obj +} diff --git a/lib/installers/sysadmintools/actrunner/install.v b/lib/installers/sysadmintools/actrunner/install.v deleted file mode 100644 index 28d5f6db..00000000 --- a/lib/installers/sysadmintools/actrunner/install.v +++ /dev/null @@ -1,59 +0,0 @@ -module actrunner - -import freeflowuniverse.herolib.osal -import freeflowuniverse.herolib.ui.console -import freeflowuniverse.herolib.core.texttools -import os - -pub fn installl(args_ InstallArgs) ! { - mut args := args_ - version := '0.2.10' - - res := os.execute('${osal.profile_path_source_and()!} actrunner -v') - if res.exit_code == 0 { - r := res.output.split_into_lines().filter(it.contains('act_runner version')) - if r.len != 1 { - return error("couldn't parse actrunner version, expected 'actrunner 0' on 1 row.\n${res.output}") - } - - v := texttools.version(r[0].all_after('act_runner version')) - if v < texttools.version(version) { - args.reset = true - } - } else { - args.reset = true - } - - if args.reset == false { - return - } - - console.print_header('install actrunner') - - mut url := '' - if core.is_linux_arm()! { - url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-linux-arm64' - } else if core.is_linux_intel()! { - url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-linux-amd64' - } else if core.is_osx_arm()! { - url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-darwin-arm64' - } else if core.is_osx_intel()! { - url = 'https://dl.gitea.com/act_runner/${version}/act_runner-${version}-darwin-amd64' - } else { - return error('unsported platform') - } - - mut dest := osal.download( - url: url - minsize_kb: 15000 - )! - - // console.print_debug(dest) - - osal.cmd_add( - cmdname: 'actrunner' - source: dest.path - )! - - return -}