feat: add dynamic Redis configuration to coordinator installer
- Add redis_port field to CoordinatorServer struct - Refactor ensure_redis_running() to use @[params] pattern - Pass redis_port and redis_addr dynamically from config - Follow same pattern as cryptpad installer for consistency
This commit is contained in:
Binary file not shown.
@@ -8,6 +8,7 @@ import incubaid.herolib.installers.ulist
|
|||||||
import incubaid.herolib.installers.lang.rust
|
import incubaid.herolib.installers.lang.rust
|
||||||
import incubaid.herolib.installers.base.redis
|
import incubaid.herolib.installers.base.redis
|
||||||
import incubaid.herolib.develop.gittools
|
import incubaid.herolib.develop.gittools
|
||||||
|
import os
|
||||||
|
|
||||||
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||||
mut cfg := get()!
|
mut cfg := get()!
|
||||||
@@ -17,6 +18,7 @@ fn startupcmd() ![]startupmanager.ZProcessNewArgs {
|
|||||||
name: 'coordinator'
|
name: 'coordinator'
|
||||||
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr} --api-http-port ${cfg.http_port} --api-ws-port ${cfg.ws_port}'
|
cmd: '${cfg.binary_path} --redis-addr ${cfg.redis_addr} --api-http-port ${cfg.http_port} --api-ws-port ${cfg.ws_port}'
|
||||||
env: {
|
env: {
|
||||||
|
'HOME': os.home_dir()
|
||||||
'RUST_LOG': cfg.log_level
|
'RUST_LOG': cfg.log_level
|
||||||
'RUST_LOG_STYLE': 'never'
|
'RUST_LOG_STYLE': 'never'
|
||||||
}
|
}
|
||||||
@@ -79,18 +81,26 @@ fn upload() ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to ensure Redis is installed and running
|
// Helper function to ensure Redis is installed and running
|
||||||
fn ensure_redis_running() ! {
|
@[params]
|
||||||
|
struct EnsureRedisArgs {
|
||||||
|
pub mut:
|
||||||
|
redis_port int = 6379
|
||||||
|
redis_addr string = 'localhost'
|
||||||
|
datadir string = '/var/lib/redis'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensure_redis_running(args EnsureRedisArgs) ! {
|
||||||
redis_config := redis.RedisInstall{
|
redis_config := redis.RedisInstall{
|
||||||
port: 6379
|
port: args.redis_port
|
||||||
datadir: '/var/lib/redis'
|
datadir: args.datadir
|
||||||
ipaddr: 'localhost'
|
ipaddr: args.redis_addr
|
||||||
}
|
}
|
||||||
|
|
||||||
if !redis.check(redis_config) {
|
if !redis.check(redis_config) {
|
||||||
println('Installing and starting Redis...')
|
println('Installing and starting Redis on ${args.redis_addr}:${args.redis_port}...')
|
||||||
redis.redis_install(redis_config)!
|
redis.redis_install(redis_config)!
|
||||||
} else {
|
} else {
|
||||||
println('Redis is already running')
|
println('Redis is already running on ${args.redis_addr}:${args.redis_port}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +132,10 @@ pub fn build() ! {
|
|||||||
|
|
||||||
// Ensure Redis is installed and running (required for coordinator)
|
// Ensure Redis is installed and running (required for coordinator)
|
||||||
println('Step 1/4: Checking Redis dependency...')
|
println('Step 1/4: Checking Redis dependency...')
|
||||||
ensure_redis_running()!
|
// Parse redis_addr to extract host
|
||||||
|
parts := cfg.redis_addr.split(':')
|
||||||
|
redis_host := if parts.len > 0 { parts[0] } else { 'localhost' }
|
||||||
|
ensure_redis_running(redis_port: cfg.redis_port, redis_addr: redis_host)!
|
||||||
println('Redis is ready\n')
|
println('Redis is ready\n')
|
||||||
|
|
||||||
// Ensure rust is installed
|
// Ensure rust is installed
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub mut:
|
|||||||
name string = 'default'
|
name string = 'default'
|
||||||
binary_path string = '/hero/var/bin/coordinator'
|
binary_path string = '/hero/var/bin/coordinator'
|
||||||
redis_addr string = '127.0.0.1:6379'
|
redis_addr string = '127.0.0.1:6379'
|
||||||
|
redis_port int = 6379
|
||||||
http_port int = 8081
|
http_port int = 8081
|
||||||
ws_port int = 9653
|
ws_port int = 9653
|
||||||
log_level string = 'info'
|
log_level string = 'info'
|
||||||
@@ -36,6 +37,9 @@ fn obj_init(mycfg_ CoordinatorServer) !CoordinatorServer {
|
|||||||
if mycfg.redis_addr == '' {
|
if mycfg.redis_addr == '' {
|
||||||
mycfg.redis_addr = '127.0.0.1:6379'
|
mycfg.redis_addr = '127.0.0.1:6379'
|
||||||
}
|
}
|
||||||
|
if mycfg.redis_port == 0 {
|
||||||
|
mycfg.redis_port = 6379
|
||||||
|
}
|
||||||
if mycfg.http_port == 0 {
|
if mycfg.http_port == 0 {
|
||||||
mycfg.http_port = 8081
|
mycfg.http_port = 8081
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user