fix ourtime, logging, some missing installers, ...

This commit is contained in:
2024-12-31 09:32:56 +01:00
parent a59a66dd71
commit f8ab2f855a
35 changed files with 1925 additions and 217 deletions

View File

@@ -0,0 +1,52 @@
module coredns
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.develop.gittools
import os
pub fn configure(args_ InstallArgs) ! {
mut args := args_
mut gs := gittools.get()!
mut repo_path := ''
if args.config_url.len > 0 {
mut repo := gs.get_repo(
url: args.config_url
)!
repo_path = repo.get_path()!
args.config_path = repo_path
}
if args.config_path.len == 0 {
args.config_path = '${os.home_dir()}/hero/cfg/Corefile'
}
if args.dnszones_url.len > 0 {
mut repo := gs.get_repo(
url: args.dnszones_url
)!
repo_path = repo.get_path()!
args.dnszones_path = repo_path
}
if args.dnszones_path.len == 0 {
args.dnszones_path = '${os.home_dir()}/hero/cfg/dnszones'
}
mycorefile := $tmpl('templates/Corefile')
mut path := pathlib.get_file(path: args.config_path, create: true)!
path.write(mycorefile)!
}
pub fn example_configure(args_ InstallArgs) ! {
mut args := args_
exampledbfile := $tmpl('templates/db.example.org')
mut path_testzone := pathlib.get_file(
path: '${args_.dnszones_path}/db.example.org'
create: true
)!
path_testzone.template_write(exampledbfile, true)!
}

View File

@@ -0,0 +1,138 @@
module coredns
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.osal.screen
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.clients.httpconnection
import os
@[params]
pub struct InstallArgs {
pub mut:
reset bool // this means we re-install and forgot what we did before
start bool = true
stop bool
restart bool // this means we stop if started, otherwise just start
homedir string // not sure what this is?
config_path string // path to Corefile, if empty will install default one
config_url string // path to Corefile through e.g. git url, will pull it if it is not local yet
dnszones_path string // path to where all the dns zones are
dnszones_url string // path on git url pull if needed
plugins []string // list of plugins to build CoreDNS with
example bool // if true we will install examples
}
pub fn install(args_ InstallArgs) ! {
mut args := args_
version := '1.11.1'
res := os.execute('${osal.profile_path_source_and()} coredns version')
if res.exit_code == 0 {
r := res.output.split_into_lines().filter(it.trim_space().starts_with('CoreDNS-'))
if r.len != 1 {
return error("couldn't parse coredns version.\n${res.output}")
}
if texttools.version(version) > texttools.version(r[0].all_after_first('CoreDNS-')) {
args.reset = true
}
} else {
args.reset = true
}
if args.reset {
console.print_header('install coredns')
mut url := ''
if osal.is_linux_arm() {
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_arm64.tgz'
} else if osal.is_linux_intel() {
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_amd64.tgz'
} else if osal.is_osx_arm() {
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_arm64.tgz'
} else if osal.is_osx_intel() {
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_amd64.tgz'
} else {
return error('unsported platform')
}
mut dest := osal.download(
url: url
minsize_kb: 13000
expand_dir: '/tmp/coredns'
)!
mut binpath := dest.file_get('coredns')!
osal.cmd_add(
cmdname: 'coredns'
source: binpath.path
)!
}
configure(args)!
if args.example {
example_configure(args)!
}
if args.restart {
restart(args)!
return
}
if args.start {
start(args)!
}
}
pub fn restart(args_ InstallArgs) ! {
stop(args_)!
start(args_)!
}
pub fn stop(args_ InstallArgs) ! {
console.print_header('coredns stop')
name := 'coredns'
// use startup manager, see caddy
mut scr := screen.new()!
scr.kill(name)!
}
pub fn start(args_ InstallArgs) ! {
mut args := args_
configure(args)!
if check()! {
return
}
console.print_header('coredns start')
name := 'coredns'
mut scr := screen.new()!
mut s := scr.add(name: name, reset: true)!
cmd2 := "coredns -conf '${args.config_path}'"
s.cmd_send(cmd2)!
if !check()! {
return error("coredns did not install propertly, do: curl 'http://localhost:3334/health'")
}
console.print_header('coredns running')
}
pub fn check() !bool {
// this checks health of coredns
mut conn := httpconnection.new(name: 'coredns', url: 'http://localhost:3334')!
r := conn.get(prefix: 'health')!
if r.trim_space() == 'OK' {
return true
}
return false
}

