...
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module livekit
|
||||
|
||||
import incubaid.herolib.data.caching
|
||||
// import incubaid.herolib.data.caching
|
||||
import os
|
||||
|
||||
// const CACHING_METHOD = caching.CachingMethod.once_per_process
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module livekit
|
||||
|
||||
import jwt
|
||||
// import jwt
|
||||
import time
|
||||
|
||||
pub struct AccessToken {
|
||||
|
||||
14
lib/core/generator/generic/generate_play_all.v
Normal file
14
lib/core/generator/generic/generate_play_all.v
Normal file
@@ -0,0 +1,14 @@
|
||||
module generic
|
||||
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import os
|
||||
|
||||
fn generate_play_all(meta_items []ModuleMeta) ! {
|
||||
mut path := pathlib.get('${os.home_dir()}/code/github/incubaid/herolib/lib/core/playcmds/play_all.v')
|
||||
mut templ_1 := $tmpl('templates/play_all.vtemplate')
|
||||
pathlib.template_write(templ_1, path.path, true)!
|
||||
console.print_debug('formating ${path.path}')
|
||||
osal.execute_silent('v fmt -w ${path.path}')!
|
||||
}
|
||||
@@ -48,6 +48,5 @@ pub fn scan(args_ ScannerArgs) ! {
|
||||
res << args_get(pparent.path)!
|
||||
}
|
||||
console.print_debug('Found ${res.len} generator args.')
|
||||
println(res)
|
||||
$dbg;
|
||||
generate_play_all(res)!
|
||||
}
|
||||
|
||||
16
lib/core/generator/generic/templates/play_all.vtemplate
Normal file
16
lib/core/generator/generic/templates/play_all.vtemplate
Normal file
@@ -0,0 +1,16 @@
|
||||
module playcmds
|
||||
|
||||
@for item in meta_items
|
||||
import @{item.module_path}
|
||||
@end
|
||||
|
||||
pub fn run_all(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
// println('DEBUG: the args is: @@{args}')
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript, path: args.heroscript_path)!
|
||||
}
|
||||
@for item in meta_items
|
||||
@{item.module_path.split(".").last()}.play(mut plbook)!
|
||||
@end
|
||||
}
|
||||
133
lib/core/playcmds/play_all.v
Normal file
133
lib/core/playcmds/play_all.v
Normal file
@@ -0,0 +1,133 @@
|
||||
module playcmds
|
||||
|
||||
import incubaid.herolib.clients.giteaclient
|
||||
import incubaid.herolib.clients.ipapi
|
||||
import incubaid.herolib.clients.jina
|
||||
import incubaid.herolib.clients.livekit
|
||||
import incubaid.herolib.clients.mailclient
|
||||
import incubaid.herolib.clients.meilisearch
|
||||
import incubaid.herolib.clients.mycelium
|
||||
import incubaid.herolib.clients.mycelium_rpc
|
||||
import incubaid.herolib.clients.openai
|
||||
import incubaid.herolib.clients.postgresql_client
|
||||
import incubaid.herolib.clients.qdrant
|
||||
import incubaid.herolib.clients.rclone
|
||||
import incubaid.herolib.clients.runpod
|
||||
import incubaid.herolib.clients.sendgrid
|
||||
import incubaid.herolib.clients.vastai
|
||||
import incubaid.herolib.clients.wireguard
|
||||
import incubaid.herolib.clients.zerodb_client
|
||||
import incubaid.herolib.clients.zinit
|
||||
import incubaid.herolib.develop.heroprompt
|
||||
import incubaid.herolib.installers.db.cometbft
|
||||
import incubaid.herolib.installers.db.meilisearch_installer
|
||||
import incubaid.herolib.installers.db.postgresql
|
||||
import incubaid.herolib.installers.db.qdrant_installer
|
||||
import incubaid.herolib.installers.db.zerodb
|
||||
import incubaid.herolib.installers.db.zerofs
|
||||
import incubaid.herolib.installers.infra.coredns
|
||||
import incubaid.herolib.installers.infra.gitea
|
||||
import incubaid.herolib.installers.infra.livekit
|
||||
import incubaid.herolib.installers.infra.zinit_installer
|
||||
import incubaid.herolib.installers.lang.golang
|
||||
import incubaid.herolib.installers.lang.nodejs
|
||||
import incubaid.herolib.installers.lang.python
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.installers.net.mycelium_installer
|
||||
import incubaid.herolib.installers.net.wireguard_installer
|
||||
import incubaid.herolib.installers.net.yggdrasil
|
||||
import incubaid.herolib.installers.sysadmintools.actrunner
|
||||
import incubaid.herolib.installers.sysadmintools.b2
|
||||
import incubaid.herolib.installers.sysadmintools.fungistor
|
||||
import incubaid.herolib.installers.sysadmintools.garage_s3
|
||||
import incubaid.herolib.installers.sysadmintools.grafana
|
||||
import incubaid.herolib.installers.sysadmintools.prometheus
|
||||
import incubaid.herolib.installers.sysadmintools.rclone
|
||||
import incubaid.herolib.installers.sysadmintools.restic
|
||||
import incubaid.herolib.installers.threefold.griddriver
|
||||
import incubaid.herolib.installers.virt.cloudhypervisor
|
||||
import incubaid.herolib.installers.virt.docker
|
||||
import incubaid.herolib.installers.virt.herorunner
|
||||
import incubaid.herolib.installers.virt.lima
|
||||
import incubaid.herolib.installers.virt.pacman
|
||||
import incubaid.herolib.installers.virt.podman
|
||||
import incubaid.herolib.installers.virt.youki
|
||||
import incubaid.herolib.installers.web.bun
|
||||
import incubaid.herolib.installers.web.imagemagick
|
||||
import incubaid.herolib.installers.web.lighttpd
|
||||
import incubaid.herolib.installers.web.tailwind
|
||||
import incubaid.herolib.installers.web.tailwind4
|
||||
import incubaid.herolib.installers.web.traefik
|
||||
import incubaid.herolib.installers.web.zola
|
||||
import incubaid.herolib.threefold.grid3.deployer
|
||||
import incubaid.herolib.virt.hetznermanager
|
||||
|
||||
pub fn run_all(args_ PlayArgs) ! {
|
||||
mut args := args_
|
||||
// println('DEBUG: the args is: @{args}')
|
||||
mut plbook := args.plbook or {
|
||||
playbook.new(text: args.heroscript, path: args.heroscript_path)!
|
||||
}
|
||||
|
||||
giteaclient.play(mut plbook)!
|
||||
ipapi.play(mut plbook)!
|
||||
jina.play(mut plbook)!
|
||||
livekit.play(mut plbook)!
|
||||
mailclient.play(mut plbook)!
|
||||
meilisearch.play(mut plbook)!
|
||||
mycelium.play(mut plbook)!
|
||||
mycelium_rpc.play(mut plbook)!
|
||||
openai.play(mut plbook)!
|
||||
postgresql_client.play(mut plbook)!
|
||||
qdrant.play(mut plbook)!
|
||||
rclone.play(mut plbook)!
|
||||
runpod.play(mut plbook)!
|
||||
sendgrid.play(mut plbook)!
|
||||
vastai.play(mut plbook)!
|
||||
wireguard.play(mut plbook)!
|
||||
zerodb_client.play(mut plbook)!
|
||||
zinit.play(mut plbook)!
|
||||
heroprompt.play(mut plbook)!
|
||||
cometbft.play(mut plbook)!
|
||||
meilisearch_installer.play(mut plbook)!
|
||||
postgresql.play(mut plbook)!
|
||||
qdrant_installer.play(mut plbook)!
|
||||
zerodb.play(mut plbook)!
|
||||
zerofs.play(mut plbook)!
|
||||
coredns.play(mut plbook)!
|
||||
gitea.play(mut plbook)!
|
||||
livekit.play(mut plbook)!
|
||||
zinit_installer.play(mut plbook)!
|
||||
golang.play(mut plbook)!
|
||||
nodejs.play(mut plbook)!
|
||||
python.play(mut plbook)!
|
||||
rust.play(mut plbook)!
|
||||
mycelium_installer.play(mut plbook)!
|
||||
wireguard_installer.play(mut plbook)!
|
||||
yggdrasil.play(mut plbook)!
|
||||
actrunner.play(mut plbook)!
|
||||
b2.play(mut plbook)!
|
||||
fungistor.play(mut plbook)!
|
||||
garage_s3.play(mut plbook)!
|
||||
grafana.play(mut plbook)!
|
||||
prometheus.play(mut plbook)!
|
||||
rclone.play(mut plbook)!
|
||||
restic.play(mut plbook)!
|
||||
griddriver.play(mut plbook)!
|
||||
cloudhypervisor.play(mut plbook)!
|
||||
docker.play(mut plbook)!
|
||||
herorunner.play(mut plbook)!
|
||||
lima.play(mut plbook)!
|
||||
pacman.play(mut plbook)!
|
||||
podman.play(mut plbook)!
|
||||
youki.play(mut plbook)!
|
||||
bun.play(mut plbook)!
|
||||
imagemagick.play(mut plbook)!
|
||||
lighttpd.play(mut plbook)!
|
||||
tailwind.play(mut plbook)!
|
||||
tailwind4.play(mut plbook)!
|
||||
traefik.play(mut plbook)!
|
||||
zola.play(mut plbook)!
|
||||
deployer.play(mut plbook)!
|
||||
hetznermanager.play(mut plbook)!
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
module rfs
|
||||
module zerofs
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.installers.zinit
|
||||
// import incubaid.herolib.installers.zinit
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
pub fn install_() ! {
|
||||
rust.install()!
|
||||
zinit.install()!
|
||||
console.print_header('install rfs')
|
||||
if !osal.done_exists('install_rfs') || !osal.cmd_exists('rfs') {
|
||||
osal.package_install('musl-dev,musl-tools')!
|
||||
// pub fn install_() ! {
|
||||
// rust.install()!
|
||||
// zinit.install()!
|
||||
// console.print_header('install rfs')
|
||||
// if !osal.done_exists('install_rfs') || !osal.cmd_exists('rfs') {
|
||||
// osal.package_install('musl-dev,musl-tools')!
|
||||
|
||||
mut gs := gittools.new()!
|
||||
mut repo := gs.get_repo(url: 'https://github.com/threefoldtech/rfs', reset: true)!
|
||||
path := repo.path()
|
||||
cmd := '
|
||||
cd ${path}
|
||||
rustup target add x86_64-unknown-linux-musl
|
||||
cargo build --features build-binary --release --target=x86_64-unknown-linux-musl
|
||||
// mut gs := gittools.new()!
|
||||
// mut repo := gs.get_repo(url: 'https://github.com/threefoldtech/rfs', reset: true)!
|
||||
// path := repo.path()
|
||||
// cmd := '
|
||||
// cd ${path}
|
||||
// rustup target add x86_64-unknown-linux-musl
|
||||
// cargo build --features build-binary --release --target=x86_64-unknown-linux-musl
|
||||
|
||||
cp ~/code/github/threefoldtech/rfs/target/x86_64-unknown-linux-musl/release/rfs /usr/local/bin/
|
||||
'
|
||||
console.print_header('build rfs')
|
||||
osal.execute_stdout(cmd)!
|
||||
osal.done_set('install_rfs', 'OK')!
|
||||
}
|
||||
console.print_header('rfs already done')
|
||||
}
|
||||
// cp ~/code/github/threefoldtech/rfs/target/x86_64-unknown-linux-musl/release/rfs /usr/local/bin/
|
||||
// '
|
||||
// console.print_header('build rfs')
|
||||
// osal.execute_stdout(cmd)!
|
||||
// osal.done_set('install_rfs', 'OK')!
|
||||
// }
|
||||
// console.print_header('rfs already done')
|
||||
// }
|
||||
|
||||
@@ -6,7 +6,7 @@ import incubaid.herolib.core.texttools
|
||||
import incubaid.herolib.core
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.installers.ulist
|
||||
import incubaid.herolib.libarchive.zinit as zinit_lib
|
||||
// import incubaid.herolib.libarchive.zinit as zinit_lib
|
||||
import incubaid.herolib.core.httpconnection
|
||||
import os
|
||||
import json
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
!!hero_code.generate_installer
|
||||
name: "s3"
|
||||
classname: "S3Installer"
|
||||
hasconfig: false
|
||||
singleton: true
|
||||
default: true
|
||||
title: ""
|
||||
templates: false
|
||||
build: true
|
||||
startupmanager: true
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.develop.gittools
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
@[params]
|
||||
pub struct BuildArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
// bin_push bool = true
|
||||
}
|
||||
|
||||
// install s3cas will return true if it was already installed
|
||||
pub fn build_(args BuildArgs) ! {
|
||||
// make sure we install base on the node
|
||||
if core.platform() != .ubuntu {
|
||||
return error('only support ubuntu for now')
|
||||
}
|
||||
rust.install()!
|
||||
|
||||
// install s3cas if it was already done will return true
|
||||
console.print_header('build s3cas')
|
||||
|
||||
osal.package_install('libssl-dev,pkg-config')!
|
||||
|
||||
mut gs := gittools.new()!
|
||||
mut repo := gs.get_repo(
|
||||
url: 'https://github.com/leesmet/s3-cas'
|
||||
reset: false
|
||||
pull: true
|
||||
)!
|
||||
|
||||
mut path := repo.path()
|
||||
|
||||
cmd := '
|
||||
set -ex
|
||||
cd ${path}
|
||||
cargo build --all-features
|
||||
'
|
||||
osal.execute_stdout(cmd) or { return error('Cannot install s3.\n${err}') }
|
||||
|
||||
osal.cmd_add(
|
||||
// cmdname: ''
|
||||
source: '${path}/target/debug/s3-cas'
|
||||
)!
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
## S3
|
||||
@@ -1,24 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.installers.base
|
||||
import incubaid.herolib.installers.zinit as zinitinstaller
|
||||
import incubaid.herolib.installers.rclone
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
// install s3 will return true if it was already installed
|
||||
pub fn install_() ! {
|
||||
base.install()!
|
||||
zinitinstaller.install()!
|
||||
rclone.install()!
|
||||
|
||||
if osal.done_exists('install_s3') {
|
||||
return
|
||||
}
|
||||
|
||||
build()!
|
||||
|
||||
console.print_header('install s3')
|
||||
|
||||
osal.done_set('install_s3', 'OK')!
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.ui.console
|
||||
import incubaid.herolib.core.texttools
|
||||
import incubaid.herolib.core.pathlib
|
||||
import incubaid.herolib.osal.systemd
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.installers.ulist
|
||||
import incubaid.herolib.installers.lang.golang
|
||||
import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.installers.lang.python
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut installer := get()!
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res << startupmanager.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 core.is_linux_arm()! {
|
||||
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_arm64.tar.gz'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_linux_amd64.tar.gz'
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/s3-dev/s3/releases/download/v${version}/s3_${version}_darwin_arm64.tar.gz'
|
||||
// } else if core.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 core.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
|
||||
// ")!
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.herolib.core.playbook { PlayBook }
|
||||
import incubaid.herolib.ui.console
|
||||
import json
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
s3_global map[string]&S3Installer
|
||||
s3_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&S3Installer {
|
||||
return &S3Installer{}
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&S3Installer {
|
||||
return new(args)!
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
if !plbook.exists(filter: 's3.') {
|
||||
return
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 's3.configure')!
|
||||
if install_actions.len > 0 {
|
||||
return error("can't configure s3, because no configuration allowed for this installer.")
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 's3.')!
|
||||
for mut 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 s3.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action s3.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut s3_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${s3_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action s3.${other_action.name}')
|
||||
s3_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action s3.${other_action.name}')
|
||||
s3_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action s3.${other_action.name}')
|
||||
s3_obj.restart()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
// zinit
|
||||
// tmux
|
||||
// systemd
|
||||
match cat {
|
||||
.screen {
|
||||
console.print_debug("installer: s3' startupmanager get screen")
|
||||
return startupmanager.get(.screen)!
|
||||
}
|
||||
.zinit {
|
||||
console.print_debug("installer: s3' startupmanager get zinit")
|
||||
return startupmanager.get(.zinit)!
|
||||
}
|
||||
.systemd {
|
||||
console.print_debug("installer: s3' startupmanager get systemd")
|
||||
return startupmanager.get(.systemd)!
|
||||
}
|
||||
else {
|
||||
console.print_debug("installer: s3' startupmanager get auto")
|
||||
return startupmanager.get(.auto)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self S3Installer) start() ! {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('installer: s3 start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: s3 starting 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(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
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()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
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(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.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) {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.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()!
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
module s3
|
||||
|
||||
import incubaid.herolib.osal.core as osal
|
||||
import incubaid.herolib.osal.startupmanager
|
||||
import incubaid.herolib.data.dbfs
|
||||
import incubaid.herolib.core.texttools
|
||||
import json
|
||||
import rand
|
||||
import incubaid.herolib.ui.console
|
||||
|
||||
// --fs-root <fs-root> [default: .]
|
||||
// --host <host> [default: localhost]
|
||||
// --meta-root <meta-root> [default: .]
|
||||
// --metric-host <metric-host> [default: localhost]
|
||||
// --metric-port <metric-port> [default: 9100]
|
||||
// --port <port> [default: 8014]
|
||||
// --access-key <access-key>
|
||||
// --secret-key <secret-key>
|
||||
@[params]
|
||||
pub struct Config {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
fs_root string = '/var/data/s3'
|
||||
host string = 'localhost'
|
||||
meta_root string = '/var/data/s3_meta'
|
||||
metric_host string = 'localhost'
|
||||
metric_port int = 9100
|
||||
port int = 8014
|
||||
access_key string
|
||||
secret_key string
|
||||
}
|
||||
|
||||
pub struct Server {
|
||||
pub mut:
|
||||
name string
|
||||
config Config
|
||||
process ?zinit.ZProcess
|
||||
}
|
||||
|
||||
// get the s3 server
|
||||
//```js
|
||||
// fs_root string = "/var/data/s3"
|
||||
// host string = "localhost"
|
||||
// meta_root string = "/var/data/s3_meta"
|
||||
// metric_host string
|
||||
// metric_port int //9100
|
||||
// port int = 8014
|
||||
// access_key string @[required]
|
||||
// secret_key string
|
||||
//```
|
||||
// if name exists already in the config DB, it will load for that name
|
||||
pub fn new(args_ Config) !Server {
|
||||
install()! // make sure it has been build & ready to be used
|
||||
mut args := args_
|
||||
args.name = texttools.name_fix(args.name)
|
||||
key := 's3_config_${args.name}'
|
||||
mut kvs := dbfs.new(name: 'config')!
|
||||
if !kvs.exists(key) {
|
||||
if args.access_key == '' {
|
||||
args.access_key = rand.string(12)
|
||||
}
|
||||
if args.secret_key == '' {
|
||||
args.secret_key = rand.string(12)
|
||||
}
|
||||
data := json.encode(args)
|
||||
console.print_debug('set config s3')
|
||||
kvs.set(key, data)!
|
||||
}
|
||||
return get(args.name)!
|
||||
}
|
||||
|
||||
pub fn get(name_ string) !Server {
|
||||
name := texttools.name_fix(name_)
|
||||
key := 's3_config_${name}'
|
||||
mut kvs := dbfs.new(name: 'config')!
|
||||
if kvs.exists(key) {
|
||||
data := kvs.get(key)!
|
||||
args := json.decode(Config, data)!
|
||||
mut server := Server{
|
||||
name: name
|
||||
config: args
|
||||
}
|
||||
mut z := zinit.new()!
|
||||
processname := 's3_${args.name}'
|
||||
if z.process_exists(processname) {
|
||||
server.process = z.process_get(processname)!
|
||||
}
|
||||
return server
|
||||
}
|
||||
return error("can't find S3 server with name:'${name}'")
|
||||
}
|
||||
|
||||
pub fn (mut server Server) start() ! {
|
||||
mut args := server.config
|
||||
|
||||
mut cmd := 's3-cas --fs-root ${args.fs_root} --host ${args.host} --meta-root ${args.meta_root} --port ${args.port}'
|
||||
if args.metric_host.len > 0 {
|
||||
cmd += ' --metric-host ${args.metric_host}'
|
||||
}
|
||||
if args.metric_port > 0 {
|
||||
cmd += ' --metric-port ${args.metric_port}'
|
||||
}
|
||||
if args.secret_key == '' {
|
||||
args.secret_key = args.access_key
|
||||
}
|
||||
cmd += ' --access-key ${args.access_key}'
|
||||
cmd += ' --secret-key ${args.secret_key}'
|
||||
|
||||
mut z := zinit.new()!
|
||||
mut p := z.process_new(
|
||||
name: 's3_${args.name}'
|
||||
cmd: cmd
|
||||
)!
|
||||
|
||||
p.status()!
|
||||
p.output_wait('server is running at', 10)!
|
||||
}
|
||||
|
||||
// return status
|
||||
// ```
|
||||
// pub enum ZProcessStatus {
|
||||
// unknown
|
||||
// init
|
||||
// ok
|
||||
// error
|
||||
// blocked
|
||||
// spawned
|
||||
// }
|
||||
// ```
|
||||
pub fn (mut server Server) status() !zinit.ZProcessStatus {
|
||||
mut process := server.process or { return error("can't find process yet.") }
|
||||
return process.status()!
|
||||
}
|
||||
|
||||
// will check if running
|
||||
pub fn (mut server Server) check() ! {
|
||||
mut process := server.process or { return error("can't find process yet.") }
|
||||
process.check()!
|
||||
// TODO: need to do more checks S3 checks
|
||||
}
|
||||
|
||||
pub fn (mut server Server) stop() ! {
|
||||
mut process := server.process or { return error("can't find process yet.") }
|
||||
return process.stop()
|
||||
}
|
||||
Reference in New Issue
Block a user