feat: Support garage_s3 installer
- Added a new config template file to be loaded when starting the server - Run the server in zinit as a service - Fix the install, destroy, installed, and running functions
This commit is contained in:
8
examples/installers/sysadmintools/garage_s3.vsh
Executable file
8
examples/installers/sysadmintools/garage_s3.vsh
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
|
import freeflowuniverse.herolib.installers.sysadmintools.garage_s3 as garage_s3_installer
|
||||||
|
|
||||||
|
mut garage_s3 := garage_s3_installer.get()!
|
||||||
|
garage_s3.install()!
|
||||||
|
garage_s3.start()!
|
||||||
|
garage_s3.destroy()!
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
// module garage_s3
|
|
||||||
|
|
||||||
// import freeflowuniverse.herolib.osal
|
|
||||||
// import freeflowuniverse.herolib.core
|
|
||||||
// import freeflowuniverse.herolib.ui.console
|
|
||||||
// import freeflowuniverse.herolib.core.texttools
|
|
||||||
// import os
|
|
||||||
|
|
||||||
// pub fn install(args_ GarageS3) ! {
|
|
||||||
// mut args := args_
|
|
||||||
// version := '1.0.0'
|
|
||||||
|
|
||||||
// res := os.execute('garage --version')
|
|
||||||
// if res.exit_code == 0 {
|
|
||||||
// r := res.output.split(' ')
|
|
||||||
// if r.len < 2 {
|
|
||||||
// return error("couldn't parse garage version, expected 'garage v*'.\n${res.output}")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// v := r[1]
|
|
||||||
// if texttools.version(v) < texttools.version(version) {
|
|
||||||
// args.reset = true
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// args.reset = true
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if args.reset {
|
|
||||||
// console.print_header('install garage')
|
|
||||||
|
|
||||||
// mut url := ''
|
|
||||||
// if core.is_linux_arm()! {
|
|
||||||
// url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/aarch64-unknown-linux-musl/garage'
|
|
||||||
// } else if core.is_linux_intel()! {
|
|
||||||
// url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/x86_64-unknown-linux-musl/garage'
|
|
||||||
// } else {
|
|
||||||
// return error('unsported platform')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mut dest := osal.download(
|
|
||||||
// url: url
|
|
||||||
// minsize_kb: 15 * 1024
|
|
||||||
// dest: '/tmp/garage'
|
|
||||||
// reset: true
|
|
||||||
// )!
|
|
||||||
// console.print_debug('download garage done')
|
|
||||||
// osal.cmd_add(
|
|
||||||
// cmdname: 'garage'
|
|
||||||
// source: '${dest.path}'
|
|
||||||
// )!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if args.start {
|
|
||||||
// start(args)!
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
module garage_s3
|
|
||||||
|
|
||||||
// import freeflowuniverse.herolib.ui.console
|
|
||||||
// import freeflowuniverse.herolib.core.pathlib
|
|
||||||
// import freeflowuniverse.herolib.sysadmin.startupmanager
|
|
||||||
// import freeflowuniverse.herolib.crypt.secrets
|
|
||||||
// // import freeflowuniverse.herolib.core.texttools
|
|
||||||
// // import freeflowuniverse.herolib.core.httpconnection
|
|
||||||
// import os
|
|
||||||
// import time
|
|
||||||
|
|
||||||
// @[params]
|
|
||||||
// pub struct S3Config {
|
|
||||||
// pub mut:
|
|
||||||
// replication_mode string = '3'
|
|
||||||
// metadata_dir string = '/var/garage/meta'
|
|
||||||
// data_dir string = '/var/garage/data'
|
|
||||||
// sled_cache_capacity u32 = 128 // in MB
|
|
||||||
// compression_level u8 = 1
|
|
||||||
|
|
||||||
// rpc_secret string //{GARAGE_RPCSECRET}
|
|
||||||
// rpc_bind_addr string = '[::]:3901'
|
|
||||||
// rpc_bind_outgoing bool
|
|
||||||
// rpc_public_addr string = '127.0.0.1:3901'
|
|
||||||
|
|
||||||
// bootstrap_peers []string
|
|
||||||
|
|
||||||
// api_bind_addr string = '[::]:3900'
|
|
||||||
// s3_region string = 'garage'
|
|
||||||
// root_domain string = '.s3.garage'
|
|
||||||
|
|
||||||
// web_bind_addr string = '[::]:3902'
|
|
||||||
// web_root_domain string = '.web.garage'
|
|
||||||
|
|
||||||
// admin_api_bind_addr string = '[::]:3903'
|
|
||||||
// admin_metrics_token string //{GARAGE_METRICSTOKEN}
|
|
||||||
// admin_token string //{GARAGE_ADMINTOKEN}
|
|
||||||
// admin_trace_sink string = 'http://localhost:4317'
|
|
||||||
|
|
||||||
// reset bool
|
|
||||||
// config_reset bool
|
|
||||||
// start bool = true
|
|
||||||
// restart bool = true
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn configure(args_ S3Config) !S3Config {
|
|
||||||
// mut args := args_
|
|
||||||
|
|
||||||
// if args.rpc_secret == '' {
|
|
||||||
// args.rpc_secret = secrets.openssl_hex_secret()!
|
|
||||||
// println('export GARAGE_RPCSECRET=${args.rpc_secret}')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if args.admin_metrics_token == '' {
|
|
||||||
// args.admin_metrics_token = secrets.openssl_base64_secret()!
|
|
||||||
// println('export GARAGE_METRICSTOKEN=${args.admin_metrics_token}')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if args.admin_token == '' {
|
|
||||||
// args.admin_token = secrets.openssl_base64_secret()!
|
|
||||||
// println('export GARAGE_ADMINTOKEN=${args.admin_token}')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mut config_file := $tmpl('templates/garage.toml')
|
|
||||||
|
|
||||||
// myconfigpath_ := '/etc/garage.toml'
|
|
||||||
// mut myconfigpath := pathlib.get_file(path: myconfigpath_, create: true)!
|
|
||||||
// myconfigpath.write(config_file)!
|
|
||||||
|
|
||||||
// console.print_header('garage start')
|
|
||||||
|
|
||||||
// return args
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn start(args_ S3Config) !S3Config {
|
|
||||||
// mut args := args_
|
|
||||||
|
|
||||||
// myconfigpath_ := '/etc/garage.toml'
|
|
||||||
|
|
||||||
// if args.config_reset || !os.exists(myconfigpath_) {
|
|
||||||
// args = configure(args)!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if args.restart {
|
|
||||||
// stop()!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mut sm := startupmanager.get()!
|
|
||||||
|
|
||||||
// sm.new(
|
|
||||||
// name: 'garage'
|
|
||||||
// cmd: 'garage -c ${myconfigpath_} server'
|
|
||||||
// start: true
|
|
||||||
// )!
|
|
||||||
|
|
||||||
// console.print_debug('garage -c ${myconfigpath_} server')
|
|
||||||
|
|
||||||
// for _ in 0 .. 50 {
|
|
||||||
// if check(args)! {
|
|
||||||
// return args
|
|
||||||
// }
|
|
||||||
// time.sleep(100 * time.millisecond)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return error('garage server did not start properly.')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn stop() ! {
|
|
||||||
// console.print_header('garage stop')
|
|
||||||
// mut sm := startupmanager.get()!
|
|
||||||
// sm.stop('garage')!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn check(args S3Config) !bool {
|
|
||||||
// _ := 'garage status'
|
|
||||||
// res := os.execute('garage status')
|
|
||||||
// if res.exit_code == 0 {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
@@ -5,8 +5,72 @@ import freeflowuniverse.herolib.ui.console
|
|||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
// import freeflowuniverse.herolib.osal.systemd
|
import freeflowuniverse.herolib.installers.ulist
|
||||||
|
import freeflowuniverse.herolib.core.httpconnection
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||||
|
mut res := []zinit.ZProcessNewArgs{}
|
||||||
|
res << zinit.ZProcessNewArgs{
|
||||||
|
name: 'garage_s3'
|
||||||
|
cmd: 'garage_s3 -c /var/garage/config.toml server'
|
||||||
|
startuptype: .zinit
|
||||||
|
env: {
|
||||||
|
'HOME': '/root'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GarageS3InstanceStatus {
|
||||||
|
status string
|
||||||
|
known_nodes int @[json: 'knownNodes']
|
||||||
|
connected_nodes int @[json: 'connectedNodes']
|
||||||
|
storage_nodes int @[json: 'storageNodes']
|
||||||
|
storage_nodes_ok int @[json: 'storageNodesOk']
|
||||||
|
partitions int @[json: 'partitions']
|
||||||
|
partitions_quorum int @[json: 'partitionsQuorum']
|
||||||
|
partitions_all_ok int @[json: 'partitionsAllOk']
|
||||||
|
}
|
||||||
|
|
||||||
|
fn running() !bool {
|
||||||
|
mut installer := get()!
|
||||||
|
url := 'http://127.0.0.1:3903/'
|
||||||
|
if installer.admin_token.len < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
mut conn := httpconnection.new(name: 'garage_s3', url: url)!
|
||||||
|
conn.default_header.add(.authorization, 'Bearer ${installer.admin_token}')
|
||||||
|
|
||||||
|
r := conn.get_json_dict(prefix: 'v1/health', debug: false) or { return false }
|
||||||
|
if r.len == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
decoded_response := json.decode(GarageS3InstanceStatus, r.str()) or { return false }
|
||||||
|
|
||||||
|
if decoded_response.status != 'healthy' {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// checks if a certain version or above is installed
|
||||||
fn installed() !bool {
|
fn installed() !bool {
|
||||||
@@ -28,114 +92,77 @@ fn installed() !bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install() ! {
|
// get the Upload List of the files
|
||||||
console.print_header('install garage_s3')
|
fn ulist_get() !ulist.UList {
|
||||||
// mut installer := get()!
|
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
return ulist.UList{}
|
||||||
mut url := ''
|
|
||||||
if core.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 core.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 core.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 core.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 startupcmd() ![]zinit.ZProcessNewArgs {
|
// uploads to S3 server if configured
|
||||||
mut res := []zinit.ZProcessNewArgs{}
|
fn upload() ! {}
|
||||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
|
||||||
res << zinit.ZProcessNewArgs{
|
fn install() ! {
|
||||||
name: 'garage_s3'
|
console.print_header('install garage_s3')
|
||||||
cmd: 'garage_s3 server'
|
|
||||||
env: {
|
mut res := os.execute('garage_s3 --version')
|
||||||
'HOME': '/root'
|
if res.exit_code == 0 {
|
||||||
|
console.print_header('garage_s3 is already installed')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
p := core.platform()!
|
||||||
|
|
||||||
|
if p != .ubuntu {
|
||||||
|
return error('unsupported platform')
|
||||||
|
}
|
||||||
|
|
||||||
|
mut url := ''
|
||||||
|
if core.is_linux_arm()! {
|
||||||
|
url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/aarch64-unknown-linux-musl/garage'
|
||||||
|
}
|
||||||
|
if core.is_linux_intel()! {
|
||||||
|
url = 'https://garagehq.deuxfleurs.fr/_releases/v${version}/x86_64-unknown-linux-musl/garage'
|
||||||
|
}
|
||||||
|
|
||||||
|
res = os.execute('wget --version')
|
||||||
|
if res.exit_code == 0 {
|
||||||
|
console.print_header('wget is already installed')
|
||||||
|
} else {
|
||||||
|
osal.package_install('wget') or {
|
||||||
|
return error('Could not install wget, its required to install rclone.\nerror:\n${err}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
// Check if garage_s3 is installed
|
||||||
|
osal.execute_stdout('sudo wget -O /usr/local/bin/garage_s3 ${url}') or {
|
||||||
|
return error('cannot install garage_s3 due to: ${err}')
|
||||||
|
}
|
||||||
|
|
||||||
|
res = os.execute('sudo chmod +x /usr/local/bin/garage_s3')
|
||||||
|
if res.exit_code != 0 {
|
||||||
|
return error('failed to install garage_s3: ${res.output}')
|
||||||
|
}
|
||||||
|
|
||||||
|
console.print_header('garage_s3 is installed')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn running_() !bool {
|
fn destroy() ! {
|
||||||
_ := get()!
|
console.print_header('uninstall garage_s3')
|
||||||
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
res := os.execute('sudo rm -rf /usr/local/bin/garage_s3')
|
||||||
// this checks health of garage_s3
|
if res.exit_code != 0 {
|
||||||
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
|
return error('failed to uninstall garage_s3: ${res.output}')
|
||||||
// url:='http://127.0.0.1:${cfg.port}/api/v1'
|
}
|
||||||
// mut conn := httpconnection.new(name: 'garage_s3', url: url)!
|
|
||||||
|
|
||||||
// if cfg.secret.len > 0 {
|
mut zinit_factory := zinit.new()!
|
||||||
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
|
|
||||||
// }
|
if zinit_factory.exists('garage_s3') {
|
||||||
// conn.default_header.add(.content_type, 'application/json')
|
zinit_factory.stop('garage_s3') or {
|
||||||
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
|
return error('Could not stop garage_s3 service due to: ${err}')
|
||||||
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
|
}
|
||||||
// println(r)
|
zinit_factory.delete('garage_s3') or {
|
||||||
// if true{panic("ssss")}
|
return error('Could not delete garage_s3 service due to: ${err}')
|
||||||
// tags := r['Tags'] or { return false }
|
}
|
||||||
// console.print_debug(tags)
|
}
|
||||||
// console.print_debug('garage_s3 is answering.')
|
|
||||||
return false
|
console.print_header('garage_s3 is uninstalled')
|
||||||
}
|
|
||||||
|
|
||||||
fn start_pre() ! {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_post() ! {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop_pre() ! {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop_post() ! {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn destroy_() ! {
|
|
||||||
// mut systemdfactory := systemd.new()!
|
|
||||||
// systemdfactory.destroy("zinit")!
|
|
||||||
|
|
||||||
// osal.process_kill_recursive(name:'zinit')!
|
|
||||||
// osal.cmd_delete('zinit')!
|
|
||||||
|
|
||||||
// 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
|
|
||||||
// ")!
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ module garage_s3
|
|||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import freeflowuniverse.herolib.ui.console
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
@@ -17,14 +17,11 @@ __global (
|
|||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet {
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get(args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut args := args_
|
mut args := args_
|
||||||
if args.name == '' {
|
|
||||||
args.name = garage_s3_default
|
|
||||||
}
|
|
||||||
if args.name == '' {
|
if args.name == '' {
|
||||||
args.name = 'default'
|
args.name = 'default'
|
||||||
}
|
}
|
||||||
@@ -32,74 +29,110 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&GarageS3 {
|
pub fn get(args_ ArgsGet) !&GarageS3 {
|
||||||
|
mut context := base.context()!
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
|
mut obj := GarageS3{}
|
||||||
if args.name !in garage_s3_global {
|
if args.name !in garage_s3_global {
|
||||||
if !config_exists() {
|
if !exists(args)! {
|
||||||
if default {
|
set(obj)!
|
||||||
config_save()!
|
} else {
|
||||||
}
|
heroscript := context.hero_config_get('garage_s3', args.name)!
|
||||||
|
mut obj_ := heroscript_loads(heroscript)!
|
||||||
|
set_in_mem(obj_)!
|
||||||
}
|
}
|
||||||
config_load()!
|
|
||||||
}
|
}
|
||||||
return garage_s3_global[args.name] or {
|
return garage_s3_global[args.name] or {
|
||||||
println(garage_s3_global)
|
println(garage_s3_global)
|
||||||
panic('bug in get from factory: ')
|
// bug if we get here because should be in globals
|
||||||
|
panic('could not get config for garage_s3 with name, is bug:${args.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_exists(args_ ArgsGet) bool {
|
// register the config for the future
|
||||||
|
pub fn set(o GarageS3) ! {
|
||||||
|
set_in_mem(o)!
|
||||||
|
mut context := base.context()!
|
||||||
|
heroscript := heroscript_dumps(o)!
|
||||||
|
context.hero_config_set('garage_s3', o.name, heroscript)!
|
||||||
|
}
|
||||||
|
|
||||||
|
// does the config exists?
|
||||||
|
pub fn exists(args_ ArgsGet) !bool {
|
||||||
|
mut context := base.context()!
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
mut context := base.context() or { panic('bug') }
|
|
||||||
return context.hero_config_exists('garage_s3', args.name)
|
return context.hero_config_exists('garage_s3', args.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_load(args_ ArgsGet) ! {
|
pub fn delete(args_ ArgsGet) ! {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
mut context := base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get('garage_s3', args.name)!
|
context.hero_config_delete('garage_s3', args.name)!
|
||||||
play(heroscript: heroscript)!
|
if args.name in garage_s3_global {
|
||||||
|
// del garage_s3_global[args.name]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_save(args_ ArgsGet) ! {
|
// only sets in mem, does not set as config
|
||||||
mut args := args_get(args_)
|
fn set_in_mem(o GarageS3) ! {
|
||||||
mut context := base.context()!
|
|
||||||
context.hero_config_set('garage_s3', args.name, heroscript_default()!)!
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set(o GarageS3) ! {
|
|
||||||
mut o2 := obj_init(o)!
|
mut o2 := obj_init(o)!
|
||||||
garage_s3_global['default'] = &o2
|
garage_s3_global[o.name] = &o2
|
||||||
|
garage_s3_default = o.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
|
||||||
heroscript string // if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
|
|
||||||
start bool
|
|
||||||
stop bool
|
|
||||||
restart bool
|
|
||||||
delete bool
|
|
||||||
configure bool // make sure there is at least one installed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
mut args := args_
|
mut args := args_
|
||||||
|
|
||||||
if args.heroscript == '' {
|
|
||||||
args.heroscript = heroscript_default()!
|
|
||||||
}
|
|
||||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||||
|
|
||||||
mut install_actions := plbook.find(filter: 'garage_s3.configure')!
|
mut install_actions := plbook.find(filter: 'garage_s3.configure')!
|
||||||
if install_actions.len > 0 {
|
if install_actions.len > 0 {
|
||||||
for install_action in install_actions {
|
for install_action in install_actions {
|
||||||
mut p := install_action.params
|
heroscript := install_action.heroscript()
|
||||||
mycfg := cfg_play(p)!
|
mut obj2 := heroscript_loads(heroscript)!
|
||||||
set(mycfg)!
|
set(obj2)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mut other_actions := plbook.find(filter: 'garage_s3.')!
|
||||||
|
for other_action in other_actions {
|
||||||
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
reset := p.get_default_false('reset')
|
||||||
|
if other_action.name == 'destroy' || reset {
|
||||||
|
console.print_debug('install action garage_s3.destroy')
|
||||||
|
destroy()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action garage_s3.install')
|
||||||
|
install()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut garage_s3_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${garage_s3_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action garage_s3.${other_action.name}')
|
||||||
|
garage_s3_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action garage_s3.${other_action.name}')
|
||||||
|
garage_s3_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action garage_s3.${other_action.name}')
|
||||||
|
garage_s3_obj.restart()!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +239,7 @@ pub fn (mut self GarageS3) running() !bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running_()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
@@ -224,12 +257,18 @@ pub fn (mut self GarageS3) install(args InstallArgs) ! {
|
|||||||
|
|
||||||
pub fn (mut self GarageS3) destroy() ! {
|
pub fn (mut self GarageS3) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
self.stop() or {}
|
self.stop() or {}
|
||||||
destroy_()!
|
destroy()!
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch instance to be used for garage_s3
|
// switch instance to be used for garage_s3
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
garage_s3_default = name
|
garage_s3_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct DefaultConfigArgs {
|
||||||
|
instance string = 'default'
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,38 +1,22 @@
|
|||||||
module garage_s3
|
module garage_s3
|
||||||
|
|
||||||
import freeflowuniverse.herolib.data.paramsparser
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
import os
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
|
import rand
|
||||||
|
|
||||||
pub const version = '1.14.3'
|
pub const version = '1.0.1'
|
||||||
const singleton = false
|
const singleton = false
|
||||||
const default = true
|
const default = true
|
||||||
|
|
||||||
// TODO: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT
|
|
||||||
pub fn heroscript_default() !string {
|
|
||||||
heroscript := "
|
|
||||||
!!garage_s3.configure
|
|
||||||
name:'garage_s3'
|
|
||||||
homedir: '{HOME}/hero/var/garage_s3'
|
|
||||||
configpath: '{HOME}/.config/garage_s3/admin.yaml'
|
|
||||||
username: 'admin'
|
|
||||||
password: 'secretpassword'
|
|
||||||
secret: ''
|
|
||||||
title: 'My Hero DAG'
|
|
||||||
host: 'localhost'
|
|
||||||
port: 8888
|
|
||||||
|
|
||||||
"
|
|
||||||
|
|
||||||
return heroscript
|
|
||||||
}
|
|
||||||
|
|
||||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||||
|
@[heap]
|
||||||
pub struct GarageS3 {
|
pub struct GarageS3 {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string = 'default'
|
||||||
|
|
||||||
replication_mode string = '3'
|
replication_mode string = '3'
|
||||||
|
config_path string = '/var/garage/config.toml'
|
||||||
metadata_dir string = '/var/garage/meta'
|
metadata_dir string = '/var/garage/meta'
|
||||||
data_dir string = '/var/garage/data'
|
data_dir string = '/var/garage/data'
|
||||||
sled_cache_capacity u32 = 128 // in MB
|
sled_cache_capacity u32 = 128 // in MB
|
||||||
@@ -63,49 +47,102 @@ pub mut:
|
|||||||
restart bool = true
|
restart bool = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cfg_play(p paramsparser.Params) !GarageS3 {
|
// your checking & initialization code if needed
|
||||||
mut mycfg := GarageS3{
|
fn obj_init(mycfg_ GarageS3) !GarageS3 {
|
||||||
name: p.get_default('name', 'default')!
|
mut mycfg := mycfg_
|
||||||
replication_mode: p.get_default('replication_mode', '3')!
|
|
||||||
metadata_dir: p.get_default('metadata_dir', '/var/garage/meta')!
|
if mycfg.name == '' {
|
||||||
data_dir: p.get_default('data_dir', '/var/garage/data')!
|
mycfg.name = 'default'
|
||||||
sled_cache_capacity: p.get_u32_default('sled_cache_capacity', 128)!
|
|
||||||
compression_level: p.get_u8_default('compression_level', 1)!
|
|
||||||
rpc_secret: p.get_default('rpc_secret', '')!
|
|
||||||
rpc_bind_addr: p.get_default('rpc_bind_addr', '[::]:3901')!
|
|
||||||
rpc_public_addr: p.get_default('rpc_public_addr', '127.0.0.1:3901')!
|
|
||||||
api_bind_addr: p.get_default('api_bind_addr', '[::]:3900')!
|
|
||||||
s3_region: p.get_default('s3_region', 'garage')!
|
|
||||||
root_domain: p.get_default('root_domain', '.s3.garage')!
|
|
||||||
web_bind_addr: p.get_default('web_bind_addr', '[::]:3902')!
|
|
||||||
web_root_domain: p.get_default('web_root_domain', '.web.garage')!
|
|
||||||
admin_api_bind_addr: p.get_default('admin_api_bind_addr', '[::]:3903')!
|
|
||||||
admin_metrics_token: p.get_default('admin_metrics_token', '')!
|
|
||||||
admin_token: p.get_default('admin_token', '')!
|
|
||||||
admin_trace_sink: p.get_default('admin_trace_sink', 'http://localhost:4317')!
|
|
||||||
bootstrap_peers: p.get_list_default('bootstrap_peers', [])!
|
|
||||||
rpc_bind_outgoing: p.get_default_false('rpc_bind_outgoing')
|
|
||||||
reset: p.get_default_false('reset')
|
|
||||||
config_reset: p.get_default_false('config_reset')
|
|
||||||
start: p.get_default_true('start')
|
|
||||||
restart: p.get_default_true('restart')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mycfg
|
if mycfg.config_path == '' {
|
||||||
}
|
mycfg.config_path = '/var/garage/config.toml'
|
||||||
|
}
|
||||||
|
|
||||||
fn obj_init(obj_ GarageS3) !GarageS3 {
|
if mycfg.replication_mode == '' {
|
||||||
// never call get here, only thing we can do here is work on object itself
|
mycfg.replication_mode = '3'
|
||||||
mut obj := obj_
|
}
|
||||||
return obj
|
|
||||||
|
if mycfg.metadata_dir == '' {
|
||||||
|
mycfg.replication_mode = '/var/garage/meta'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.data_dir == '' {
|
||||||
|
mycfg.data_dir = '/var/garage/data'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.sled_cache_capacity == 0 {
|
||||||
|
mycfg.sled_cache_capacity = 128
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.compression_level == 0 {
|
||||||
|
mycfg.compression_level = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.rpc_bind_addr == '' {
|
||||||
|
mycfg.rpc_bind_addr = '[::]:3901'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.rpc_public_addr == '' {
|
||||||
|
mycfg.rpc_public_addr = '127.0.0.1:3901'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.api_bind_addr == '' {
|
||||||
|
mycfg.api_bind_addr = '[::]:3900'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.s3_region == '' {
|
||||||
|
mycfg.s3_region = 'garage'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.root_domain == '' {
|
||||||
|
mycfg.root_domain = '.s3.garage'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.web_bind_addr == '' {
|
||||||
|
mycfg.web_bind_addr = '[::]:3902'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.web_root_domain == '' {
|
||||||
|
mycfg.web_root_domain = '.web.garage'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.admin_api_bind_addr == '' {
|
||||||
|
mycfg.admin_api_bind_addr = '[::]:3903'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.admin_trace_sink == '' {
|
||||||
|
mycfg.admin_trace_sink = 'http://localhost:4317'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.admin_token == '' {
|
||||||
|
mycfg.admin_token = rand.hex(64)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.admin_metrics_token == '' {
|
||||||
|
mycfg.admin_metrics_token = rand.hex(64)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.rpc_secret == '' {
|
||||||
|
mycfg.rpc_secret = rand.hex(64)
|
||||||
|
}
|
||||||
|
return mycfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// called before start if done
|
// called before start if done
|
||||||
fn configure() ! {
|
fn configure() ! {
|
||||||
// mut installer := get()!
|
server := get()!
|
||||||
|
mut mycode := $tmpl('templates/config.ini')
|
||||||
// mut mycode := $tmpl('templates/atemplate.yaml')
|
mut path := pathlib.get_file(path: server.config_path, create: true)!
|
||||||
// mut path := pathlib.get_file(path: cfg.configpath, create: true)!
|
path.write(mycode)!
|
||||||
// path.write(mycode)!
|
console.print_debug(mycode)
|
||||||
// console.print_debug(mycode)
|
}
|
||||||
|
|
||||||
|
pub fn heroscript_dumps(obj GarageS3) !string {
|
||||||
|
return encoderhero.encode[GarageS3](obj)!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn heroscript_loads(heroscript string) !GarageS3 {
|
||||||
|
mut obj := encoderhero.decode[GarageS3](heroscript)!
|
||||||
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
name: ${cfg.configpath}
|
|
||||||
|
|
||||||
|
|
||||||
27
lib/installers/sysadmintools/garage_s3/templates/config.ini
Normal file
27
lib/installers/sysadmintools/garage_s3/templates/config.ini
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
metadata_dir = "${server.metadata_dir}"
|
||||||
|
data_dir = "${server.data_dir}"
|
||||||
|
db_engine = "sqlite"
|
||||||
|
|
||||||
|
replication_factor = ${server.replication_mode}
|
||||||
|
|
||||||
|
rpc_bind_addr = "${server.rpc_bind_addr}"
|
||||||
|
rpc_public_addr = "${server.rpc_public_addr}"
|
||||||
|
rpc_secret = "${server.rpc_secret}"
|
||||||
|
|
||||||
|
[s3_api]
|
||||||
|
s3_region = "${server.s3_region}"
|
||||||
|
api_bind_addr = "${server.api_bind_addr}"
|
||||||
|
root_domain = "${server.root_domain}"
|
||||||
|
|
||||||
|
[s3_web]
|
||||||
|
bind_addr = "${server.web_bind_addr}"
|
||||||
|
root_domain = "${server.web_root_domain}"
|
||||||
|
index = "index.html"
|
||||||
|
|
||||||
|
[k2v_api]
|
||||||
|
api_bind_addr = "${server.api_bind_addr}"
|
||||||
|
|
||||||
|
[admin]
|
||||||
|
api_bind_addr = "${server.admin_api_bind_addr}"
|
||||||
|
admin_token = "${server.admin_token}"
|
||||||
|
metrics_token = "${server.admin_metrics_token}"
|
||||||
Reference in New Issue
Block a user