installers

This commit is contained in:
2024-12-25 20:53:37 +01:00
parent 7cbfb504d6
commit d458ccb7d0
52 changed files with 3416 additions and 35 deletions

View File

@@ -2,6 +2,6 @@
name: "openai"
classname: "OpenAI"
hasconfig: false
singleton: true
singleton: false
default: true
title: ""

View File

@@ -3,7 +3,7 @@ import freeflowuniverse.herolib.data.paramsparser
import os
pub const version = '0.0.0'
const singleton = true
const singleton = false
const default = true

View File

@@ -1,5 +1,5 @@
!!hero_code.generate_client
name: "postgres"
name: "postgresql_client"
classname: "PostgresClient"
hasconfig: false
singleton: true

View File

@@ -1,5 +1,5 @@
module postgres
module postgresql_client
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
@@ -7,8 +7,8 @@ import freeflowuniverse.herolib.ui.console
__global (
postgres_global map[string]&PostgresClient
postgres_default string
postgresql_client_global map[string]&PostgresClient
postgresql_client_default string
)
/////////FACTORY
@@ -26,7 +26,7 @@ pub fn get(args_ ArgsGet) !&PostgresClient {
//switch instance to be used for postgres
//switch instance to be used for postgresql_client
pub fn switch(name string) {
postgres_default = name
postgresql_client_default = name
}

View File

@@ -1,4 +1,4 @@
module postgres
module postgresql_client
import freeflowuniverse.herolib.data.paramsparser
import os

View File

@@ -1,19 +0,0 @@
module zdb
// TODO: enable this test when we have running zdb in ci also implement missing tests
fn test_get() {
// // must set unix domain with --socket argument when running zdb
// // run zdb as following:
// // mkdir -p ~/.zdb/ && zdb --socket ~/.zdb/socket --admin 1234
// mut zdb := get('~/.zdb/socket', '1234', 'test')!
// // check info returns info about zdb
// info := zdb.info()!
// assert info.contains('server_name: 0-db')
// nslist := zdb.nslist()!
// assert nslist == ['default', 'test']
// nsinfo := zdb.nsinfo('default')!
// assert 'name: default' in nsinfo
}

View File

@@ -1,5 +1,5 @@
!!hero_code.generate_client
name: "zdb"
name: "zerodb_client"
classname: "ZeroDBClient"
hasconfig: false
singleton: true

View File

@@ -1,5 +1,5 @@
module zdb
module zerodb_client
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
@@ -7,8 +7,8 @@ import freeflowuniverse.herolib.ui.console
__global (
zdb_global map[string]&ZeroDBClient
zdb_default string
zerodb_client_global map[string]&ZeroDBClient
zerodb_client_default string
)
/////////FACTORY
@@ -26,7 +26,7 @@ pub fn get(args_ ArgsGet) !&ZeroDBClient {
//switch instance to be used for zdb
//switch instance to be used for zerodb_client
pub fn switch(name string) {
zdb_default = name
zerodb_client_default = name
}

View File

@@ -1,4 +1,4 @@
module zdb
module zerodb_client
import freeflowuniverse.herolib.data.paramsparser
import os

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "actrunner"
classname: "ActRunner"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
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 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'
// }
// }
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.')
return false
}
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 {
//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
// }
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: 'actrunner'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/actrunner'
// )!
}
fn install() ! {
console.print_header('install actrunner')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/actrunner-dev/actrunner/releases/download/v${version}/actrunner_${version}_darwin_arm64.tar.gz'
// } else if osal.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 dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/actrunner'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('actrunner')!
// osal.cmd_add(
// cmdname: 'actrunner'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/actrunner'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build actrunner')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module actrunner
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
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{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 ActRunner) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('actrunner start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting actrunner 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('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) 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 ActRunner) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self ActRunner) 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 ActRunner) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self ActRunner) build() ! {
switch(self.name)
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
}

View File

