commetbft

This commit is contained in:
2025-03-03 17:32:28 -05:00
parent 6bbaa0d1f7
commit fb9c9b8070
25 changed files with 735 additions and 352 deletions

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
import freeflowuniverse.herolib.installers.db.cometbft as cometbft_installer
// coredns_installer.delete()!
mut installer := cometbft_installer.get()!
installer.install()!

View File

@@ -8,33 +8,5 @@ import freeflowuniverse.herolib.core
core.interactive_set()! // make sure the sudo works so we can do things even if it requires those rights
// import freeflowuniverse.herolib.data.dbfs
// import freeflowuniverse.herolib.installers.lang.vlang
// import freeflowuniverse.herolib.installers.db.redis as redis_installer
// import freeflowuniverse.herolib.installers.infra.coredns as coredns_installer
// import freeflowuniverse.herolib.installers.sysadmintools.daguserver as dagu_installer
// import freeflowuniverse.herolib.installers.sysadmintools.b2 as b2_installer
// import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
// import freeflowuniverse.herolib.osal.screen
// import freeflowuniverse.herolib.osal
// redis_installer.new()!
// dagu_installer.install(passwd:"1234",secret:"1234",restart:true)!
// coredns_installer.install()!
// mycelium_installer.install()!
// mycelium_installer.restart()!
// mut screens:=screen.new()!
// println(screens)
// dagu_installer.check(secret:"1234")!
// vlang.v_analyzer_install()!
// b2_installer.install()!
// rust.install(reset:false)!
// python.install(reset:false)!
// nodejs.install(reset:false)!
golang.install(reset: false)!
mut i1:=golang.get()!
i1.install()!

View File

@@ -22,7 +22,6 @@ deployment.add_machine(
wireguard: true
public_ip4: false
size: 10 // 10 gig
mycelium: tfgrid3deployer.Mycelium{}
)
deployment.deploy()!

View File

