feat: Improved the griddriver installer, added an example
This commit is contained in:
@@ -4,3 +4,4 @@ import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||
|
||||
mut griddriver_installer := griddriver.get()!
|
||||
griddriver_installer.install()!
|
||||
// griddriver_installer.destroy()!
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
module griddriver
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.installers.lang.golang
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
fn installed() !bool {
|
||||
res := os.execute('/bin/bash -c "griddriver --version"')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
@@ -27,12 +26,22 @@ fn installed_() !bool {
|
||||
return true
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
// console.print_header('install griddriver')
|
||||
build()!
|
||||
// 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{}
|
||||
}
|
||||
|
||||
fn build_() ! {
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install griddriver')
|
||||
build()!
|
||||
console.print_header('install griddriver OK')
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
console.print_header('build griddriver')
|
||||
mut installer := golang.get()!
|
||||
installer.install()!
|
||||
@@ -58,37 +67,17 @@ fn build_() ! {
|
||||
console.print_header('build griddriver OK')
|
||||
}
|
||||
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
// mut installer := get()!
|
||||
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
fn destroy() ! {
|
||||
console.print_header('uninstall griddriver')
|
||||
mut res := os.execute('sudo rm -rf /usr/local/bin/griddriver')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to uninstall griddriver: ${res.output}')
|
||||
}
|
||||
|
||||
// uploads to S3 server if configured
|
||||
fn upload_() ! {
|
||||
// mut installer := get()!
|
||||
// installers.upload(
|
||||
// cmdname: 'griddriver'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/griddriver'
|
||||
// )!
|
||||
res = os.execute('sudo rm -rf ~/code/github/threefoldtech/web3gw')
|
||||
if res.exit_code != 0 {
|
||||
return error('failed to uninstall griddriver: ${res.output}')
|
||||
}
|
||||
|
||||
fn destroy_() ! {
|
||||
// mut installer := get()!
|
||||
// cmd:="
|
||||
// systemctl disable griddriver_scheduler.service
|
||||
// systemctl disable griddriver.service
|
||||
// systemctl stop griddriver_scheduler.service
|
||||
// systemctl stop griddriver.service
|
||||
|
||||
// systemctl list-unit-files | grep griddriver
|
||||
|
||||
// pkill -9 -f griddriver
|
||||
|
||||
// ps aux | grep griddriver
|
||||
|
||||
// "
|
||||
|
||||
// osal.exec(cmd: cmd, stdout:true, debug: false)!
|
||||
console.print_header('uninstall griddriver OK')
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ module griddriver
|
||||
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
|
||||
@@ -14,29 +16,113 @@ __global (
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&GridDriverInstaller {
|
||||
return &GridDriverInstaller{}
|
||||
}
|
||||
|
||||
@[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: 'griddriver.')!
|
||||
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 griddriver.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action griddriver.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 install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
pub fn (mut self GridDriverInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self GridDriverInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self GridDriverInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
destroy()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
install_()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for griddriver
|
||||
pub fn switch(name string) {
|
||||
griddriver_default = name
|
||||
}
|
||||
|
||||
pub fn destroy() ! {
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
pub fn build() ! {
|
||||
build_()!
|
||||
//helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
module griddriver
|
||||
|
||||
pub const version = 'v0.1.0'
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
|
||||
pub const version = '0.1.1'
|
||||
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 GridDriverInstaller {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ GridDriverInstaller) !GridDriverInstaller {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
return obj
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ GridDriverInstaller) !GridDriverInstaller {
|
||||
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 GridDriverInstaller) !string {
|
||||
return encoderhero.encode[GridDriverInstaller](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !GridDriverInstaller {
|
||||
mut obj := encoderhero.decode[GridDriverInstaller](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user