View File

@@ -0,0 +1,49 @@
module coredns
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.installers.base
import os
pub fn play(mut plbook playbook.PlayBook) ! {
base.play(playbook)!
coredns_actions := plbook.find(filter: 'coredns.')!
if coredns_actions.len == 0 {
return
}
mut install_actions := plbook.find(filter: 'coredns.install')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
// CoreDNS parameters
reset := p.get_default_false('reset')
start := p.get_default_true('start')
stop := p.get_default_false('stop')
restart := p.get_default_false('restart')
homedir := p.get_default('homedir', '${os.home_dir()}/hero/var/coredns')!
config_path := p.get_default('config_path', '${os.home_dir()}/hero/cfg/Corefile')!
config_url := p.get_default('config_url', '')!
dnszones_path := p.get_default('dnszones_path', '${os.home_dir()}/hero/var/coredns/zones')!
dnszones_url := p.get_default('dnszones_url', '')!
plugins := p.get_list_default('plugins', [])!
example := p.get_default_false('example')
install(
reset: reset
start: start
stop: stop
restart: restart
homedir: homedir
config_path: config_path
config_url: config_url
dnszones_path: dnszones_path
dnszones_url: dnszones_url
plugins: plugins
example: example
)!
}
}
}

View File

@@ -0,0 +1,7 @@
.:53 {
forward . 8.8.8.8 9.9.9.9
log
errors
health :3334
import '${args.dnszones_path}/*'
}

View File

@@ -0,0 +1,14 @@
??ORIGIN example.org.
^^ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. (
2017042745 ; serial
7200 ; refresh (2 hours)
3600 ; retry (1 hour)
1209600 ; expire (2 weeks)
3600 ; minimum (1 hour)
)
3600 IN NS a.iana-servers.net.
3600 IN NS b.iana-servers.net.
www IN A 127.0.0.1
IN AAAA ::1

View File

View File

@@ -0,0 +1,77 @@
module gitea
import freeflowuniverse.herolib.installers.db.postgresql as postgresinstaller
import freeflowuniverse.herolib.installers.base
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console
pub fn install() ! {
if osal.platform() != .ubuntu || osal.platform() != .arch {
return error('only support ubuntu and arch for now')
}
if osal.done_exists('gitea_install') {
console.print_header('gitea binaraies already installed')
return
}
// make sure we install base on the node
base.install()!
postgresinstaller.install()!
version := '1.22.0'
url := 'https://github.com/go-gitea/gitea/releases/download/v${version}/gitea-${version}-linux-amd64.xz'
console.print_debug(' download ${url}')
mut dest := osal.download(
url: url
minsize_kb: 40000
reset: true
expand_file: '/tmp/download/gitea'
)!
binpath := pathlib.get_file(path: '/tmp/download/gitea', create: false)!
osal.cmd_add(
cmdname: 'gitea'
source: binpath.path
)!
osal.done_set('gitea_install', 'OK')!
console.print_header('gitea installed properly.')
}
pub fn start() ! {
if osal.platform() != .ubuntu || osal.platform() != .arch {
return error('only support ubuntu and arch for now')
}
if osal.done_exists('gitea_install') {
console.print_header('gitea binaraies already installed')
return
}
// make sure we install base on the node
base.install()!
postgresinstaller.install()!
version := '1.22.0'
url := 'https://github.com/go-gitea/gitea/releases/download/v${version}/gitea-${version}-linux-amd64.xz'
console.print_debug(' download ${url}')
mut dest := osal.download(
url: url
minsize_kb: 40000
reset: true
expand_file: '/tmp/download/gitea'
)!
binpath := pathlib.get_file(path: '/tmp/download/gitea', create: false)!
osal.cmd_add(
cmdname: 'gitea'
source: binpath.path
)!
osal.done_set('gitea_install', 'OK')!
console.print_header('gitea installed properly.')
}