@@ -18,8 +18,7 @@ fn main() {
memory: 2
planetary: false
public_ip4: false
mycelium: tfgrid3deployer.Mycelium{}
nodes: [u32(167)]
nodes: [167]
)
// deployment.add_machine(
// name: 'my_vm2'
@@ -27,7 +26,6 @@ fn main() {
// memory: 2
// planetary: false
// public_ip4: true
// mycelium: tfgrid3deployer.Mycelium{}
// // nodes: [u32(164)]
// )

View File

@@ -0,0 +1,13 @@
!!hero_code.generate_installer
name:'cometbft'
classname:'CometBFT'
singleton:0
templates:1
default:1
title:''
supported_platforms:''
reset:0
startupmanager:1
hasconfig:1
build:1

View File

@@ -0,0 +1,184 @@
module cometbft
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: 'cometbft'
// cmd: 'cometbft server'
// env: {
// 'HOME': '/root'
// }
// }
return res
}
fn running() !bool {
mut installer := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of cometbft
// 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: 'cometbft', 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('cometbft 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()!} cometbft 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 cometbft version.\n${res.output}")
// }
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return false
}
fn ulist_get() !ulist.UList {
return ulist.UList{}
}
// uploads to S3 server if configured
fn upload() ! {
// installers.upload(
// cmdname: 'cometbft'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/cometbft'
// )!
}
fn install() ! {
console.print_header('install cometbft')
mut url := ''
if core.is_linux_arm() {
url = 'https://github.com/cometbft/cometbft/releases/download/v${version}/cometbft_${version}_linux_arm64.tar.gz'
} else if core.is_linux_intel() {
url = 'https://github.com/cometbft/cometbft/releases/download/v${version}/cometbft_${version}_linux_amd64.tar.gz'
} else if core.is_osx_arm() {
url = 'https://github.com/cometbft/cometbft/releases/download/v${version}/cometbft_${version}_darwin_arm64.tar.gz'
} else if osal.is_osx_intel() {
url = 'https://github.com/cometbft/cometbft/releases/download/v${version}/cometbft_${version}_darwin_amd64.tar.gz'
} else {
return error('unsported platform')
}
mut dest := osal.download(
url: url
minsize_kb: 9000
expand_dir: '/tmp/cometbft'
)!
//dest.moveup_single_subdir()!
mut binpath := dest.file_get('cometbft')!
osal.cmd_add(
cmdname: 'cometbft'
source: binpath.path
)!
}
fn build() ! {
// url := 'https://github.com/threefoldtech/cometbft'
// 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 cometbft')
// 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,279 @@
module cometbft
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 (
cometbft_global map[string]&CometBFT
cometbft_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
fn args_get(args_ ArgsGet) ArgsGet {
mut args := args_
if args.name == '' {
args.name = 'default'
}
return args
}
pub fn get(args_ ArgsGet) !&CometBFT {
mut context := base.context()!
mut args := args_get(args_)
mut obj := CometBFT{}
if args.name !in cometbft_global {
if !exists(args)! {
set(obj)!
} else {
heroscript := context.hero_config_get('cometbft', args.name)!
mut obj_ := heroscript_loads(heroscript)!
set_in_mem(obj_)!
}
}
return cometbft_global[args.name] or {
println(cometbft_global)
// bug if we get here because should be in globals
panic('could not get config for cometbft with name, is bug:${args.name}')
}
}
// register the config for the future
pub fn set(o CometBFT) ! {
set_in_mem(o)!
mut context := base.context()!
heroscript := heroscript_dumps(o)!
context.hero_config_set('cometbft', o.name, heroscript)!
}
// does the config exists?
pub fn exists(args_ ArgsGet) !bool {
mut context := base.context()!
mut args := args_get(args_)
return context.hero_config_exists('cometbft', args.name)
}
pub fn delete(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()!
context.hero_config_delete('cometbft', args.name)!
if args.name in cometbft_global {
// del cometbft_global[args.name]
}
}
// only sets in mem, does not set as config
fn set_in_mem(o CometBFT) ! {
mut o2 := obj_init(o)!
cometbft_global[o.name] = &o2
cometbft_default = o.name
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut install_actions := plbook.find(filter: 'cometbft.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)!
set(obj2)!
}
}
mut other_actions := plbook.find(filter: 'cometbft.')!
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 cometbft.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action cometbft.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut cometbft_obj := get(name: name)!
console.print_debug('action object:\n${cometbft_obj}')
if other_action.name == 'start' {
console.print_debug('install action cometbft.${other_action.name}')
cometbft_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action cometbft.${other_action.name}')
cometbft_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action cometbft.${other_action.name}')
cometbft_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
// unknown
// screen
// zinit
// tmux
// systemd
match cat {
.zinit {
console.print_debug('startupmanager: zinit')
return startupmanager.get(cat: .zinit)!
}
.systemd {
console.print_debug('startupmanager: systemd')
return startupmanager.get(cat: .systemd)!
}
else {
console.print_debug('startupmanager: auto')
return startupmanager.get()!
}
}
}
// load from disk and make sure is properly intialized
pub fn (mut self CometBFT) reload() ! {
switch(self.name)
self = obj_init(self)!
}
pub fn (mut self CometBFT) start() ! {
switch(self.name)
if self.running()! {
return
}
console.print_header('cometbft start')
if !installed()! {
install()!
}
configure()!
start_pre()!
for zprocess in startupcmd()! {
mut sm := startupmanager_get(zprocess.startuptype)!
console.print_debug('starting cometbft 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('cometbft did not install properly.')
}
pub fn (mut self CometBFT) install_start(args InstallArgs) ! {
switch(self.name)
self.install(args)!
self.start()!
}
pub fn (mut self CometBFT) 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 CometBFT) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self CometBFT) 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 CometBFT) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self CometBFT) build() ! {
switch(self.name)
build()!
}
pub fn (mut self CometBFT) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for cometbft
pub fn switch(name string) {
cometbft_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -0,0 +1,52 @@
module cometbft
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import os
pub const version = '0.0.0'
const singleton = false
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 CometBFT {
pub mut:
name string = 'default'
// homedir string
// configpath string
// username string
// password string @[secret]
// title string
// host string
// port int
}
// your checking & initialization code if needed
fn obj_init(mycfg_ CometBFT) !CometBFT {
mut mycfg := mycfg_
if mycfg.password == '' && mycfg.secret == '' {
return error('password or secret needs to be filled in for ${mycfg.name}')
}
return mycfg
}
// called before start if done
fn configure() ! {
// mut installer := get()!
// mut mycode := $tmpl('templates/atemplate.yaml')
// mut path := pathlib.get_file(path: cfg.configpath, create: true)!
// path.write(mycode)!
// console.print_debug(mycode)
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj CometBFT) !string {
return encoderhero.encode[CometBFT](obj)!
}
pub fn heroscript_loads(heroscript string) !CometBFT {
mut obj := encoderhero.decode[CometBFT](heroscript)!
return obj
}

View File

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

View File

@@ -0,0 +1,5 @@
name: ${cfg.configpath}

View File

@@ -7,7 +7,6 @@
default:1
title:''
supported_platforms:''
reset:0
startupmanager:0
build:1
hasconfig:0

View File

@@ -9,7 +9,7 @@ import os
// checks if a certain version or above is installed
fn installed() !bool {
res := os.execute('/bin/bash -c "griddriver --version"')
res := os.execute("griddriver --version")
if res.exit_code != 0 {
return false
}
@@ -26,7 +26,6 @@ fn installed() !bool {
return true
}
// 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{}
@@ -37,7 +36,7 @@ fn upload() ! {}
fn install() ! {
console.print_header('install griddriver')
build()!
panic("to implement")
console.print_header('install griddriver OK')
}

View File

@@ -1,45 +0,0 @@
module caddy
import freeflowuniverse.herolib.data.paramsparser
pub const xcaddy_version = '0.4.2'
pub const caddy_version = '2.8.4'
const singleton = true
const default = true
const heroscript_default = "
!!caddy.configure
path: ''
domain: ''
plugins: ''
"
// CaddyServer represents a Caddy server configuration.
pub struct CaddyServer {
pub mut:
// name is the name of the Caddy server.
name string = 'default'
// path is the path to the server's root directory.
path string = '/var/www'
// domain is the default domain for the server.
domain string // sort of default domain
// plugins is a list of plugins to be used by the server.
plugins []string
}
fn cfg_play(p paramsparser.Params) ! {
mut mycfg := CaddyServer{
path: p.get_default('homedir', '{HOME}/hero/var/caddy')!
domain: p.get_default('configpath', '{HOME}/hero/var/caddy/admin.yaml')!
plugins: p.get_list_default('plugins', []string{})!
}
if mycfg.path == '' && mycfg.domain == '' {
return error('path or domain needs to be filled in for caddy')
}
set(mycfg)!
}

View File

@@ -1,129 +0,0 @@
module caddy
import freeflowuniverse.herolib.core.playbook
// import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.ui.console
import time
@[params]
pub struct InstallPlayArgs {
pub mut:
name string = 'default'
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
start bool
stop bool
restart bool
delete bool
configure bool // make sure there is at least one installed
}
pub fn play(args_ InstallPlayArgs) ! {
mut args := args_
if args.heroscript == '' {
args.heroscript = heroscript_default
}
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut install_actions := plbook.find(filter: 'caddy.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
cfg_play(p)!
}
}
}
// load from disk and make sure is properly intialized
// pub fn (mut self CaddyServer) reload() ! {
// switch(self.name)
// obj_init()!
// }
// pub fn (mut self CaddyServer) start() ! {
// switch(self.name)
// if self.running()! {
// return
// }
// console.print_header('caddy start')
// configure()!
// start_pre()!
// mut sm := startupmanager.get()!
// for zprocess in startupcmd()! {
// sm.start(zprocess.name)!
// }
// start_post()!
// for _ in 0 .. 50 {
// if self.running()! {
// return
// }
// time.sleep(100 * time.millisecond)
// }
// return error('caddy did not install properly.')
// }
// pub fn (mut self CaddyServer) install_start(args RestartArgs) ! {
// switch(self.name)
// self.install(args)!
// self.start()!
// }
// pub fn (mut self CaddyServer) stop() ! {
// switch(self.name)
// stop_pre()!
// mut sm := startupmanager.get()!
// for zprocess in startupcmd()! {
// sm.stop(zprocess.name)!
// }
// stop_post()!
// }
// pub fn (mut self CaddyServer) restart() ! {
// switch(self.name)
// self.stop()!
// self.start()!
// }
// pub fn (mut self CaddyServer) running() !bool {
// switch(self.name)
// mut sm := startupmanager.get()!
// // walk over the generic processes, if not running return
// for zprocess in startupcmd()! {
// r := sm.running(zprocess.name)!
// if r == false {
// return false
// }
// }
// return running()!
// }
// @[params]
// pub struct RestartArgs {
// pub mut:
// reset bool
// }
// pub fn (mut self CaddyServer) install(args RestartArgs) ! {
// switch(self.name)
// if args.reset || (!installed()!) {
// install()!
// }
// }
// pub fn (mut self CaddyServer) destroy() ! {
// switch(self.name)
// self.stop()!
// destroy()!
// }

View File

@@ -2,11 +2,57 @@ module caddy
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 os
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut res := []zinit.ZProcessNewArgs{}
res << zinit.ZProcessNewArgs{
name: 'caddy'
cmd: 'caddy run --config /etc/caddy/Caddyfile'
}
return res
}
fn running() !bool {
res := os.execute('${osal.profile_path_source_and()!} caddy version')
if res.exit_code == 0 {
mut r := res.output.split_into_lines().filter(it.trim_space().len > 0)
if r.len > 1 {
r = r.filter(it.starts_with('v'))
}
if r.len != 1 {
return error("couldn't parse caddy version.\n${r}")
}
if texttools.version(version) > texttools.version(r[0]) {
return false
}
return true
}
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 {
fn installed() !bool {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('${osal.profile_path_source_and()!} caddy version')
// if res.exit_code != 0 {
@@ -16,13 +62,28 @@ fn installed_() !bool {
// if r.len != 1 {
// return error("couldn't parse caddy version.\n${res.output}")
// }
// if texttools.version(version) > texttools.version(r[0]) {
// return false
// if texttools.version(version) == texttools.version(r[0]) {
// return true
// }
return true
return false
}
fn install_() ! {
// 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: 'caddy'
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/caddy'
// )!
}
fn install() ! {
console.print_header('install caddy')
mut cfg := get()!
@@ -67,24 +128,40 @@ fn install_() ! {
)!
}
fn startupcmd() ![]zinit.ZProcessNewArgs {
mut res := []zinit.ZProcessNewArgs{}
res << zinit.ZProcessNewArgs{
name: 'caddy'
cmd: 'caddy run --config /etc/caddy/Caddyfile'
}
return res
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
// ")!
}
// user needs to us switch to make sure we get the right object
fn configure() ! {
mut cfg := get()!
if !os.exists('/etc/caddy/Caddyfile') {
// set the default caddyfile
configure_examples(path: cfg.path)!
}
}
// configure caddy as default webserver & start
// node, path, domain
@@ -112,61 +189,3 @@ pub fn configure_examples(config WebConfig) ! {
configuration_set(content: config_file)!
}
fn running_() !bool {
mut cfg := get()!
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of caddy
// 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: 'caddy', 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('caddy is answering.')
return true
}
fn destroy_() ! {
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// cmd:="
// systemctl disable caddy_scheduler.service
// systemctl disable caddy.service
// systemctl stop caddy_scheduler.service
// systemctl stop caddy.service
// systemctl list-unit-files | grep caddy
// pkill -9 -f caddy
// ps aux | grep caddy
// "
// osal.exec(cmd: cmd, stdout:true, debug: false)!
}
fn obj_init() ! {
}
fn start_pre() ! {
}
fn start_post() ! {
}
fn stop_pre() ! {
}
fn stop_post() ! {
}

View File

@@ -0,0 +1,49 @@
module caddy
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import os
pub const xcaddy_version = '0.4.2'
pub const caddy_version = '2.8.4'
const singleton = true
const default = true
@[heap]
pub struct CaddyServer {
pub mut:
name string = 'default'
// path is the path to the server's root directory.
path string = '/var/www'
// domain is the default domain for the server.
domain string // sort of default domain
// plugins is a list of plugins to be used by the server.
plugins []string
}
// your checking & initialization code if needed
fn obj_init(mycfg_ CaddyServer) !CaddyServer {
mut mycfg := mycfg_
return mycfg
}
// user needs to us switch to make sure we get the right object
fn configure() ! {
mut cfg := get()!
if !os.exists('/etc/caddy/Caddyfile') {
// set the default caddyfile
configure_examples(path: cfg.path)!
}
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj CaddyServer) !string {
return encoderhero.encode[CaddyServer](obj)!
}
pub fn heroscript_loads(heroscript string) !CaddyServer {
mut obj := encoderhero.decode[CaddyServer](heroscript)!
return obj
}

View File

@@ -8,69 +8,7 @@ import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.installers.lang.golang
import os
pub const version = '2.8.4'
// @[params]
// pub struct InstallArgs {
// pub mut:
// reset bool
// start bool
// restart bool
// stop bool
// homedir string = '/var/www'
// file_path string // path to caddyfile
// file_url string // path to caddyfile
// xcaddy bool // wether to install caddy with xcaddy
// plugins []string // list of plugins to build caddy with
// }
// // install caddy will return true if it was already installed
// pub fn install_(args_ InstallArgs) ! {
// mut args := args_
// version := '2.8.4'
// installed := is_installed(version)!
// if args.reset || !installed {
// console.print_header('install caddy')
// if args.xcaddy || args.plugins.len > 0 {
// golang.install()!
// install_caddy_with_xcaddy(args.plugins)!
// } else {
// install_caddy_from_release()!
// }
// } else if args.plugins.any(!plugin_is_installed(it)!) {
// golang.install()!
// install_caddy_with_xcaddy(args.plugins)!
// }
// if args.restart {
// restart(args)!
// return
// }
// if args.start {
// start(args)!
// }
// }
pub fn is_installed(version string) !bool {
res := os.execute('${osal.profile_path_source_and()!} caddy version')
if res.exit_code == 0 {
mut r := res.output.split_into_lines().filter(it.trim_space().len > 0)
if r.len > 1 {
r = r.filter(it.starts_with('v'))
}
if r.len != 1 {
return error("couldn't parse caddy version.\n${r}")
}
if texttools.version(version) > texttools.version(r[0]) {
return false
}
return true
}
return false
}
pub fn install_caddy_from_release() ! {
version := '2.8.4'