@@ -0,0 +1,30 @@
module actrunner
import freeflowuniverse.herolib.data.paramsparser
import os
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 ActRunner {
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
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "b2"
classname: "BackBase"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module b2
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'b2'
// cmd: 'b2 server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of b2
// 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: 'b2', 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('b2 is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} b2 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 b2 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: 'b2'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/b2'
// )!
}
fn install() ! {
console.print_header('install b2')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/b2-dev/b2/releases/download/v${version}/b2_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/b2'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('b2')!
// osal.cmd_add(
// cmdname: 'b2'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/b2'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build b2')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module b2
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
b2_global map[string]&BackBase
b2_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&BackBase {
return &BackBase{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 BackBase) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('b2 start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting b2 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('b2 did not install properly.')
}
pub fn (mut self BackBase) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self BackBase) 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 BackBase) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self BackBase) 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 BackBase) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self BackBase) build() ! {
switch(self.name)
build()!
}
pub fn (mut self BackBase) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for b2
pub fn switch(name string) {
b2_default = name
}

View File

@@ -0,0 +1,30 @@
module b2
import freeflowuniverse.herolib.data.paramsparser
import os
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 BackBase {
pub mut:
name string = 'default'
}
fn obj_init(obj_ BackBase)!BackBase{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,44 @@
# b2
To get started
```vlang
import freeflowuniverse.herolib.installers.something.b2 as b2_installer
heroscript:="
!!b2.configure name:'test'
password: '1234'
port: 7701
!!b2.start name:'test' reset:1
"
b2_installer.play(heroscript=heroscript)!
//or we can call the default and do a start with reset
//mut installer:= b2_installer.get()!
//installer.start(reset:true)!
```
## example heroscript
```hero
!!b2.configure
homedir: '/home/user/b2'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "fungistor"
classname: "FungiStor"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module fungistor
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'fungistor'
// cmd: 'fungistor server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of fungistor
// 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: 'fungistor', 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('fungistor is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} fungistor 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 fungistor 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: 'fungistor'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/fungistor'
// )!
}
fn install() ! {
console.print_header('install fungistor')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/fungistor-dev/fungistor/releases/download/v${version}/fungistor_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/fungistor'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('fungistor')!
// osal.cmd_add(
// cmdname: 'fungistor'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/fungistor'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build fungistor')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module fungistor
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
fungistor_global map[string]&FungiStor
fungistor_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&FungiStor {
return &FungiStor{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 FungiStor) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('fungistor start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting fungistor 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('fungistor did not install properly.')
}
pub fn (mut self FungiStor) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self FungiStor) 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 FungiStor) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self FungiStor) 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 FungiStor) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self FungiStor) build() ! {
switch(self.name)
build()!
}
pub fn (mut self FungiStor) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for fungistor
pub fn switch(name string) {
fungistor_default = name
}

View File

@@ -0,0 +1,30 @@
module fungistor
import freeflowuniverse.herolib.data.paramsparser
import os
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 FungiStor {
pub mut:
name string = 'default'
}
fn obj_init(obj_ FungiStor)!FungiStor{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,44 @@
# fungistor
To get started
```vlang
import freeflowuniverse.herolib.installers.something.fungistor as fungistor_installer
heroscript:="
!!fungistor.configure name:'test'
password: '1234'
port: 7701
!!fungistor.start name:'test' reset:1
"
fungistor_installer.play(heroscript=heroscript)!
//or we can call the default and do a start with reset
//mut installer:= fungistor_installer.get()!
//installer.start(reset:true)!
```
## example heroscript
```hero
!!fungistor.configure
homedir: '/home/user/fungistor'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "garage_s3"
classname: "GarageS3"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module garage_s3
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'garage_s3'
// cmd: 'garage_s3 server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of garage_s3
// 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: 'garage_s3', 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('garage_s3 is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} garage_s3 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 garage_s3 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: 'garage_s3'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/garage_s3'
// )!
}
fn install() ! {
console.print_header('install garage_s3')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/garage_s3-dev/garage_s3/releases/download/v${version}/garage_s3_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/garage_s3'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('garage_s3')!
// osal.cmd_add(
// cmdname: 'garage_s3'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/garage_s3'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build garage_s3')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module garage_s3
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
garage_s3_global map[string]&GarageS3
garage_s3_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&GarageS3 {
return &GarageS3{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 GarageS3) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('garage_s3 start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting garage_s3 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('garage_s3 did not install properly.')
}
pub fn (mut self GarageS3) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self GarageS3) 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 GarageS3) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self GarageS3) 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 GarageS3) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self GarageS3) build() ! {
switch(self.name)
build()!
}
pub fn (mut self GarageS3) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for garage_s3
pub fn switch(name string) {
garage_s3_default = name
}