View File

@@ -0,0 +1,210 @@
module gitea
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.data.dbfs
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.installers.postgresql
import json
import rand
import os
import time
import freeflowuniverse.herolib.ui.console
@[params]
pub struct Config {
pub mut:
name string = 'default'
reset bool
path string = '/data/gitea'
passwd string
postgresql_name string = 'default'
mail_from string = 'git@meet.tf'
smtp_addr string = 'smtp-relay.brevo.com'
smtp_login string @[required]
smpt_port int = 587
smtp_passwd string
domain string @[required]
jwt_secret string
lfs_jwt_secret string
internal_token string
secret_key string
}
pub struct Server {
pub mut:
name string
config Config
process ?zinit.ZProcess
path_config pathlib.Path
}
// get the gitea server
//```js
// name string = 'default'
// path string = '/data/gitea'
// passwd 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_
if args.passwd == '' {
args.passwd = rand.string(12)
}
args.name = texttools.name_fix(args.name)
key := 'gitea_config_${args.name}'
mut kvs := dbfs.new(name: 'config')!
if !kvs.exists(key) {
// jwt_secret string
// lfs_jwt_secret string
// internal_token string
// secret_key string
if args.jwt_secret == '' {
r := os.execute_or_panic('gitea generate secret JWT_SECRET')
args.jwt_secret = r.output.trim_space()
}
if args.lfs_jwt_secret == '' {
r := os.execute_or_panic('gitea generate secret LFS_JWT_SECRET')
args.lfs_jwt_secret = r.output.trim_space()
}
if args.internal_token == '' {
r := os.execute_or_panic('gitea generate secret INTERNAL_TOKEN')
args.internal_token = r.output.trim_space()
}
if args.secret_key == '' {
r := os.execute_or_panic('gitea generate secret SECRET_KEY')
args.secret_key = r.output.trim_space()
}
data := json.encode(args)
kvs.set(key, data)!
}
return get(args.name)!
}
pub fn get(name_ string) !Server {
console.print_header('get gitea server ${name_}')
name := texttools.name_fix(name_)
key := 'gitea_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
path_config: pathlib.get_dir(path: '${args.path}/cfg', create: true)!
}
mut z := zinit.new()!
processname := 'gitea_${name}'
if z.process_exists(processname) {
server.process = z.process_get(processname)!
}
// console.print_debug(" - server get ok")
server.start()!
return server
}
return error("can't find server gitea with name ${name}")
}
// 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 .unknown }
return process.status() or { return .unknown }
}
// run gitea as docker compose
pub fn (mut server Server) start() ! {
// if server.ok(){
// return
// }
console.print_header('start gitea: ${server.name}')
mut db := postgresql.get(server.config.postgresql_name)!
// now create the DB
db.db_create('gitea')!
// if true{
// panic("sd")
// }
// TODO: postgresql can be on other server, need to fill in all arguments in template
t1 := $tmpl('templates/app.ini')
mut config_path := server.path_config.file_get_new('app.ini')!
config_path.write(t1)!
osal.user_add(name: 'git')!
osal.exec(
cmd: '
chown -R git:root ${server.config.path}
chmod -R 777 /usr/local/bin
'
)!
mut z := zinit.new()!
processname := 'gitea_${server.name}'
mut p := z.process_new(
name: processname
cmd: '
cd /tmp
sudo -u git bash -c \'gitea web --config ${config_path.path} --verbose\'
'
)!
p.output_wait('Starting new Web server: tcp:0.0.0.0:3000', 120)!
o := p.log()!
console.print_debug(o)
server.check()!
console.print_header('gitea start ok.')
}
pub fn (mut server Server) restart() ! {
server.stop()!
server.start()!
}
pub fn (mut server Server) stop() ! {
print_backtrace()
console.print_header('stop gitea: ${server.name}')
mut process := server.process or { return }
return process.stop()
}
// check health, return true if ok
pub fn (mut server Server) check() ! {
mut p := server.process or { return error("can't find process for server.") }
p.check()!
// TODO: need to do some other checks to gitea e.g. rest calls
}
// check health, return true if ok
pub fn (mut server Server) ok() bool {
server.check() or { return false }
return true
}
// remove all data
pub fn (mut server Server) destroy() ! {
server.stop()!
server.path_config.delete()!
}

