Skip to content

installers.horus.coordinator #

Coordinator Installer

A V language installer module for building and managing the Coordinator service. This installer handles the complete lifecycle of the Coordinator binary from the Horus workspace.

Features

  • Automatic Rust Installation: Installs Rust toolchain if not present
  • Git Repository Management: Clones and manages the horus repository
  • Binary Building: Compiles the coordinator binary from the horus workspace
  • Service Management: Start/stop/restart via zinit
  • Configuration: Customizable Redis, HTTP, and WebSocket ports

Quick Start

Using the Example Script

cd /root/code/github/incubaid/herolib/examples/installers/horus
./coordinator.vsh

Manual Usage

import incubaid.herolib.installers.horus.coordinator as coordinator_installer

mut coordinator := coordinator_installer.get()!
coordinator.install()!
coordinator.start()!

Configuration

!!coordinator.configure
    name:'default'
    binary_path:'/hero/var/bin/coordinator'
    redis_addr:'127.0.0.1:6379'
    redis_port:6379
    http_port:8081
    ws_port:9653
    log_level:'info'
    repo_path:'/root/code/git.ourworld.tf/herocode/horus'

Configuration Fields

  • name: Instance name (default: 'default')
  • binary_path: Path where the coordinator binary will be installed (default: '/hero/var/bin/coordinator')
  • redis_addr: Redis server address (default: '127.0.0.1:6379')
  • redis_port: Redis server port (default: 6379)
  • http_port: HTTP API port (default: 8081)
  • ws_port: WebSocket API port (default: 9653)
  • log_level: Rust log level - trace, debug, info, warn, error (default: 'info')
  • repo_path: Path to clone the horus repository (default: '/root/code/git.ourworld.tf/herocode/horus')

Commands

Install

Builds the coordinator binary from the horus workspace. This will:1. Check if Rust is installed (installs if not present)2. Clone the horus repository from git.ourworld.tf3. Build the coordinator binary with cargo build -p hero-coordinator --release

Note: The installer skips the build if the binary already exists at the configured path.

hero coordinator.install

Force Reinstall

To force a rebuild even if the binary already exists, use the reset flag:

import incubaid.herolib.installers.horus.coordinator as coordinator_installer

mut coordinator := coordinator_installer.get()!
coordinator.install(reset: true)!  // Force reinstall

Or manually delete the binary before running install:

rm /hero/var/bin/coordinator
hero coordinator.install

Start

Starts the coordinator service using zinit:

hero coordinator.start

Stop

Stops the running service:

hero coordinator.stop

Restart

Restarts the service:

hero coordinator.restart

Destroy

Stops the service and removes all files:

hero coordinator.destroy

Requirements

  • Dependencies:
  • Rust toolchain (automatically installed if not present)
  • Git (for cloning repository)
  • Redis (must be pre-installed and running)
  • Mycelium (must be installed and running separately)

Architecture

The installer follows the standard herolib installer pattern:

  • coordinator_model.v: Configuration structure and initialization
  • coordinator_actions.v: Build, install, start, stop, destroy logic
  • coordinator_factory_.v: Factory pattern for instance management

Notes

  • The installer builds from source rather than downloading pre-built binaries
  • Redis must be pre-installed and running - the installer does not install Redis
  • The installer checks if the binary already exists and skips rebuild unless reset: true is used
  • Rust is automatically installed if not present (checks for rustc command)
  • The binary is built with RUSTFLAGS="-A warnings" to suppress warnings
  • Service management uses zinit by default

Example Workflow

import incubaid.herolib.installers.horus.coordinator as hc

// Get installer instance
mut coordinator := hc.get()!

// Customize configuration
coordinator.redis_addr = '127.0.0.1:6379'
coordinator.redis_port = 6379
coordinator.http_port = 8081
coordinator.log_level = 'debug'
hc.set(coordinator)!

// Build and start
coordinator.install()!
coordinator.start()!

// Check status
if coordinator.running()! {
    println('Coordinator is running on port ${coordinator.http_port}')
}

// Later: cleanup
coordinator.destroy()!

fn build_coordinator #

fn build_coordinator() !

Public function to build coordinator without requiring factory/redis

fn delete #

fn delete(args ArgsGet) !

fn exists #

fn exists(args ArgsGet) !bool

does the config exists?

fn get #

fn get(args ArgsGet) !&Coordinator

fn heroscript_dumps #

fn heroscript_dumps(obj Coordinator) !string

///////////NORMALLY NO NEED TO TOUCH

fn heroscript_loads #

fn heroscript_loads(heroscript string) !Coordinator

fn list #

fn list(args ArgsList) ![]&Coordinator

if fromdb set: load from filesystem, and not from mem, will also reset what is in mem

fn new #

fn new(args ArgsGet) !&Coordinator

fn play #

fn play(mut plbook PlayBook) !

fn set #

fn set(o Coordinator) !

register the config for the future

fn switch #

fn switch(name string)

switch instance to be used for coordinator

struct ArgsGet #

@[params]
struct ArgsGet {
pub mut:
	name        string = 'default'
	binary_path string
	redis_addr  string
	http_port   int
	ws_port     int
	log_level   string
	repo_path   string
	fromdb      bool // will load from filesystem
	create      bool // default will not create if not exist
}

///////FACTORY

struct ArgsList #

@[params]
struct ArgsList {
pub mut:
	fromdb bool // will load from filesystem
}

struct Coordinator #

@[heap]
struct Coordinator {
pub mut:
	name        string = 'default'
	binary_path string = os.join_path(os.home_dir(), 'hero/bin/coordinator')
	redis_addr  string = '127.0.0.1:6379'
	http_port   int    = 8081
	ws_port     int    = 9653
	log_level   string = 'info'
	repo_path   string = '/root/code/git.ourworld.tf/herocode/horus'
}

THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED

fn (Coordinator) install_start #

fn (mut self Coordinator) install_start(args InstallArgs) !

fn (Coordinator) reload #

fn (mut self Coordinator) reload() !

load from disk and make sure is properly intialized

fn (Coordinator) restart #

fn (mut self Coordinator) restart(args StartArgs) !

fn (Coordinator) running #

fn (mut self Coordinator) running() !bool

fn (Coordinator) start #

fn (mut self Coordinator) start(args StartArgs) !

fn (Coordinator) stop #

fn (mut self Coordinator) stop() !

struct InstallArgs #

@[params]
struct InstallArgs {
pub mut:
	reset bool
}

struct StartArgs #

@[params]
struct StartArgs {
pub mut:
	reset bool
}