Merge branch 'development_nile_installers' into development_fix_zinit

This commit is contained in:
Timur Gordon
2025-11-20 07:56:48 +01:00
committed by GitHub
13 changed files with 103 additions and 129 deletions

View File

@@ -20,8 +20,7 @@ import incubaid.herolib.installers.lang.python
import os
@if args.startupmanager
fn startupcmd () ![]startupmanager.ZProcessNewArgs{
mut installer := get()!
fn (self &${args.classname}) startupcmd() ![]startupmanager.ZProcessNewArgs {
mut res := []startupmanager.ZProcessNewArgs{}
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res << startupmanager.ZProcessNewArgs{
@@ -36,8 +35,7 @@ fn startupcmd () ![]startupmanager.ZProcessNewArgs{
}
fn running() !bool {
mut installer := get()!
fn (self &${args.classname}) running_check() !bool {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// this checks health of ${args.name}
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
@@ -58,19 +56,19 @@ fn running() !bool {
return false
}
fn start_pre()!{
fn (self &${args.classname}) start_pre() ! {
}
fn start_post()!{
fn (self &${args.classname}) start_post() ! {
}
fn stop_pre()!{
fn (self &${args.classname}) stop_pre() ! {
}
fn stop_post()!{
fn (self &${args.classname}) stop_post() ! {
}
@@ -80,7 +78,7 @@ fn stop_post()!{
@if args.cat == .installer
// checks if a certain version or above is installed
fn installed() !bool {
fn (self &${args.classname}) installed() !bool {
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// res := os.execute('??{osal.profile_path_source_and()!} ${args.name} version')
// if res.exit_code != 0 {
@@ -111,7 +109,14 @@ fn upload() ! {
}
fn install() ! {
^^[params]
pub struct InstallArgs {
pub mut:
reset bool
}
fn (mut self ${args.classname}) install(args InstallArgs) ! {
console.print_header('install ${args.name}')
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
// mut url := ''
@@ -143,7 +148,7 @@ fn install() ! {
}
@if args.build
fn build() ! {
fn (mut self ${args.classname}) build() ! {
//url := 'https://github.com/threefoldtech/${args.name}'
// make sure we install base on the node
@@ -174,7 +179,8 @@ fn build() ! {
}
@end
fn destroy() ! {
fn (mut self ${args.classname}) destroy() ! {
self.stop()!
// mut systemdfactory := systemd.new()!
// systemdfactory.destroy("zinit")!

View File

@@ -169,29 +169,34 @@ pub fn play(mut plbook PlayBook) ! {
@if args.cat == .installer
mut other_actions := plbook.find(filter: '${args.name}.')!
for mut other_action in other_actions {
@if args.startupmanager
if other_action.name in ["destroy","install","build","start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
@else
if other_action.name in ["destroy","install","build"]{
@end
mut p := other_action.params
name := p.get_default('name', 'default')!
reset:=p.get_default_false("reset")
mut ${args.name}_obj:=get(name:name)!
console.print_debug("action object:\n??{${args.name}_obj}")
if other_action.name == "destroy" || reset{
console.print_debug("install action ${args.name}.destroy")
destroy()!
${args.name}_obj.destroy()!
}
if other_action.name == "install"{
console.print_debug("install action ${args.name}.install")
install()!
}
}
@if args.startupmanager
if other_action.name in ["start","stop","restart"]{
mut p := other_action.params
name := p.get('name')!
mut ${args.name}_obj:=get(name:name)!
console.print_debug("action object:\n??{${args.name}_obj}")
${args.name}_obj.install(reset: reset)!
}
if other_action.name == "build"{
console.print_debug("install action ${args.name}.build")
${args.name}_obj.build()!
}
@if args.startupmanager
if other_action.name == "start"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.start()!
}
if other_action.name == "stop"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.stop()!
@@ -200,8 +205,24 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.restart()!
}
if other_action.name == "start_pre"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.start_pre()!
}
if other_action.name == "start_post"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.start_post()!
}
if other_action.name == "stop_pre"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.stop_pre()!
}
if other_action.name == "stop_post"{
console.print_debug("install action ${args.name}.??{other_action.name}")
${args.name}_obj.stop_post()!
}
@end
}
@end
other_action.done = true
}
@end
@@ -262,15 +283,13 @@ pub fn (mut self ${args.classname}) start() ! {
console.print_header('installer: ${args.name} 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: ${args.name} starting with ??{zprocess.startuptype}...')
@@ -280,7 +299,7 @@ pub fn (mut self ${args.classname}) start() ! {
sm.start(zprocess.name)!
}
start_post()!
self.start_post()!
for _ in 0 .. 50 {
if self.running()! {
@@ -300,12 +319,12 @@ pub fn (mut self ${args.classname}) install_start(args InstallArgs) ! {
pub fn (mut self ${args.classname}) 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 ${args.classname}) restart() ! {
@@ -318,7 +337,7 @@ pub fn (mut self ${args.classname}) 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)!
@@ -327,37 +346,10 @@ pub fn (mut self ${args.classname}) running() !bool {
}
}
}
return running()!
return self.running_check()!
}
@end
@@[params]
pub struct InstallArgs{
pub mut:
reset bool
}
pub fn (mut self ${args.classname}) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
@if args.build
pub fn (mut self ${args.classname}) build() ! {
switch(self.name)
build()!
}
@end
pub fn (mut self ${args.classname}) destroy() ! {
switch(self.name)
@if args.startupmanager
self.stop() or {}
@end
destroy()!
}
@end

View File

@@ -11,7 +11,7 @@ import os
fn startupcmd() ![]startupmanager.ZProcessNewArgs {
mut cfg := get()!
mut res := []startupmanager.ZProcessNewArgs{}
res << startupmanager.ZProcessNewArgs{
name: 'redis'
cmd: 'redis-server ${configfilepath(cfg)}'
@@ -37,9 +37,9 @@ fn start_pre() ! {
if running()! {
return
}
mut cfg := get()!
// Ensure data directory exists with proper permissions before configuring
osal.execute_silent('mkdir -p ${cfg.datadir}')!
if core.is_linux()! {
@@ -47,13 +47,13 @@ fn start_pre() ! {
osal.execute_silent('chown -R redis:redis ${cfg.datadir}')!
osal.execute_silent('chmod 755 ${cfg.datadir}')!
}
// Configure redis before starting (applies template)
configure()!
// Kill any existing redis processes
osal.process_kill_recursive(name: 'redis-server')!
// On macOS, start redis with daemonize (not via startupmanager)
if core.platform()! == .osx {
osal.exec(cmd: 'redis-server ${configfilepath(cfg)} --daemonize yes')!
@@ -108,9 +108,9 @@ pub fn redis_install(args RedisInstall) ! {
console.print_debug('Redis already running on port ${args.port}')
return
}
console.print_header('install redis')
// Install Redis package if not already installed
if !installed()! {
if core.is_linux()! {
@@ -119,12 +119,12 @@ pub fn redis_install(args RedisInstall) ! {
osal.package_install('redis')! // macOS, Alpine, Arch, etc.
}
}
// Create data directory with correct permissions
osal.execute_silent('mkdir -p ${args.datadir}')!
osal.execute_silent('chown -R redis:redis ${args.datadir}') or {}
osal.execute_silent('chmod 755 ${args.datadir}') or {}
// Configure and start Redis
start(args)!
}
@@ -145,10 +145,10 @@ pub fn start(args RedisInstall) ! {
console.print_debug('Redis already running on port ${args.port}')
return
}
// Write Redis configuration file
configure_with_args(args)!
// Kill any existing Redis processes (including package auto-started ones)
osal.process_kill_recursive(name: 'redis-server')!
@@ -172,7 +172,7 @@ pub fn start(args RedisInstall) ! {
osal.exec(cmd: 'redis-server ${configfilepath(args)} --daemonize yes')!
}
}
// Wait for Redis to be ready
for _ in 0 .. 100 {
if check(args) {
@@ -181,7 +181,7 @@ pub fn start(args RedisInstall) ! {
}
time.sleep(100)
}
return error('Redis did not start properly after 10 seconds - could not ping on port ${args.port}')
}

View File

@@ -154,13 +154,13 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'coordinator.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
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')
coordinator_obj.destroy()!
@@ -173,12 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action coordinator.build')
coordinator_obj.build()!
}
}
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)!
console.print_debug('action object:\n${coordinator_obj}')
if other_action.name == 'start' {
console.print_debug('install action coordinator.${other_action.name}')
coordinator_obj.start()!

View File

@@ -14,7 +14,7 @@ const default = true
@[heap]
pub struct Coordinator {
pub mut:
name string = 'coordinator'
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

View File

@@ -142,7 +142,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'herorunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -161,12 +161,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action herorunner.build')
herorunner_obj.build()!
}
}
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)!
console.print_debug('action object:\n${herorunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action herorunner.${other_action.name}')
herorunner_obj.start()!

View File

@@ -14,10 +14,10 @@ const default = true
@[heap]
pub struct Herorunner {
pub mut:
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/herorunner')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/herorunner')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
}
// your checking & initialization code if needed

View File

@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'osirisrunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action osirisrunner.build')
osirisrunner_obj.build()!
}
}
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)!
console.print_debug('action object:\n${osirisrunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action osirisrunner.${other_action.name}')
osirisrunner_obj.start()!

View File

@@ -14,11 +14,11 @@ const default = true
@[heap]
pub struct Osirisrunner {
pub mut:
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_osiris')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_osiris')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
}
// your checking & initialization code if needed

View File

@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'salrunner.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
console.print_debug('install action salrunner.build')
salrunner_obj.build()!
}
}
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)!
console.print_debug('action object:\n${salrunner_obj}')
if other_action.name == 'start' {
console.print_debug('install action salrunner.${other_action.name}')
salrunner_obj.start()!

View File

@@ -14,11 +14,11 @@ const default = true
@[heap]
pub struct Salrunner {
pub mut:
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_sal')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/runner_sal')
redis_addr string = '127.0.0.1:6379'
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
}
// your checking & initialization code if needed

View File

@@ -153,7 +153,7 @@ pub fn play(mut plbook PlayBook) ! {
}
mut other_actions := plbook.find(filter: 'supervisor.')!
for mut other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
mut p := other_action.params
name := p.get_default('name', 'default')!
reset := p.get_default_false('reset')

View File

@@ -14,13 +14,13 @@ const default = true
@[heap]
pub struct Supervisor {
pub mut:
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/supervisor')
redis_addr string = '127.0.0.1:6379'
http_port int = 8082
ws_port int = 9654
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
name string = 'default'
binary_path string = os.join_path(os.home_dir(), 'hero/bin/supervisor')
redis_addr string = '127.0.0.1:6379'
http_port int = 8082
ws_port int = 9654
log_level string = 'info'
repo_path string = '/root/code/git.ourworld.tf/herocode/horus'
}
// your checking & initialization code if needed