View File

@@ -0,0 +1,108 @@
APP_NAME = ${server.config.name}
RUN_MODE = prod
RUN_USER = git
WORK_PATH = ${server.config.path}
[repository]
ROOT = ${server.config.path}/gitrepo
[repository.local]
LOCAL_COPY_PATH = ${server.config.path}/localrepo
[repository.upload]
TEMP_PATH = ${server.config.path}/uploads
[server]
APP_DATA_PATH = ${server.config.domain}
DOMAIN = ${server.config.domain}
SSH_DOMAIN = ${server.config.domain}
SSH_PORT = 22
SSH_LISTEN_PORT = 22
HTTP_PORT = 3000
ROOT_URL = https://${server.config.domain}
DISABLE_SSH = false
LFS_START_SERVER = true
LFS_JWT_SECRET = ${server.config.lfs_jwt_secret}
OFFLINE_MODE = false
[database]
PATH = ${server.config.path}/gitea.db
DB_TYPE = postgres
HOST = localhost:5432
NAME = gitea
USER = root
PASSWD = ${db.config.passwd}
LOG_SQL = false
SCHEMA =
SSL_MODE = disable
[indexer]
ISSUE_INDEXER_PATH = ${server.config.path}/indexers/issues.bleve
[session]
PROVIDER_CONFIG = ${server.config.path}/sessions
PROVIDER = file
[picture]
AVATAR_UPLOAD_PATH = ${server.config.path}/avatars
REPOSITORY_AVATAR_UPLOAD_PATH = ${server.config.path}/repo-avatars
[attachment]
PATH = ${server.config.path}/attachments
[log]
MODE = console
LEVEL = info
ROOT_PATH = ${server.config.path}/log
[security]
INSTALL_LOCK = true
SECRET_KEY = ${server.config.secret_key}
REVERSE_PROXY_LIMIT = 1
REVERSE_PROXY_TRUSTED_PROXIES = *
INTERNAL_TOKEN = ${server.config.internal_token}
PASSWORD_HASH_ALGO = pbkdf2
[service]
DISABLE_REGISTRATION = false
REQUIRE_SIGNIN_VIEW = false
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = true
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
ENABLE_CAPTCHA = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_ENABLE_TIMETRACKING = true
NO_REPLY_ADDRESS = noreply.localhost
[lfs]
PATH = ${server.config.path}/lfs
[mailer]
ENABLED = true
FROM = ${server.config.mail_from}
; PROTOCOL = smtps
SMTP_ADDR = ${server.config.smtp_addr}
SMTP_PORT = ${server.config.smpt_port}
USER = ${server.config.smtp_login}
PASSWD = ${server.config.smtp_passwd}
[openid]
ENABLE_OPENID_SIGNIN = true
ENABLE_OPENID_SIGNUP = true
[cron.update_checker]
ENABLED = false
[repository.pull-request]
DEFAULT_MERGE_STYLE = merge
[repository.signing]
DEFAULT_TRUST_MODEL = committer
[oauth2]
JWT_SECRET = ${server.config.jwt_secret}
[actions]
ENABLED=true

