Merge branch 'development_nile_installers' into development_fix_zinit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This file demonstrates how to configure all Horus components using heroscript
|
||||
|
||||
// Configure Coordinator
|
||||
!!herocoordinator.configure
|
||||
!!coordinator.configure
|
||||
name:'default'
|
||||
binary_path:'/hero/var/bin/coordinator'
|
||||
redis_addr:'127.0.0.1:6379'
|
||||
|
||||
@@ -13,6 +13,11 @@ import incubaid.herolib.osal.tmux
|
||||
import incubaid.herolib.installers.base
|
||||
import incubaid.herolib.installers.lang.vlang
|
||||
import incubaid.herolib.installers.lang.herolib
|
||||
import incubaid.herolib.installers.horus.coordinator
|
||||
import incubaid.herolib.installers.horus.supervisor
|
||||
import incubaid.herolib.installers.horus.herorunner
|
||||
import incubaid.herolib.installers.horus.osirisrunner
|
||||
import incubaid.herolib.installers.horus.salrunner
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// run – entry point for all HeroScript play‑commands
|
||||
@@ -69,6 +74,13 @@ pub fn run(args_ PlayArgs) ! {
|
||||
|
||||
giteaclient.play(mut plbook)!
|
||||
|
||||
// Horus
|
||||
coordinator.play(mut plbook)!
|
||||
supervisor.play(mut plbook)!
|
||||
herorunner.play(mut plbook)!
|
||||
osirisrunner.play(mut plbook)!
|
||||
salrunner.play(mut plbook)!
|
||||
|
||||
if args.emptycheck {
|
||||
// Ensure we did not leave any actions un‑processed
|
||||
plbook.empty_check()!
|
||||
|
||||
@@ -21,6 +21,11 @@ import incubaid.herolib.clients.zerodb_client
|
||||
import incubaid.herolib.clients.zinit
|
||||
import incubaid.herolib.develop.heroprompt
|
||||
import incubaid.herolib.installers.db.meilisearch_installer
|
||||
import incubaid.herolib.installers.horus.coordinator
|
||||
import incubaid.herolib.installers.horus.supervisor
|
||||
import incubaid.herolib.installers.horus.herorunner
|
||||
import incubaid.herolib.installers.horus.osirisrunner
|
||||
import incubaid.herolib.installers.horus.salrunner
|
||||
import incubaid.herolib.installers.infra.coredns
|
||||
import incubaid.herolib.installers.infra.gitea
|
||||
import incubaid.herolib.installers.infra.livekit
|
||||
@@ -38,7 +43,6 @@ import incubaid.herolib.installers.sysadmintools.garage_s3
|
||||
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.kubernetes_installer
|
||||
import incubaid.herolib.installers.virt.lima
|
||||
import incubaid.herolib.installers.virt.pacman
|
||||
@@ -109,4 +113,9 @@ pub fn run_all(args_ PlayArgs) ! {
|
||||
zola.play(mut plbook)!
|
||||
hetznermanager.play(mut plbook)!
|
||||
kubernetes.play(mut plbook)!
|
||||
coordinator.play(mut plbook)!
|
||||
supervisor.play(mut plbook)!
|
||||
herorunner.play(mut plbook)!
|
||||
osirisrunner.play(mut plbook)!
|
||||
salrunner.play(mut plbook)!
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:''
|
||||
classname:'CoordinatorServer'
|
||||
classname:'Coordinator'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
|
||||
@@ -9,16 +9,15 @@ import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut cfg := get()!
|
||||
fn (self &Coordinator) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
res << startupmanager.ZProcessNewArgs{
|
||||
name: 'coordinator'
|
||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr} --api-http-port ${cfg.http_port} --api-ws-port ${cfg.ws_port}'
|
||||
cmd: '${self.binary_path} --redis-addr ${self.redis_addr} --api-http-port ${self.http_port} --api-ws-port ${self.ws_port}'
|
||||
env: {
|
||||
'HOME': os.home_dir()
|
||||
'RUST_LOG': cfg.log_level
|
||||
'RUST_LOG': self.log_level
|
||||
'RUST_LOG_STYLE': 'never'
|
||||
}
|
||||
}
|
||||
@@ -26,37 +25,34 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut cfg := get()!
|
||||
fn (self &Coordinator) running_check() !bool {
|
||||
// Check if the process is running by checking the HTTP port
|
||||
res := osal.exec(
|
||||
cmd: 'curl -fsSL http://127.0.0.1:${cfg.http_port} || exit 1'
|
||||
cmd: 'curl -fsSL http://127.0.0.1:${self.http_port} || exit 1'
|
||||
stdout: false
|
||||
raise_error: false
|
||||
)!
|
||||
return res.exit_code == 0
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
fn (self &Coordinator) start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
fn (self &Coordinator) start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
fn (self &Coordinator) stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
fn (self &Coordinator) stop_post() ! {
|
||||
}
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
mut cfg := get()!
|
||||
|
||||
fn (self &Coordinator) installed() !bool {
|
||||
// Check if the binary exists
|
||||
mut binary := pathlib.get(cfg.binary_path)
|
||||
mut binary := pathlib.get(self.binary_path)
|
||||
if !binary.exists() {
|
||||
return false
|
||||
}
|
||||
@@ -78,10 +74,16 @@ fn upload() ! {
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn (mut self Coordinator) install(args InstallArgs) ! {
|
||||
console.print_header('install coordinator')
|
||||
// For coordinator, we build from source instead of downloading
|
||||
build()!
|
||||
self.build()!
|
||||
}
|
||||
|
||||
// Public function to build coordinator without requiring factory/redis
|
||||
@@ -91,7 +93,7 @@ pub fn build_coordinator() ! {
|
||||
|
||||
// Use default config instead of getting from factory
|
||||
println('⚙️ Initializing configuration...')
|
||||
mut cfg := CoordinatorServer{}
|
||||
mut cfg := Coordinator{}
|
||||
println('✅ Configuration initialized')
|
||||
println(' - Binary path: ${cfg.binary_path}')
|
||||
println(' - Redis address: ${cfg.redis_addr}')
|
||||
@@ -150,10 +152,10 @@ pub fn build_coordinator() ! {
|
||||
println('📍 Binary location: ${cfg.binary_path}')
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
fn (mut self Coordinator) build() ! {
|
||||
console.print_header('build coordinator')
|
||||
|
||||
mut cfg := get()!
|
||||
println('Building coordinator binary from ${self}')
|
||||
|
||||
// Ensure Redis is installed and running (required for coordinator)
|
||||
console.print_debug('Checking if Redis is installed and running...')
|
||||
@@ -192,41 +194,40 @@ fn build() ! {
|
||||
)!
|
||||
|
||||
// Update the path to the actual cloned repo
|
||||
cfg.repo_path = repo.path()
|
||||
set(cfg)!
|
||||
console.print_debug('Repository path: ${cfg.repo_path}')
|
||||
self.repo_path = repo.path()
|
||||
set(self)!
|
||||
console.print_debug('Repository path: ${self.repo_path}')
|
||||
|
||||
// Build the coordinator binary from the horus workspace
|
||||
console.print_header('Building coordinator binary (this may take several minutes ${cfg.repo_path})...')
|
||||
console.print_header('Building coordinator binary (this may take several minutes ${self.repo_path})...')
|
||||
console.print_debug('Running: cargo build -p hero-coordinator --release')
|
||||
console.print_debug('Build output:')
|
||||
|
||||
cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release'
|
||||
cmd := 'cd ${self.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-coordinator --release'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
console.print_debug('Build completed successfully')
|
||||
|
||||
// Ensure binary directory exists and copy the binary
|
||||
console.print_header('Preparing binary directory: ${cfg.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(cfg.binary_path)
|
||||
console.print_header('Preparing binary directory: ${self.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
|
||||
// Copy the built binary to the configured location
|
||||
source_binary := '${cfg.repo_path}/target/release/coordinator'
|
||||
source_binary := '${self.repo_path}/target/release/coordinator'
|
||||
console.print_debug('Copying binary from: ${source_binary}')
|
||||
console.print_debug('Copying binary to: ${cfg.binary_path}')
|
||||
console.print_debug('Copying binary to: ${self.binary_path}')
|
||||
mut source_file := pathlib.get_file(path: source_binary)!
|
||||
source_file.copy(dest: cfg.binary_path, rsync: false)!
|
||||
source_file.copy(dest: self.binary_path, rsync: false)!
|
||||
|
||||
console.print_header('coordinator built successfully at ${cfg.binary_path}')
|
||||
console.print_header('coordinator built successfully at ${self.binary_path}')
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut server := get()!
|
||||
server.stop()!
|
||||
fn (mut self Coordinator) destroy() ! {
|
||||
self.stop()!
|
||||
|
||||
osal.process_kill_recursive(name: 'coordinator')!
|
||||
|
||||
// Remove the built binary
|
||||
osal.rm(server.binary_path)!
|
||||
osal.rm(self.binary_path)!
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
coordinator_global map[string]&CoordinatorServer
|
||||
coordinator_global map[string]&Coordinator
|
||||
coordinator_default string
|
||||
)
|
||||
|
||||
@@ -28,8 +28,8 @@ pub mut:
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&CoordinatorServer {
|
||||
mut obj := CoordinatorServer{
|
||||
pub fn new(args ArgsGet) !&Coordinator {
|
||||
mut obj := Coordinator{
|
||||
name: args.name
|
||||
binary_path: args.binary_path
|
||||
redis_addr: args.redis_addr
|
||||
@@ -48,7 +48,7 @@ pub fn new(args ArgsGet) !&CoordinatorServer {
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&CoordinatorServer {
|
||||
pub fn get(args ArgsGet) !&Coordinator {
|
||||
mut context := base.context()!
|
||||
coordinator_default = args.name
|
||||
if args.fromdb || args.name !in coordinator_global {
|
||||
@@ -57,16 +57,16 @@ pub fn get(args ArgsGet) !&CoordinatorServer {
|
||||
data := r.hget('context:coordinator', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('CoordinatorServer with name: ${args.name} does not exist, prob bug.')
|
||||
return error('Coordinator with name: ${args.name} does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(CoordinatorServer, data)!
|
||||
mut obj := json.decode(Coordinator, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("CoordinatorServer with name '${args.name}' does not exist")
|
||||
return error("Coordinator with name '${args.name}' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
@@ -78,7 +78,7 @@ pub fn get(args ArgsGet) !&CoordinatorServer {
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o CoordinatorServer) ! {
|
||||
pub fn set(o Coordinator) ! {
|
||||
mut o2 := set_in_mem(o)!
|
||||
coordinator_default = o2.name
|
||||
mut context := base.context()!
|
||||
@@ -106,12 +106,12 @@ pub mut:
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&CoordinatorServer {
|
||||
mut res := []&CoordinatorServer{}
|
||||
pub fn list(args ArgsList) ![]&Coordinator {
|
||||
mut res := []&Coordinator{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
coordinator_global = map[string]&CoordinatorServer{}
|
||||
coordinator_global = map[string]&Coordinator{}
|
||||
coordinator_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
@@ -132,7 +132,7 @@ pub fn list(args ArgsList) ![]&CoordinatorServer {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o CoordinatorServer) !CoordinatorServer {
|
||||
fn set_in_mem(o Coordinator) !Coordinator {
|
||||
mut o2 := obj_init(o)!
|
||||
coordinator_global[o2.name] = &o2
|
||||
coordinator_default = o2.name
|
||||
@@ -156,17 +156,25 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
mut coordinator_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${coordinator_obj}')
|
||||
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action coordinator.destroy')
|
||||
destroy()!
|
||||
coordinator_obj.destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action coordinator.install')
|
||||
install()!
|
||||
coordinator_obj.install(reset: reset)!
|
||||
}
|
||||
if other_action.name == 'build' {
|
||||
console.print_debug('install action coordinator.build')
|
||||
coordinator_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut coordinator_obj := get(name: name)!
|
||||
@@ -175,7 +183,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.stop()!
|
||||
@@ -184,6 +191,22 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.restart()!
|
||||
}
|
||||
if other_action.name == 'start_pre' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.start_pre()!
|
||||
}
|
||||
if other_action.name == 'start_post' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.start_post()!
|
||||
}
|
||||
if other_action.name == 'stop_pre' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.stop_pre()!
|
||||
}
|
||||
if other_action.name == 'stop_post' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@@ -221,12 +244,12 @@ fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.Sta
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self CoordinatorServer) reload() ! {
|
||||
pub fn (mut self Coordinator) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) start() ! {
|
||||
pub fn (mut self Coordinator) start() ! {
|
||||
switch(self.name)
|
||||
|
||||
if self.running()! {
|
||||
@@ -235,14 +258,14 @@ pub fn (mut self CoordinatorServer) start() ! {
|
||||
|
||||
console.print_header('installer: coordinator start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
if !self.installed()! {
|
||||
self.install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
self.configure()!
|
||||
|
||||
start_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.start_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: coordinator starting with ${zprocess.startuptype}...')
|
||||
@@ -252,7 +275,7 @@ pub fn (mut self CoordinatorServer) start() ! {
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
self.start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
@@ -263,33 +286,33 @@ pub fn (mut self CoordinatorServer) start() ! {
|
||||
return error('coordinator did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) install_start(args InstallArgs) ! {
|
||||
pub fn (mut self Coordinator) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) stop() ! {
|
||||
pub fn (mut self Coordinator) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.stop_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) restart() ! {
|
||||
pub fn (mut self Coordinator) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) running() !bool {
|
||||
pub fn (mut self Coordinator) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
@@ -298,31 +321,7 @@ pub fn (mut self CoordinatorServer) running() !bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoordinatorServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
// switch instance to be used for coordinator
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 CoordinatorServer {
|
||||
pub struct Coordinator {
|
||||
pub mut:
|
||||
name string = 'coordinator'
|
||||
binary_path string = os.join_path(os.home_dir(), 'hero/bin/coordinator')
|
||||
@@ -24,7 +24,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ CoordinatorServer) !CoordinatorServer {
|
||||
fn obj_init(mycfg_ Coordinator) !Coordinator {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'default'
|
||||
@@ -51,20 +51,19 @@ fn obj_init(mycfg_ CoordinatorServer) !CoordinatorServer {
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
mut server := get()!
|
||||
fn (self &Coordinator) configure() ! {
|
||||
// Ensure the binary directory exists
|
||||
mut binary_path_obj := pathlib.get(server.binary_path)
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
}
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj CoordinatorServer) !string {
|
||||
return encoderhero.encode[CoordinatorServer](obj)!
|
||||
pub fn heroscript_dumps(obj Coordinator) !string {
|
||||
return encoderhero.encode[Coordinator](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !CoordinatorServer {
|
||||
mut obj := encoderhero.decode[CoordinatorServer](heroscript)!
|
||||
pub fn heroscript_loads(heroscript string) !Coordinator {
|
||||
mut obj := encoderhero.decode[Coordinator](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:''
|
||||
classname:'HerorunnerServer'
|
||||
classname:'Herorunner'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
|
||||
@@ -9,16 +9,15 @@ import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut cfg := get()!
|
||||
fn (self &Herorunner) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
res << startupmanager.ZProcessNewArgs{
|
||||
name: 'herorunner'
|
||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr}'
|
||||
cmd: '${self.binary_path} --redis-addr ${self.redis_addr}'
|
||||
env: {
|
||||
'HOME': os.home_dir()
|
||||
'RUST_LOG': cfg.log_level
|
||||
'RUST_LOG': self.log_level
|
||||
'RUST_LOG_STYLE': 'never'
|
||||
}
|
||||
}
|
||||
@@ -26,32 +25,30 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
fn (self &Herorunner) running_check() !bool {
|
||||
// Check if the process is running
|
||||
res := osal.exec(cmd: 'pgrep -f herorunner', stdout: false, raise_error: false)!
|
||||
return res.exit_code == 0
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
fn (self &Herorunner) start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
fn (self &Herorunner) start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
fn (self &Herorunner) stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
fn (self &Herorunner) stop_post() ! {
|
||||
}
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
mut cfg := get()!
|
||||
|
||||
fn (self &Herorunner) installed() !bool {
|
||||
// Check if the binary exists
|
||||
mut binary := pathlib.get(cfg.binary_path)
|
||||
mut binary := pathlib.get(self.binary_path)
|
||||
if !binary.exists() {
|
||||
return false
|
||||
}
|
||||
@@ -69,17 +66,22 @@ fn ulist_get() !ulist.UList {
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install herorunner')
|
||||
// For herorunner, we build from source instead of downloading
|
||||
build()!
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
fn (mut self Herorunner) install(args InstallArgs) ! {
|
||||
console.print_header('install herorunner')
|
||||
// For herorunner, we build from source instead of downloading
|
||||
self.build()!
|
||||
}
|
||||
|
||||
fn (mut self Herorunner) build() ! {
|
||||
console.print_header('build herorunner')
|
||||
|
||||
mut cfg := get()!
|
||||
|
||||
// Ensure rust is installed
|
||||
console.print_debug('Checking if Rust is installed...')
|
||||
mut rust_installer := rust.get()!
|
||||
@@ -114,26 +116,25 @@ fn build() ! {
|
||||
console.print_debug('Build completed successfully')
|
||||
|
||||
// Ensure binary directory exists and copy the binary
|
||||
console.print_debug('Preparing binary directory: ${cfg.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(cfg.binary_path)
|
||||
console.print_debug('Preparing binary directory: ${self.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
|
||||
// Copy the built binary to the configured location
|
||||
source_binary := '${repo_path}/target/release/herorunner'
|
||||
console.print_debug('Copying binary from: ${source_binary}')
|
||||
console.print_debug('Copying binary to: ${cfg.binary_path}')
|
||||
console.print_debug('Copying binary to: ${self.binary_path}')
|
||||
mut source_file := pathlib.get_file(path: source_binary)!
|
||||
source_file.copy(dest: cfg.binary_path, rsync: false)!
|
||||
source_file.copy(dest: self.binary_path, rsync: false)!
|
||||
|
||||
console.print_header('herorunner built successfully at ${cfg.binary_path}')
|
||||
console.print_header('herorunner built successfully at ${self.binary_path}')
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut server := get()!
|
||||
server.stop()!
|
||||
fn (mut self Herorunner) destroy() ! {
|
||||
self.stop()!
|
||||
|
||||
osal.process_kill_recursive(name: 'herorunner')!
|
||||
|
||||
// Remove the built binary
|
||||
osal.rm(server.binary_path)!
|
||||
osal.rm(self.binary_path)!
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
herorunner_global map[string]&HerorunnerServer
|
||||
herorunner_global map[string]&Herorunner
|
||||
herorunner_default string
|
||||
)
|
||||
|
||||
@@ -25,8 +25,8 @@ pub mut:
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&HerorunnerServer {
|
||||
mut obj := HerorunnerServer{
|
||||
pub fn new(args ArgsGet) !&Herorunner {
|
||||
mut obj := Herorunner{
|
||||
name: args.name
|
||||
binary_path: args.binary_path
|
||||
redis_addr: args.redis_addr
|
||||
@@ -36,7 +36,7 @@ pub fn new(args ArgsGet) !&HerorunnerServer {
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&HerorunnerServer {
|
||||
pub fn get(args ArgsGet) !&Herorunner {
|
||||
mut context := base.context()!
|
||||
herorunner_default = args.name
|
||||
if args.fromdb || args.name !in herorunner_global {
|
||||
@@ -45,16 +45,16 @@ pub fn get(args ArgsGet) !&HerorunnerServer {
|
||||
data := r.hget('context:herorunner', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('HerorunnerServer with name: ${args.name} does not exist, prob bug.')
|
||||
return error('Herorunner with name: ${args.name} does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(HerorunnerServer, data)!
|
||||
mut obj := json.decode(Herorunner, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("HerorunnerServer with name '${args.name}' does not exist")
|
||||
return error("Herorunner with name '${args.name}' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
@@ -66,7 +66,7 @@ pub fn get(args ArgsGet) !&HerorunnerServer {
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o HerorunnerServer) ! {
|
||||
pub fn set(o Herorunner) ! {
|
||||
mut o2 := set_in_mem(o)!
|
||||
herorunner_default = o2.name
|
||||
mut context := base.context()!
|
||||
@@ -94,12 +94,12 @@ pub mut:
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&HerorunnerServer {
|
||||
mut res := []&HerorunnerServer{}
|
||||
pub fn list(args ArgsList) ![]&Herorunner {
|
||||
mut res := []&Herorunner{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
herorunner_global = map[string]&HerorunnerServer{}
|
||||
herorunner_global = map[string]&Herorunner{}
|
||||
herorunner_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
@@ -120,7 +120,7 @@ pub fn list(args ArgsList) ![]&HerorunnerServer {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o HerorunnerServer) !HerorunnerServer {
|
||||
fn set_in_mem(o Herorunner) !Herorunner {
|
||||
mut o2 := obj_init(o)!
|
||||
herorunner_global[o2.name] = &o2
|
||||
herorunner_default = o2.name
|
||||
@@ -144,17 +144,25 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
mut herorunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${herorunner_obj}')
|
||||
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action herorunner.destroy')
|
||||
destroy()!
|
||||
herorunner_obj.destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action herorunner.install')
|
||||
install()!
|
||||
herorunner_obj.install(reset: reset)!
|
||||
}
|
||||
if other_action.name == 'build' {
|
||||
console.print_debug('install action herorunner.build')
|
||||
herorunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut herorunner_obj := get(name: name)!
|
||||
@@ -163,7 +171,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.stop()!
|
||||
@@ -172,6 +179,22 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.restart()!
|
||||
}
|
||||
if other_action.name == 'start_pre' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.start_pre()!
|
||||
}
|
||||
if other_action.name == 'start_post' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.start_post()!
|
||||
}
|
||||
if other_action.name == 'stop_pre' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.stop_pre()!
|
||||
}
|
||||
if other_action.name == 'stop_post' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@@ -208,12 +231,12 @@ fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.Sta
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self HerorunnerServer) reload() ! {
|
||||
pub fn (mut self Herorunner) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) start() ! {
|
||||
pub fn (mut self Herorunner) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
@@ -221,15 +244,13 @@ pub fn (mut self HerorunnerServer) start() ! {
|
||||
|
||||
console.print_header('installer: herorunner start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
if !self.installed()! {
|
||||
self.install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
self.start_pre()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: herorunner starting with ${zprocess.startuptype}...')
|
||||
@@ -239,7 +260,7 @@ pub fn (mut self HerorunnerServer) start() ! {
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
self.start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
@@ -250,33 +271,33 @@ pub fn (mut self HerorunnerServer) start() ! {
|
||||
return error('herorunner did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) install_start(args InstallArgs) ! {
|
||||
pub fn (mut self Herorunner) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) stop() ! {
|
||||
pub fn (mut self Herorunner) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.stop_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) restart() ! {
|
||||
pub fn (mut self Herorunner) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) running() !bool {
|
||||
pub fn (mut self Herorunner) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
@@ -285,31 +306,7 @@ pub fn (mut self HerorunnerServer) running() !bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self HerorunnerServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
// switch instance to be used for herorunner
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 HerorunnerServer {
|
||||
pub struct Herorunner {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
binary_path string = os.join_path(os.home_dir(), 'hero/bin/herorunner')
|
||||
@@ -21,7 +21,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ HerorunnerServer) !HerorunnerServer {
|
||||
fn obj_init(mycfg_ Herorunner) !Herorunner {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'default'
|
||||
@@ -48,11 +48,11 @@ fn configure() ! {
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj HerorunnerServer) !string {
|
||||
return encoderhero.encode[HerorunnerServer](obj)!
|
||||
pub fn heroscript_dumps(obj Herorunner) !string {
|
||||
return encoderhero.encode[Herorunner](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !HerorunnerServer {
|
||||
mut obj := encoderhero.decode[HerorunnerServer](heroscript)!
|
||||
pub fn heroscript_loads(heroscript string) !Herorunner {
|
||||
mut obj := encoderhero.decode[Herorunner](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:''
|
||||
classname:'OsirisrunnerServer'
|
||||
classname:'Osirisrunner'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
|
||||
@@ -9,16 +9,15 @@ import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut cfg := get()!
|
||||
fn (self &Osirisrunner) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
res << startupmanager.ZProcessNewArgs{
|
||||
name: 'runner_osiris'
|
||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr}'
|
||||
cmd: '${self.binary_path} --redis-addr ${self.redis_addr}'
|
||||
env: {
|
||||
'HOME': os.home_dir()
|
||||
'RUST_LOG': cfg.log_level
|
||||
'RUST_LOG': self.log_level
|
||||
'RUST_LOG_STYLE': 'never'
|
||||
}
|
||||
}
|
||||
@@ -26,33 +25,30 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut cfg := get()!
|
||||
fn (self &Osirisrunner) running_check() !bool {
|
||||
// Check if the process is running
|
||||
res := osal.exec(cmd: 'pgrep -f runner_osiris', stdout: false, raise_error: false)!
|
||||
return res.exit_code == 0
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
fn (self &Osirisrunner) start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
fn (self &Osirisrunner) start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
fn (self &Osirisrunner) stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
fn (self &Osirisrunner) stop_post() ! {
|
||||
}
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
mut cfg := get()!
|
||||
|
||||
fn (self &Osirisrunner) installed() !bool {
|
||||
// Check if the binary exists
|
||||
mut binary := pathlib.get(cfg.binary_path)
|
||||
mut binary := pathlib.get(self.binary_path)
|
||||
if !binary.exists() {
|
||||
return false
|
||||
}
|
||||
@@ -70,17 +66,22 @@ fn ulist_get() !ulist.UList {
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install osirisrunner')
|
||||
// For osirisrunner, we build from source instead of downloading
|
||||
build()!
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
fn (mut self Osirisrunner) install(args InstallArgs) ! {
|
||||
console.print_header('install osirisrunner')
|
||||
// For osirisrunner, we build from source instead of downloading
|
||||
self.build()!
|
||||
}
|
||||
|
||||
fn (mut self Osirisrunner) build() ! {
|
||||
console.print_header('build osirisrunner')
|
||||
|
||||
mut cfg := get()!
|
||||
|
||||
// Ensure rust is installed
|
||||
console.print_debug('Checking if Rust is installed...')
|
||||
mut rust_installer := rust.get()!
|
||||
@@ -102,41 +103,40 @@ fn build() ! {
|
||||
)!
|
||||
|
||||
// Update the path to the actual cloned repo
|
||||
cfg.repo_path = repo.path()
|
||||
set(cfg)!
|
||||
console.print_debug('Repository path: ${cfg.repo_path}')
|
||||
self.repo_path = repo.path()
|
||||
set(self)!
|
||||
console.print_debug('Repository path: ${self.repo_path}')
|
||||
|
||||
// Build the osirisrunner binary from the horus workspace
|
||||
console.print_header('Building osirisrunner binary (this may take several minutes)...')
|
||||
console.print_debug('Running: cargo build -p runner-osiris --release')
|
||||
console.print_debug('Build output:')
|
||||
|
||||
cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p runner-osiris --release'
|
||||
cmd := 'cd ${self.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p runner-osiris --release'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
console.print_debug('Build completed successfully')
|
||||
|
||||
// Ensure binary directory exists and copy the binary
|
||||
console.print_debug('Preparing binary directory: ${cfg.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(cfg.binary_path)
|
||||
console.print_debug('Preparing binary directory: ${self.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
|
||||
// Copy the built binary to the configured location
|
||||
source_binary := '${cfg.repo_path}/target/release/runner_osiris'
|
||||
source_binary := '${self.repo_path}/target/release/runner_osiris'
|
||||
console.print_debug('Copying binary from: ${source_binary}')
|
||||
console.print_debug('Copying binary to: ${cfg.binary_path}')
|
||||
console.print_debug('Copying binary to: ${self.binary_path}')
|
||||
mut source_file := pathlib.get_file(path: source_binary)!
|
||||
source_file.copy(dest: cfg.binary_path, rsync: false)!
|
||||
source_file.copy(dest: self.binary_path, rsync: false)!
|
||||
|
||||
console.print_header('osirisrunner built successfully at ${cfg.binary_path}')
|
||||
console.print_header('osirisrunner built successfully at ${self.binary_path}')
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut server := get()!
|
||||
server.stop()!
|
||||
fn (mut self Osirisrunner) destroy() ! {
|
||||
self.stop()!
|
||||
|
||||
osal.process_kill_recursive(name: 'runner_osiris')!
|
||||
|
||||
// Remove the built binary
|
||||
osal.rm(server.binary_path)!
|
||||
osal.rm(self.binary_path)!
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
osirisrunner_global map[string]&OsirisrunnerServer
|
||||
osirisrunner_global map[string]&Osirisrunner
|
||||
osirisrunner_default string
|
||||
)
|
||||
|
||||
@@ -26,8 +26,8 @@ pub mut:
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&OsirisrunnerServer {
|
||||
mut obj := OsirisrunnerServer{
|
||||
pub fn new(args ArgsGet) !&Osirisrunner {
|
||||
mut obj := Osirisrunner{
|
||||
name: args.name
|
||||
binary_path: args.binary_path
|
||||
redis_addr: args.redis_addr
|
||||
@@ -38,7 +38,7 @@ pub fn new(args ArgsGet) !&OsirisrunnerServer {
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&OsirisrunnerServer {
|
||||
pub fn get(args ArgsGet) !&Osirisrunner {
|
||||
mut context := base.context()!
|
||||
osirisrunner_default = args.name
|
||||
if args.fromdb || args.name !in osirisrunner_global {
|
||||
@@ -47,16 +47,16 @@ pub fn get(args ArgsGet) !&OsirisrunnerServer {
|
||||
data := r.hget('context:osirisrunner', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('OsirisrunnerServer with name: ${args.name} does not exist, prob bug.')
|
||||
return error('Osirisrunner with name: ${args.name} does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(OsirisrunnerServer, data)!
|
||||
mut obj := json.decode(Osirisrunner, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("OsirisrunnerServer with name '${args.name}' does not exist")
|
||||
return error("Osirisrunner with name '${args.name}' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
@@ -68,7 +68,7 @@ pub fn get(args ArgsGet) !&OsirisrunnerServer {
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o OsirisrunnerServer) ! {
|
||||
pub fn set(o Osirisrunner) ! {
|
||||
mut o2 := set_in_mem(o)!
|
||||
osirisrunner_default = o2.name
|
||||
mut context := base.context()!
|
||||
@@ -96,12 +96,12 @@ pub mut:
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&OsirisrunnerServer {
|
||||
mut res := []&OsirisrunnerServer{}
|
||||
pub fn list(args ArgsList) ![]&Osirisrunner {
|
||||
mut res := []&Osirisrunner{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
osirisrunner_global = map[string]&OsirisrunnerServer{}
|
||||
osirisrunner_global = map[string]&Osirisrunner{}
|
||||
osirisrunner_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
@@ -122,7 +122,7 @@ pub fn list(args ArgsList) ![]&OsirisrunnerServer {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o OsirisrunnerServer) !OsirisrunnerServer {
|
||||
fn set_in_mem(o Osirisrunner) !Osirisrunner {
|
||||
mut o2 := obj_init(o)!
|
||||
osirisrunner_global[o2.name] = &o2
|
||||
osirisrunner_default = o2.name
|
||||
@@ -146,17 +146,25 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
mut osirisrunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${osirisrunner_obj}')
|
||||
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action osirisrunner.destroy')
|
||||
destroy()!
|
||||
osirisrunner_obj.destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action osirisrunner.install')
|
||||
install()!
|
||||
osirisrunner_obj.install(reset: reset)!
|
||||
}
|
||||
if other_action.name == 'build' {
|
||||
console.print_debug('install action osirisrunner.build')
|
||||
osirisrunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut osirisrunner_obj := get(name: name)!
|
||||
@@ -165,7 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.stop()!
|
||||
@@ -174,6 +181,22 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.restart()!
|
||||
}
|
||||
if other_action.name == 'start_pre' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.start_pre()!
|
||||
}
|
||||
if other_action.name == 'start_post' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.start_post()!
|
||||
}
|
||||
if other_action.name == 'stop_pre' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.stop_pre()!
|
||||
}
|
||||
if other_action.name == 'stop_post' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@@ -210,12 +233,12 @@ fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.Sta
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self OsirisrunnerServer) reload() ! {
|
||||
pub fn (mut self Osirisrunner) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) start() ! {
|
||||
pub fn (mut self Osirisrunner) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
@@ -223,15 +246,13 @@ pub fn (mut self OsirisrunnerServer) start() ! {
|
||||
|
||||
console.print_header('installer: osirisrunner start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
if !self.installed()! {
|
||||
self.install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
self.start_pre()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: osirisrunner starting with ${zprocess.startuptype}...')
|
||||
@@ -241,7 +262,7 @@ pub fn (mut self OsirisrunnerServer) start() ! {
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
self.start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
@@ -252,33 +273,33 @@ pub fn (mut self OsirisrunnerServer) start() ! {
|
||||
return error('osirisrunner did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) install_start(args InstallArgs) ! {
|
||||
pub fn (mut self Osirisrunner) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) stop() ! {
|
||||
pub fn (mut self Osirisrunner) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.stop_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) restart() ! {
|
||||
pub fn (mut self Osirisrunner) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) running() !bool {
|
||||
pub fn (mut self Osirisrunner) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
@@ -287,31 +308,7 @@ pub fn (mut self OsirisrunnerServer) running() !bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self OsirisrunnerServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
// switch instance to be used for osirisrunner
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 OsirisrunnerServer {
|
||||
pub struct Osirisrunner {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_osiris')
|
||||
@@ -22,7 +22,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ OsirisrunnerServer) !OsirisrunnerServer {
|
||||
fn obj_init(mycfg_ Osirisrunner) !Osirisrunner {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'default'
|
||||
@@ -52,11 +52,11 @@ fn configure() ! {
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj OsirisrunnerServer) !string {
|
||||
return encoderhero.encode[OsirisrunnerServer](obj)!
|
||||
pub fn heroscript_dumps(obj Osirisrunner) !string {
|
||||
return encoderhero.encode[Osirisrunner](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !OsirisrunnerServer {
|
||||
mut obj := encoderhero.decode[OsirisrunnerServer](heroscript)!
|
||||
pub fn heroscript_loads(heroscript string) !Osirisrunner {
|
||||
mut obj := encoderhero.decode[Osirisrunner](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:''
|
||||
classname:'SalrunnerServer'
|
||||
classname:'Salrunner'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
|
||||
@@ -9,16 +9,15 @@ import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut cfg := get()!
|
||||
fn (self &Salrunner) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
res << startupmanager.ZProcessNewArgs{
|
||||
name: 'runner_sal'
|
||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr}'
|
||||
cmd: '${self.binary_path} --redis-addr ${self.redis_addr}'
|
||||
env: {
|
||||
'HOME': os.home_dir()
|
||||
'RUST_LOG': cfg.log_level
|
||||
'RUST_LOG': self.log_level
|
||||
'RUST_LOG_STYLE': 'never'
|
||||
}
|
||||
}
|
||||
@@ -26,33 +25,30 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut cfg := get()!
|
||||
fn (self &Salrunner) running_check() !bool {
|
||||
// Check if the process is running
|
||||
res := osal.exec(cmd: 'pgrep -f runner_sal', stdout: false, raise_error: false)!
|
||||
return res.exit_code == 0
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
fn (self &Salrunner) start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
fn (self &Salrunner) start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
fn (self &Salrunner) stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
fn (self &Salrunner) stop_post() ! {
|
||||
}
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
mut cfg := get()!
|
||||
|
||||
fn (self &Salrunner) installed() !bool {
|
||||
// Check if the binary exists
|
||||
mut binary := pathlib.get(cfg.binary_path)
|
||||
mut binary := pathlib.get(self.binary_path)
|
||||
if !binary.exists() {
|
||||
return false
|
||||
}
|
||||
@@ -70,17 +66,22 @@ fn ulist_get() !ulist.UList {
|
||||
fn upload() ! {
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install salrunner')
|
||||
// For salrunner, we build from source instead of downloading
|
||||
build()!
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
fn (mut self Salrunner) install(args InstallArgs) ! {
|
||||
console.print_header('install salrunner')
|
||||
// For salrunner, we build from source instead of downloading
|
||||
self.build()!
|
||||
}
|
||||
|
||||
fn (mut self Salrunner) build() ! {
|
||||
console.print_header('build salrunner')
|
||||
|
||||
mut cfg := get()!
|
||||
|
||||
// Ensure rust is installed
|
||||
console.print_debug('Checking if Rust is installed...')
|
||||
mut rust_installer := rust.get()!
|
||||
@@ -102,41 +103,40 @@ fn build() ! {
|
||||
)!
|
||||
|
||||
// Update the path to the actual cloned repo
|
||||
cfg.repo_path = repo.path()
|
||||
set(cfg)!
|
||||
console.print_debug('Repository path: ${cfg.repo_path}')
|
||||
self.repo_path = repo.path()
|
||||
set(self)!
|
||||
console.print_debug('Repository path: ${self.repo_path}')
|
||||
|
||||
// Build the salrunner binary from the horus workspace
|
||||
console.print_header('Building salrunner binary (this may take several minutes)...')
|
||||
console.print_debug('Running: cargo build -p runner-sal --release')
|
||||
console.print_debug('Build output:')
|
||||
|
||||
cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p runner-sal --release'
|
||||
cmd := 'cd ${self.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p runner-sal --release'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
console.print_debug('Build completed successfully')
|
||||
|
||||
// Ensure binary directory exists and copy the binary
|
||||
console.print_debug('Preparing binary directory: ${cfg.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(cfg.binary_path)
|
||||
console.print_debug('Preparing binary directory: ${self.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
|
||||
// Copy the built binary to the configured location
|
||||
source_binary := '${cfg.repo_path}/target/release/runner_sal'
|
||||
source_binary := '${self.repo_path}/target/release/runner_sal'
|
||||
console.print_debug('Copying binary from: ${source_binary}')
|
||||
console.print_debug('Copying binary to: ${cfg.binary_path}')
|
||||
console.print_debug('Copying binary to: ${self.binary_path}')
|
||||
mut source_file := pathlib.get_file(path: source_binary)!
|
||||
source_file.copy(dest: cfg.binary_path, rsync: false)!
|
||||
source_file.copy(dest: self.binary_path, rsync: false)!
|
||||
|
||||
console.print_header('salrunner built successfully at ${cfg.binary_path}')
|
||||
console.print_header('salrunner built successfully at ${self.binary_path}')
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut server := get()!
|
||||
server.stop()!
|
||||
fn (mut self Salrunner) destroy() ! {
|
||||
self.stop()!
|
||||
|
||||
osal.process_kill_recursive(name: 'runner_sal')!
|
||||
|
||||
// Remove the built binary
|
||||
osal.rm(server.binary_path)!
|
||||
osal.rm(self.binary_path)!
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
salrunner_global map[string]&SalrunnerServer
|
||||
salrunner_global map[string]&Salrunner
|
||||
salrunner_default string
|
||||
)
|
||||
|
||||
@@ -26,8 +26,8 @@ pub mut:
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&SalrunnerServer {
|
||||
mut obj := SalrunnerServer{
|
||||
pub fn new(args ArgsGet) !&Salrunner {
|
||||
mut obj := Salrunner{
|
||||
name: args.name
|
||||
binary_path: args.binary_path
|
||||
redis_addr: args.redis_addr
|
||||
@@ -38,7 +38,7 @@ pub fn new(args ArgsGet) !&SalrunnerServer {
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&SalrunnerServer {
|
||||
pub fn get(args ArgsGet) !&Salrunner {
|
||||
mut context := base.context()!
|
||||
salrunner_default = args.name
|
||||
if args.fromdb || args.name !in salrunner_global {
|
||||
@@ -47,16 +47,16 @@ pub fn get(args ArgsGet) !&SalrunnerServer {
|
||||
data := r.hget('context:salrunner', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('SalrunnerServer with name: ${args.name} does not exist, prob bug.')
|
||||
return error('Salrunner with name: ${args.name} does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(SalrunnerServer, data)!
|
||||
mut obj := json.decode(Salrunner, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("SalrunnerServer with name '${args.name}' does not exist")
|
||||
return error("Salrunner with name '${args.name}' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
@@ -68,7 +68,7 @@ pub fn get(args ArgsGet) !&SalrunnerServer {
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o SalrunnerServer) ! {
|
||||
pub fn set(o Salrunner) ! {
|
||||
mut o2 := set_in_mem(o)!
|
||||
salrunner_default = o2.name
|
||||
mut context := base.context()!
|
||||
@@ -96,12 +96,12 @@ pub mut:
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&SalrunnerServer {
|
||||
mut res := []&SalrunnerServer{}
|
||||
pub fn list(args ArgsList) ![]&Salrunner {
|
||||
mut res := []&Salrunner{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
salrunner_global = map[string]&SalrunnerServer{}
|
||||
salrunner_global = map[string]&Salrunner{}
|
||||
salrunner_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
@@ -122,7 +122,7 @@ pub fn list(args ArgsList) ![]&SalrunnerServer {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o SalrunnerServer) !SalrunnerServer {
|
||||
fn set_in_mem(o Salrunner) !Salrunner {
|
||||
mut o2 := obj_init(o)!
|
||||
salrunner_global[o2.name] = &o2
|
||||
salrunner_default = o2.name
|
||||
@@ -146,17 +146,25 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
mut salrunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${salrunner_obj}')
|
||||
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action salrunner.destroy')
|
||||
destroy()!
|
||||
salrunner_obj.destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action salrunner.install')
|
||||
install()!
|
||||
salrunner_obj.install(reset: reset)!
|
||||
}
|
||||
if other_action.name == 'build' {
|
||||
console.print_debug('install action salrunner.build')
|
||||
salrunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut salrunner_obj := get(name: name)!
|
||||
@@ -165,7 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.stop()!
|
||||
@@ -174,6 +181,22 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.restart()!
|
||||
}
|
||||
if other_action.name == 'start_pre' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.start_pre()!
|
||||
}
|
||||
if other_action.name == 'start_post' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.start_post()!
|
||||
}
|
||||
if other_action.name == 'stop_pre' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.stop_pre()!
|
||||
}
|
||||
if other_action.name == 'stop_post' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@@ -210,12 +233,12 @@ fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.Sta
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self SalrunnerServer) reload() ! {
|
||||
pub fn (mut self Salrunner) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) start() ! {
|
||||
pub fn (mut self Salrunner) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
@@ -223,15 +246,13 @@ pub fn (mut self SalrunnerServer) start() ! {
|
||||
|
||||
console.print_header('installer: salrunner start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
if !self.installed()! {
|
||||
self.install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
self.start_pre()!
|
||||
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: salrunner starting with ${zprocess.startuptype}...')
|
||||
@@ -241,7 +262,7 @@ pub fn (mut self SalrunnerServer) start() ! {
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
self.start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
@@ -252,33 +273,33 @@ pub fn (mut self SalrunnerServer) start() ! {
|
||||
return error('salrunner did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) install_start(args InstallArgs) ! {
|
||||
pub fn (mut self Salrunner) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) stop() ! {
|
||||
pub fn (mut self Salrunner) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.stop_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) restart() ! {
|
||||
pub fn (mut self Salrunner) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) running() !bool {
|
||||
pub fn (mut self Salrunner) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
@@ -287,31 +308,7 @@ pub fn (mut self SalrunnerServer) running() !bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self SalrunnerServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
// switch instance to be used for salrunner
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 SalrunnerServer {
|
||||
pub struct Salrunner {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_sal')
|
||||
@@ -22,7 +22,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ SalrunnerServer) !SalrunnerServer {
|
||||
fn obj_init(mycfg_ Salrunner) !Salrunner {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'default'
|
||||
@@ -52,11 +52,11 @@ fn configure() ! {
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj SalrunnerServer) !string {
|
||||
return encoderhero.encode[SalrunnerServer](obj)!
|
||||
pub fn heroscript_dumps(obj Salrunner) !string {
|
||||
return encoderhero.encode[Salrunner](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !SalrunnerServer {
|
||||
mut obj := encoderhero.decode[SalrunnerServer](heroscript)!
|
||||
pub fn heroscript_loads(heroscript string) !Salrunner {
|
||||
mut obj := encoderhero.decode[Salrunner](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
!!hero_code.generate_installer
|
||||
name:''
|
||||
classname:'SupervisorServer'
|
||||
classname:'Supervisor'
|
||||
singleton:0
|
||||
templates:1
|
||||
default:1
|
||||
|
||||
@@ -10,16 +10,15 @@ import incubaid.herolib.installers.lang.rust
|
||||
import incubaid.herolib.develop.gittools
|
||||
import os
|
||||
|
||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut cfg := get()!
|
||||
fn (self &Supervisor) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
res << startupmanager.ZProcessNewArgs{
|
||||
name: 'supervisor'
|
||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr} --api-http-port ${cfg.http_port} --api-ws-port ${cfg.ws_port}'
|
||||
cmd: '${self.binary_path} --redis-addr ${self.redis_addr} --api-http-port ${self.http_port} --api-ws-port ${self.ws_port}'
|
||||
env: {
|
||||
'HOME': os.home_dir()
|
||||
'RUST_LOG': cfg.log_level
|
||||
'RUST_LOG': self.log_level
|
||||
'RUST_LOG_STYLE': 'never'
|
||||
}
|
||||
}
|
||||
@@ -27,33 +26,30 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut cfg := get()!
|
||||
fn (self &Supervisor) running_check() !bool {
|
||||
// Check if the process is running by checking the HTTP port
|
||||
res := osal.exec(cmd: 'curl -fsSL http://127.0.0.1:${cfg.http_port} || exit 1', stdout: false, raise_error: false)!
|
||||
res := osal.exec(cmd: 'curl -fsSL http://127.0.0.1:${self.http_port} || exit 1', stdout: false, raise_error: false)!
|
||||
return res.exit_code == 0
|
||||
}
|
||||
|
||||
fn start_pre() ! {
|
||||
fn (self &Supervisor) start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post() ! {
|
||||
fn (self &Supervisor) start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre() ! {
|
||||
fn (self &Supervisor) stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post() ! {
|
||||
fn (self &Supervisor) stop_post() ! {
|
||||
}
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
mut cfg := get()!
|
||||
|
||||
fn (self &Supervisor) installed() !bool {
|
||||
// Check if the binary exists
|
||||
mut binary := pathlib.get(cfg.binary_path)
|
||||
mut binary := pathlib.get(self.binary_path)
|
||||
if !binary.exists() {
|
||||
return false
|
||||
}
|
||||
@@ -75,10 +71,17 @@ fn upload() ! {
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn (mut self Supervisor) install(args InstallArgs) ! {
|
||||
console.print_header('install supervisor')
|
||||
// For supervisor, we build from source instead of downloading
|
||||
build()!
|
||||
self.build()!
|
||||
}
|
||||
|
||||
// Public function to build supervisor without requiring factory/redis
|
||||
@@ -88,7 +91,7 @@ pub fn build_supervisor() ! {
|
||||
|
||||
// Use default config instead of getting from factory
|
||||
println('⚙️ Initializing configuration...')
|
||||
mut cfg := SupervisorServer{}
|
||||
mut cfg := Supervisor{}
|
||||
println('✅ Configuration initialized')
|
||||
println(' - Binary path: ${cfg.binary_path}')
|
||||
println(' - Redis address: ${cfg.redis_addr}')
|
||||
@@ -171,11 +174,9 @@ pub fn build_supervisor() ! {
|
||||
println('📍 Binary location: ${cfg.binary_path}')
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
fn (mut self Supervisor) build() ! {
|
||||
console.print_header('build supervisor')
|
||||
|
||||
mut cfg := get()!
|
||||
|
||||
// Ensure Redis is installed and running (required for supervisor)
|
||||
console.print_debug('Checking if Redis is installed and running...')
|
||||
redis_check := osal.exec(cmd: 'redis-cli -c -p 6379 ping', stdout: false, raise_error: false)!
|
||||
@@ -213,41 +214,40 @@ fn build() ! {
|
||||
)!
|
||||
|
||||
// Update the path to the actual cloned repo
|
||||
cfg.repo_path = repo.path()
|
||||
set(cfg)!
|
||||
console.print_debug('Repository path: ${cfg.repo_path}')
|
||||
self.repo_path = repo.path()
|
||||
set(self)!
|
||||
console.print_debug('Repository path: ${self.repo_path}')
|
||||
|
||||
// Build the supervisor binary from the horus workspace
|
||||
console.print_header('Building supervisor binary (this may take several minutes)...')
|
||||
console.print_debug('Running: cargo build -p hero-supervisor --release')
|
||||
console.print_debug('Build output:')
|
||||
|
||||
cmd := 'cd ${cfg.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-supervisor --release'
|
||||
cmd := 'cd ${self.repo_path} && . ~/.cargo/env && RUSTFLAGS="-A warnings" cargo build -p hero-supervisor --release'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
console.print_debug('Build completed successfully')
|
||||
|
||||
// Ensure binary directory exists and copy the binary
|
||||
console.print_debug('Preparing binary directory: ${cfg.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(cfg.binary_path)
|
||||
console.print_debug('Preparing binary directory: ${self.binary_path}')
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
|
||||
// Copy the built binary to the configured location
|
||||
source_binary := '${cfg.repo_path}/target/release/supervisor'
|
||||
source_binary := '${self.repo_path}/target/release/supervisor'
|
||||
console.print_debug('Copying binary from: ${source_binary}')
|
||||
console.print_debug('Copying binary to: ${cfg.binary_path}')
|
||||
console.print_debug('Copying binary to: ${self.binary_path}')
|
||||
mut source_file := pathlib.get_file(path: source_binary)!
|
||||
source_file.copy(dest: cfg.binary_path, rsync: false)!
|
||||
source_file.copy(dest: self.binary_path, rsync: false)!
|
||||
|
||||
console.print_header('supervisor built successfully at ${cfg.binary_path}')
|
||||
console.print_header('supervisor built successfully at ${self.binary_path}')
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
mut server := get()!
|
||||
server.stop()!
|
||||
fn (mut self Supervisor) destroy() ! {
|
||||
self.stop()!
|
||||
|
||||
osal.process_kill_recursive(name: 'supervisor')!
|
||||
|
||||
// Remove the built binary
|
||||
osal.rm(server.binary_path)!
|
||||
osal.rm(self.binary_path)!
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import incubaid.herolib.osal.startupmanager
|
||||
import time
|
||||
|
||||
__global (
|
||||
supervisor_global map[string]&SupervisorServer
|
||||
supervisor_global map[string]&Supervisor
|
||||
supervisor_default string
|
||||
)
|
||||
|
||||
@@ -28,8 +28,8 @@ pub mut:
|
||||
create bool // default will not create if not exist
|
||||
}
|
||||
|
||||
pub fn new(args ArgsGet) !&SupervisorServer {
|
||||
mut obj := SupervisorServer{
|
||||
pub fn new(args ArgsGet) !&Supervisor {
|
||||
mut obj := Supervisor{
|
||||
name: args.name
|
||||
binary_path: args.binary_path
|
||||
redis_addr: args.redis_addr
|
||||
@@ -42,7 +42,7 @@ pub fn new(args ArgsGet) !&SupervisorServer {
|
||||
return get(name: args.name)!
|
||||
}
|
||||
|
||||
pub fn get(args ArgsGet) !&SupervisorServer {
|
||||
pub fn get(args ArgsGet) !&Supervisor {
|
||||
mut context := base.context()!
|
||||
supervisor_default = args.name
|
||||
if args.fromdb || args.name !in supervisor_global {
|
||||
@@ -51,16 +51,16 @@ pub fn get(args ArgsGet) !&SupervisorServer {
|
||||
data := r.hget('context:supervisor', args.name)!
|
||||
if data.len == 0 {
|
||||
print_backtrace()
|
||||
return error('SupervisorServer with name: ${args.name} does not exist, prob bug.')
|
||||
return error('Supervisor with name: ${args.name} does not exist, prob bug.')
|
||||
}
|
||||
mut obj := json.decode(SupervisorServer, data)!
|
||||
mut obj := json.decode(Supervisor, data)!
|
||||
set_in_mem(obj)!
|
||||
} else {
|
||||
if args.create {
|
||||
new(args)!
|
||||
} else {
|
||||
print_backtrace()
|
||||
return error("SupervisorServer with name '${args.name}' does not exist")
|
||||
return error("Supervisor with name '${args.name}' does not exist")
|
||||
}
|
||||
}
|
||||
return get(name: args.name)! // no longer from db nor create
|
||||
@@ -72,7 +72,7 @@ pub fn get(args ArgsGet) !&SupervisorServer {
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o SupervisorServer) ! {
|
||||
pub fn set(o Supervisor) ! {
|
||||
mut o2 := set_in_mem(o)!
|
||||
supervisor_default = o2.name
|
||||
mut context := base.context()!
|
||||
@@ -100,12 +100,12 @@ pub mut:
|
||||
}
|
||||
|
||||
// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
|
||||
pub fn list(args ArgsList) ![]&SupervisorServer {
|
||||
mut res := []&SupervisorServer{}
|
||||
pub fn list(args ArgsList) ![]&Supervisor {
|
||||
mut res := []&Supervisor{}
|
||||
mut context := base.context()!
|
||||
if args.fromdb {
|
||||
// reset what is in mem
|
||||
supervisor_global = map[string]&SupervisorServer{}
|
||||
supervisor_global = map[string]&Supervisor{}
|
||||
supervisor_default = ''
|
||||
}
|
||||
if args.fromdb {
|
||||
@@ -126,7 +126,7 @@ pub fn list(args ArgsList) ![]&SupervisorServer {
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o SupervisorServer) !SupervisorServer {
|
||||
fn set_in_mem(o Supervisor) !Supervisor {
|
||||
mut o2 := obj_init(o)!
|
||||
supervisor_global[o2.name] = &o2
|
||||
supervisor_default = o2.name
|
||||
@@ -150,17 +150,25 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
mut supervisor_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${supervisor_obj}')
|
||||
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action supervisor.destroy')
|
||||
destroy()!
|
||||
supervisor_obj.destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action supervisor.install')
|
||||
install()!
|
||||
supervisor_obj.install(reset: reset)!
|
||||
}
|
||||
if other_action.name == 'build' {
|
||||
console.print_debug('install action supervisor.build')
|
||||
supervisor_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut supervisor_obj := get(name: name)!
|
||||
@@ -169,7 +177,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.stop()!
|
||||
@@ -178,6 +185,22 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.restart()!
|
||||
}
|
||||
if other_action.name == 'start_pre' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.start_pre()!
|
||||
}
|
||||
if other_action.name == 'start_post' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.start_post()!
|
||||
}
|
||||
if other_action.name == 'stop_pre' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.stop_pre()!
|
||||
}
|
||||
if other_action.name == 'stop_post' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@@ -214,12 +237,12 @@ fn startupmanager_get(cat startupmanager.StartupManagerType) !startupmanager.Sta
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self SupervisorServer) reload() ! {
|
||||
pub fn (mut self Supervisor) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) start() ! {
|
||||
pub fn (mut self Supervisor) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
@@ -227,17 +250,19 @@ pub fn (mut self SupervisorServer) start() ! {
|
||||
|
||||
console.print_header('installer: supervisor start')
|
||||
|
||||
if !installed()! {
|
||||
install()!
|
||||
if !self.installed()! {
|
||||
self.install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
self.configure()!
|
||||
|
||||
start_pre()!
|
||||
self.start_pre()!
|
||||
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
println('debugzo ${sm}')
|
||||
|
||||
console.print_debug('installer: supervisor starting with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
@@ -245,7 +270,7 @@ pub fn (mut self SupervisorServer) start() ! {
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
self.start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
@@ -256,33 +281,33 @@ pub fn (mut self SupervisorServer) start() ! {
|
||||
return error('supervisor did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) install_start(args InstallArgs) ! {
|
||||
pub fn (mut self Supervisor) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) stop() ! {
|
||||
pub fn (mut self Supervisor) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()! {
|
||||
self.stop_pre()!
|
||||
for zprocess in self.startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) restart() ! {
|
||||
pub fn (mut self Supervisor) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) running() !bool {
|
||||
pub fn (mut self Supervisor) running() !bool {
|
||||
switch(self.name)
|
||||
|
||||
// walk over the generic processes, if not running return
|
||||
for zprocess in startupcmd()! {
|
||||
for zprocess in self.startupcmd()! {
|
||||
if zprocess.startuptype != .screen {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
r := sm.running(zprocess.name)!
|
||||
@@ -291,32 +316,9 @@ pub fn (mut self SupervisorServer) running() !bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self SupervisorServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for supervisor
|
||||
pub fn switch(name string) {
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 SupervisorServer {
|
||||
pub struct Supervisor {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
binary_path string = os.join_path(os.home_dir(), 'hero/bin/supervisor')
|
||||
@@ -24,7 +24,7 @@ pub mut:
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ SupervisorServer) !SupervisorServer {
|
||||
fn obj_init(mycfg_ Supervisor) !Supervisor {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.name == '' {
|
||||
mycfg.name = 'default'
|
||||
@@ -45,26 +45,25 @@ fn obj_init(mycfg_ SupervisorServer) !SupervisorServer {
|
||||
mycfg.log_level = 'info'
|
||||
}
|
||||
if mycfg.repo_path == '' {
|
||||
mycfg.repo_path = '/root/code/git.ourworld.tf/herocode/horus'
|
||||
mycfg.repo_path = os.join_path(os.home_dir(), 'code/git.ourworld.tf/herocode/horus')
|
||||
}
|
||||
return mycfg
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
mut server := get()!
|
||||
fn (self &Supervisor) configure() ! {
|
||||
// Ensure the binary directory exists
|
||||
mut binary_path_obj := pathlib.get(server.binary_path)
|
||||
mut binary_path_obj := pathlib.get(self.binary_path)
|
||||
osal.dir_ensure(binary_path_obj.path_dir())!
|
||||
}
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj SupervisorServer) !string {
|
||||
return encoderhero.encode[SupervisorServer](obj)!
|
||||
pub fn heroscript_dumps(obj Supervisor) !string {
|
||||
return encoderhero.encode[Supervisor](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !SupervisorServer {
|
||||
mut obj := encoderhero.decode[SupervisorServer](heroscript)!
|
||||
pub fn heroscript_loads(heroscript string) !Supervisor {
|
||||
mut obj := encoderhero.decode[Supervisor](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ pub fn get(cat StartupManagerType) !StartupManager {
|
||||
match sm.cat {
|
||||
.zinit {
|
||||
mut zinit_client_test := zinit.get(create: true)! // 'create:true' ensures a client object is initiated even if the socket isn't active.
|
||||
|
||||
if _ := zinit_client_test.rpc_discover() {
|
||||
sm.cat = .zinit
|
||||
} else {
|
||||
|
||||
@@ -33,7 +33,8 @@ pub fn (mut t UnixSocketTransport) send(request string, params SendParams) !stri
|
||||
// Close the socket explicitly
|
||||
unix.shutdown(socket.sock.handle)
|
||||
socket.close() or {}
|
||||
console.print_debug('The server closed the socket, check if closed') // We should debug this
|
||||
// print_backtrace()
|
||||
console.print_debug('The server did not close the socket, we did timeout or there was other error.')
|
||||
}
|
||||
|
||||
// Set timeout if specified
|
||||
|
||||
Reference in New Issue
Block a user