View File

@@ -0,0 +1,30 @@
module garage_s3
import freeflowuniverse.herolib.data.paramsparser
import os
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 GarageS3 {
pub mut:
name string = 'default'
}
fn obj_init(obj_ GarageS3)!GarageS3{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "grafana"
classname: "Grafana"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module grafana
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'grafana'
// cmd: 'grafana server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of grafana
// 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: 'grafana', 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('grafana is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} grafana 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 grafana 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: 'grafana'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/grafana'
// )!
}
fn install() ! {
console.print_header('install grafana')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/grafana-dev/grafana/releases/download/v${version}/grafana_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/grafana'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('grafana')!
// osal.cmd_add(
// cmdname: 'grafana'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/grafana'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build grafana')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module grafana
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
grafana_global map[string]&Grafana
grafana_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Grafana {
return &Grafana{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 Grafana) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('grafana start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting grafana 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('grafana did not install properly.')
}
pub fn (mut self Grafana) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self Grafana) 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 Grafana) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self Grafana) 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 Grafana) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self Grafana) build() ! {
switch(self.name)
build()!
}
pub fn (mut self Grafana) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for grafana
pub fn switch(name string) {
grafana_default = name
}

View File

@@ -0,0 +1,30 @@
module grafana
import freeflowuniverse.herolib.data.paramsparser
import os
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 Grafana {
pub mut:
name string = 'default'
}
fn obj_init(obj_ Grafana)!Grafana{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,44 @@
# grafana
To get started
```vlang
import freeflowuniverse.herolib.installers.something.grafana as grafana_installer
heroscript:="
!!grafana.configure name:'test'
password: '1234'
port: 7701
!!grafana.start name:'test' reset:1
"
grafana_installer.play(heroscript=heroscript)!
//or we can call the default and do a start with reset
//mut installer:= grafana_installer.get()!
//installer.start(reset:true)!
```
## example heroscript
```hero
!!grafana.configure
homedir: '/home/user/grafana'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "prometheus"
classname: "Prometheus"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module prometheus
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'prometheus'
// cmd: 'prometheus server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of prometheus
// 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: 'prometheus', 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('prometheus is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} prometheus 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 prometheus 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: 'prometheus'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/prometheus'
// )!
}
fn install() ! {
console.print_header('install prometheus')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/prometheus-dev/prometheus/releases/download/v${version}/prometheus_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/prometheus'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('prometheus')!
// osal.cmd_add(
// cmdname: 'prometheus'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/prometheus'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build prometheus')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module prometheus
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
prometheus_global map[string]&Prometheus
prometheus_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Prometheus {
return &Prometheus{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 Prometheus) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('prometheus start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting prometheus 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('prometheus did not install properly.')
}
pub fn (mut self Prometheus) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self Prometheus) 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 Prometheus) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self Prometheus) 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 Prometheus) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self Prometheus) build() ! {
switch(self.name)
build()!
}
pub fn (mut self Prometheus) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for prometheus
pub fn switch(name string) {
prometheus_default = name
}

View File

@@ -0,0 +1,30 @@
module prometheus
import freeflowuniverse.herolib.data.paramsparser
import os
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 Prometheus {
pub mut:
name string = 'default'
}
fn obj_init(obj_ Prometheus)!Prometheus{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "restic"
classname: "Restic"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,44 @@
# restic
To get started
```vlang
import freeflowuniverse.herolib.installers.something.restic as restic_installer
heroscript:="
!!restic.configure name:'test'
password: '1234'
port: 7701
!!restic.start name:'test' reset:1
"
restic_installer.play(heroscript=heroscript)!
//or we can call the default and do a start with reset
//mut installer:= restic_installer.get()!
//installer.start(reset:true)!
```
## example heroscript
```hero
!!restic.configure
homedir: '/home/user/restic'
username: 'admin'
password: 'secretpassword'
title: 'Some Title'
host: 'localhost'
port: 8888
```

View File

@@ -0,0 +1,202 @@
module restic
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 'restic'
// cmd: 'restic server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of restic
// 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: 'restic', 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('restic is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} restic 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 restic 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: 'restic'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/restic'
// )!
}
fn install() ! {
console.print_header('install restic')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/restic-dev/restic/releases/download/v${version}/restic_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/restic'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('restic')!
// osal.cmd_add(
// cmdname: 'restic'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/restic'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build restic')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module restic
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
restic_global map[string]&Restic
restic_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Restic {
return &Restic{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 Restic) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('restic start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting restic 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('restic did not install properly.')
}
pub fn (mut self Restic) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self Restic) 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 Restic) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self Restic) 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 Restic) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self Restic) build() ! {
switch(self.name)
build()!
}
pub fn (mut self Restic) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for restic
pub fn switch(name string) {
restic_default = name
}

View File

@@ -0,0 +1,30 @@
module restic
import freeflowuniverse.herolib.data.paramsparser
import os
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 Restic {
pub mut:
name string = 'default'
}
fn obj_init(obj_ Restic)!Restic{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}

View File

@@ -0,0 +1,11 @@
!!hero_code.generate_installer
name: "s3"
classname: "S3Installer"
hasconfig: false
singleton: true
default: true
title: ""
templates: false
build: true
startupmanager: true

View File

@@ -0,0 +1,202 @@
module s3
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 os
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut installer := get()!
mut res := []zinit.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << zinit.ZProcessNewArgs{
// name: 's3'
// cmd: 's3 server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of s3
// 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: 's3', 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('s3 is answering.')
return false
}
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 {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()} s3 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 s3 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: 's3'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/s3'
// )!
}
fn install() ! {
console.print_header('install s3')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
// if osal.is_linux_arm() {
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_arm64.tar.gz'
// } else if osal.is_linux_intel() {
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_amd64.tar.gz'
// } else if osal.is_osx_arm() {
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_darwin_arm64.tar.gz'
// } else if osal.is_osx_intel() {
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_darwin_amd64.tar.gz'
// } else {
// return error('unsported platform')
// }
// mut dest := osal.download(
// url: url
// minsize_kb: 9000
// expand_dir: '/tmp/s3'
// )!
// //dest.moveup_single_subdir()!
// mut binpath := dest.file_get('s3')!
// osal.cmd_add(
// cmdname: 's3'
// source: binpath.path
// )!
}
fn build() ! {
//url := 'https://github.com/threefoldtech/s3'
// make sure we install base on the node
// if osal.platform() != .ubuntu {
// return error('only support ubuntu for now')
// }
// golang.install()!
// console.print_header('build s3')
// 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
// ")!
}

View File

@@ -0,0 +1,160 @@
module s3
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import time
__global (
s3_global map[string]&S3Installer
s3_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&S3Installer {
return &S3Installer{}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# 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 S3Installer) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('s3 start')
if ! installed()!{
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()!{
mut sm:=startupmanager_get(zprocess.startuptype)!
console.print_debug('starting s3 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('s3 did not install properly.')
}
pub fn (mut self S3Installer) install_start(model InstallArgs) ! {
switch(self.name)
self.install(model)!
self.start()!
}
pub fn (mut self S3Installer) 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 S3Installer) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self S3Installer) 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 S3Installer) install(model InstallArgs) ! {
switch(self.name)
if model.reset || (!installed()!) {
install()!
}
}
pub fn (mut self S3Installer) build() ! {
switch(self.name)
build()!
}
pub fn (mut self S3Installer) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
//switch instance to be used for s3
pub fn switch(name string) {
s3_default = name
}

View File

@@ -0,0 +1,30 @@
module s3
import freeflowuniverse.herolib.data.paramsparser
import os
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 S3Installer {
pub mut:
name string = 'default'
}
fn obj_init(obj_ S3Installer)!S3Installer{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
panic("implement")
return obj
}
//called before start if done
fn configure() ! {
//mut installer := get()!
}