View File

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

View File

@@ -0,0 +1,110 @@
module livekit
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.core.pathlib
import net.http
import json
import os
// checks if a certain version or above is installed
fn installed() !bool {
res := os.execute('${osal.profile_path_source_and()} livekit-server -v')
if res.exit_code != 0 {
return false
}
r := res.output.split_into_lines().filter(it.contains("version"))
if r.len != 1 {
return error("couldn't parse livekit version.\n${res.output}")
}
installedversion:=r[0].all_after_first('version')
if texttools.version(version) != texttools.version(installedversion) {
return false
}
return true
}
fn install() ! {
console.print_header('install livekit')
mut installer := get()!
osal.execute_silent("
curl -s https://livekit.io/install.sh | bash
")!
}
fn startupcmd () ![]zinit.ZProcessNewArgs{
mut res := []zinit.ZProcessNewArgs{}
mut installer := get()!
res << zinit.ZProcessNewArgs{
name: 'livekit'
cmd: 'livekit-server --config ${installer.configpath} --bind 0.0.0.0'
}
return res
}
fn running() !bool {
mut installer := get()!
myport:=installer.nr*2+7880
endpoint := '${http://localhost:${myport}/api/v1/health'
response := http.get(endpoint) or {
println('Error connecting to LiveKit server: $err')
return false
}
if response.status_code != 200 {
println('LiveKit server returned non-200 status code: ${response.status_code}')
return false
}
health_info := json.decode(map[string]string, response.body) or {
println('Error decoding LiveKit server response: $err')
return false
}
if health_info['status'] != 'ok' {
println('LiveKit server health check failed: ${health_info["status"]}')
return false
}
return true
}
fn start_pre()!{
}
fn start_post()!{
}
fn stop_pre()!{
}
fn stop_post()!{
}
fn destroy() ! {
mut installer := get()!
os.rm("
${installer.configpath}
livekit-server
")!
}

View File

@@ -0,0 +1,229 @@
module livekit
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.ui.console
import time
__global (
livekit_global map[string]&LivekitServer
livekit_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string = "default"
}
fn args_get (args_ ArgsGet) ArgsGet {
mut args:=args_
if args.name == ""{
args.name = livekit_default
}
if args.name == ""{
args.name = "default"
}
return args
}
pub fn get(args_ ArgsGet) !&LivekitServer {
mut args := args_get(args_)
if !(args.name in livekit_global) {
if ! config_exists(){
if default{
config_save()!
}
}
config_load()!
}
return livekit_global[args.name] or {
println(livekit_global)
panic("bug in get from factory: ")
}
}
fn config_exists(args_ ArgsGet) bool {
mut args := args_get(args_)
mut context:=base.context() or { panic("bug") }
return context.hero_config_exists("livekit",args.name)
}
fn config_load(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context:=base.context()!
mut heroscript := context.hero_config_get("livekit",args.name)!
play(heroscript:heroscript)!
}
fn config_save(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context:=base.context()!
context.hero_config_set("livekit",args.name,heroscript_default()!)!
}
fn set(o LivekitServer)! {
mut o2:=obj_init(o)!
livekit_global["default"] = &o2
}
@[params]
pub struct PlayArgs {
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_ PlayArgs) ! {
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: 'livekit.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
mycfg:=cfg_play(p)!
set(mycfg)!
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//load from disk and make sure is properly intialized
pub fn (mut self LivekitServer) reload() ! {
switch(self.name)
self=obj_init(self)!
}
pub fn (mut self LivekitServer) start() ! {
switch(self.name)
if self.running()!{
return
}
console.print_header('livekit 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('livekit did not install properly.')
}
pub fn (mut self LivekitServer) install_start(args RestartArgs) ! {
switch(self.name)
self.install(args)!
self.start()!
}
pub fn (mut self LivekitServer) stop() ! {
switch(self.name)
stop_pre()!
mut sm := startupmanager.get()!
for zprocess in startupcmd()!{
sm.stop(zprocess.name)!
}
stop_post()!
}
pub fn (mut self LivekitServer) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self LivekitServer) 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 InstallArgs{
pub mut:
reset bool
}
pub fn (mut self LivekitServer) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn (mut self LivekitServer) destroy() ! {
switch(self.name)
self.stop()!
destroy()!
}
//switch instance to be used for livekit
pub fn switch(name string) {
livekit_default = name
}

View File

@@ -0,0 +1,89 @@
module livekit
import freeflowuniverse.herolib.data.paramsparser
import os
pub const version = '1.7.2'
const singleton = false
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:="
!!livekit.configure
name:'default'
apikey: ''
apisecret: ''
nr: 1 // each specific instance onto this server needs to have a unique nr
"
return heroscript
}
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
pub struct LivekitServer {
pub mut:
name string = 'default'
apikey string
apisecret string @[secret]
configpath string
nr int = 0 // each specific instance onto this server needs to have a unique nr
}
fn cfg_play(p paramsparser.Params) !LivekitServer {
mut mycfg := LivekitServer{
name: p.get_default('name', 'default')!
apikey: p.get_default('apikey', '')!
apisecret: p.get_default('apisecret', '')!
nr: p.get_default_int('nr', 0)!
}
return mycfg
}
fn obj_init(obj_ LivekitServer)!LivekitServer{
mut mycfg:=obj_
if mycfg.configpath == ''{
mycfg.configpath = '${os.home_dir()}/hero/cfg/livekit_${myconfig.name}.yaml'
}
if mycfg.apikey == '' || mycfg.apisecret == '' {
// Execute the livekit-server generate-keys command
result := os.execute('livekit-server generate-keys')
if result.exit_code != 0 {
return error('Failed to generate LiveKit keys')
}
// Split the output into lines
lines := result.output.split_into_lines()
// Extract API Key and API Secret
for line in lines {
if line.starts_with('API Key:') {
server.apikey = line.all_after('API Key:').trim_space()
} else if line.starts_with('API Secret:') {
server.apisecret = line.all_after('API Secret:').trim_space()
}
}
// Verify that both keys were extracted
if server.apikey == '' || server.apisecret == '' {
return error('Failed to extract API Key or API Secret')
}
}
return obj
}
//called before start if done
fn configure() ! {
mut installer := get()!
mut mycode := $tmpl('templates/config.yaml')
mut path := pathlib.get_file(path: installer.configpath, create: true)!
path.write(mycode)!
console.print_debug(mycode)
}

View File

@@ -0,0 +1,22 @@
# livekit
To get started
```vlang
import freeflowuniverse.herolib.installers.something. livekit
mut installer:= livekit.get()!
installer.start()!
```
livekit once installed will have generated the secret keys

View File

@@ -0,0 +1,26 @@
port: ${installer.nr*2+7880}
log_level: info
rtc:
tcp_port: ${installer.nr*2+7881}
port_range_start: ${installer.nr*1000+50000}
port_range_end: ${installer.nr*1000+999+50000}
# use_external_ip should be set to true for most cloud environments where
# the host has a public IP address, but is not exposed to the process.
# LiveKit will attempt to use STUN to discover the true IP, and advertise
# that IP with its clients
use_external_ip: true
redis:
# redis is recommended for production deploys
address: localhost:6379
keys:
# key-value pairs
${installer.apikey}: ${installer.apisecret}
# When enabled, LiveKit will expose prometheus metrics on :6789/metrics
#prometheus_port: ${installer.nr+6789}
# turn:
# enabled: true
# # domain must match tls certificate
# domain: <turn.myhost.com>
# # defaults to 3478. If not using a load balancer, must be set to 443.
# tls_port: 3478