refactor: rename mycelium to mycelium_installer
- Renamed the `mycelium` module to `mycelium_installer` to improve clarity and avoid naming conflicts. - Updated all related files and references to reflect the name change.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
import freeflowuniverse.herolib.installers.net.mycelium as mycelium_installer
|
import freeflowuniverse.herolib.installers.net.mycelium_installer
|
||||||
import freeflowuniverse.herolib.clients.mycelium
|
import freeflowuniverse.herolib.clients.mycelium
|
||||||
|
|
||||||
mut installer := mycelium_installer.get()!
|
mut installer := mycelium_installer.get()!
|
||||||
@@ -13,25 +13,27 @@ mut client := mycelium.get()!
|
|||||||
|
|
||||||
// Send a message to a node by public key
|
// Send a message to a node by public key
|
||||||
// Parameters: public_key, payload, topic, wait_for_reply
|
// Parameters: public_key, payload, topic, wait_for_reply
|
||||||
msg := client.send_msg('abc123...', // destination public key
|
msg := client.send_msg(
|
||||||
'Hello World', // message payload
|
public_key: 'abc123...' // destination public key
|
||||||
'greetings', // optional topic
|
payload: 'Hello World' // message payload
|
||||||
true // wait for reply
|
topic: 'greetings' // optional topic
|
||||||
)!
|
wait: true // wait for reply
|
||||||
|
)!
|
||||||
println('Sent message ID: ${msg.id}')
|
println('Sent message ID: ${msg.id}')
|
||||||
|
|
||||||
// Receive messages
|
// Receive messages
|
||||||
// Parameters: wait_for_message, peek_only, topic_filter
|
// Parameters: wait_for_message, peek_only, topic_filter
|
||||||
received := client.receive_msg(true, false, 'greetings')!
|
received := client.receive_msg(wait: true, peek: false, topic: 'greetings')!
|
||||||
println('Received message from: ${received.src_pk}')
|
println('Received message from: ${received.src_pk}')
|
||||||
println('Message payload: ${received.payload}')
|
println('Message payload: ${received.payload}')
|
||||||
|
|
||||||
// Reply to a message
|
// Reply to a message
|
||||||
client.reply_msg(received.id, // original message ID
|
client.reply_msg(
|
||||||
received.src_pk, // sender's public key
|
id: received.id // original message ID
|
||||||
'Got your message!', // reply payload
|
public_key: received.src_pk // sender's public key
|
||||||
'greetings' // topic
|
payload: 'Got your message!' // reply payload
|
||||||
)!
|
topic: 'greetings' // topic
|
||||||
|
)!
|
||||||
|
|
||||||
// Check message status
|
// Check message status
|
||||||
status := client.get_msg_status(msg.id)!
|
status := client.get_msg_status(msg.id)!
|
||||||
|
|||||||
@@ -1,291 +0,0 @@
|
|||||||
module mycelium
|
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
|
||||||
import freeflowuniverse.herolib.core.playbook
|
|
||||||
import freeflowuniverse.herolib.ui.console
|
|
||||||
import freeflowuniverse.herolib.data.paramsparser
|
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
|
||||||
import time
|
|
||||||
|
|
||||||
__global (
|
|
||||||
mycelium_global map[string]&MyceliumInstaller
|
|
||||||
mycelium_default string
|
|
||||||
)
|
|
||||||
|
|
||||||
/////////FACTORY
|
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct ArgsGet{
|
|
||||||
pub mut:
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
|
||||||
mut args:=args_
|
|
||||||
if args.name == ""{
|
|
||||||
args.name = "default"
|
|
||||||
}
|
|
||||||
return args
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
|
||||||
mut context:=base.context()!
|
|
||||||
mut args := args_get(args_)
|
|
||||||
mut obj := MyceliumInstaller{}
|
|
||||||
if !(args.name in mycelium_global) {
|
|
||||||
if ! exists(args)!{
|
|
||||||
set(obj)!
|
|
||||||
}else{
|
|
||||||
heroscript := context.hero_config_get("mycelium",args.name)!
|
|
||||||
mut obj_:=heroscript_loads(heroscript)!
|
|
||||||
set_in_mem(obj_)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mycelium_global[args.name] or {
|
|
||||||
println(mycelium_global)
|
|
||||||
//bug if we get here because should be in globals
|
|
||||||
panic("could not get config for mycelium with name, is bug:${args.name}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//register the config for the future
|
|
||||||
pub fn set(o MyceliumInstaller)! {
|
|
||||||
set_in_mem(o)!
|
|
||||||
mut context := base.context()!
|
|
||||||
heroscript := heroscript_dumps(o)!
|
|
||||||
context.hero_config_set("mycelium", o.name, heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
//does the config exists?
|
|
||||||
pub fn exists(args_ ArgsGet)! bool {
|
|
||||||
mut context := base.context()!
|
|
||||||
mut args := args_get(args_)
|
|
||||||
return context.hero_config_exists("mycelium", args.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn delete(args_ ArgsGet)! {
|
|
||||||
mut args := args_get(args_)
|
|
||||||
mut context:=base.context()!
|
|
||||||
context.hero_config_delete("mycelium",args.name)!
|
|
||||||
if args.name in mycelium_global {
|
|
||||||
//del mycelium_global[args.name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//only sets in mem, does not set as config
|
|
||||||
fn set_in_mem(o MyceliumInstaller)! {
|
|
||||||
mut o2:=obj_init(o)!
|
|
||||||
mycelium_global[o.name] = &o2
|
|
||||||
mycelium_default = o.name
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct PlayArgs {
|
|
||||||
pub mut:
|
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
|
||||||
plbook ?playbook.PlayBook
|
|
||||||
reset bool
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
|
||||||
|
|
||||||
mut args:=args_
|
|
||||||
|
|
||||||
|
|
||||||
mut plbook := args.plbook or {
|
|
||||||
playbook.new(text: args.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
|
||||||
if install_actions.len > 0 {
|
|
||||||
for install_action in install_actions {
|
|
||||||
heroscript:=install_action.heroscript()
|
|
||||||
mut obj2:=heroscript_loads(heroscript)!
|
|
||||||
set(obj2)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'mycelium.')!
|
|
||||||
for other_action in other_actions {
|
|
||||||
if other_action.name in ["destroy","install","build"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
reset:=p.get_default_false("reset")
|
|
||||||
if other_action.name == "destroy" || reset{
|
|
||||||
console.print_debug("install action mycelium.destroy")
|
|
||||||
destroy()!
|
|
||||||
}
|
|
||||||
if other_action.name == "install"{
|
|
||||||
console.print_debug("install action mycelium.install")
|
|
||||||
install()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if other_action.name in ["start","stop","restart"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut mycelium_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n${mycelium_obj}")
|
|
||||||
if other_action.name == "start"{
|
|
||||||
console.print_debug("install action mycelium.${other_action.name}")
|
|
||||||
mycelium_obj.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
if other_action.name == "stop"{
|
|
||||||
console.print_debug("install action mycelium.${other_action.name}")
|
|
||||||
mycelium_obj.stop()!
|
|
||||||
}
|
|
||||||
if other_action.name == "restart"{
|
|
||||||
console.print_debug("install action mycelium.${other_action.name}")
|
|
||||||
mycelium_obj.restart()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
|
||||||
// unknown
|
|
||||||
// screen
|
|
||||||
// zinit
|
|
||||||
// tmux
|
|
||||||
// systemd
|
|
||||||
match cat{
|
|
||||||
.zinit{
|
|
||||||
console.print_debug("startupmanager: zinit")
|
|
||||||
return startupmanager.get(cat:.zinit)!
|
|
||||||
}
|
|
||||||
.systemd{
|
|
||||||
console.print_debug("startupmanager: systemd")
|
|
||||||
return startupmanager.get(cat:.systemd)!
|
|
||||||
}else{
|
|
||||||
console.print_debug("startupmanager: auto")
|
|
||||||
return startupmanager.get()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self MyceliumInstaller) reload() ! {
|
|
||||||
switch(self.name)
|
|
||||||
self=obj_init(self)!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) start() ! {
|
|
||||||
switch(self.name)
|
|
||||||
if self.running()!{
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
console.print_header('mycelium start')
|
|
||||||
|
|
||||||
if ! installed()!{
|
|
||||||
install()!
|
|
||||||
}
|
|
||||||
|
|
||||||
configure()!
|
|
||||||
|
|
||||||
start_pre()!
|
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
|
||||||
|
|
||||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
|
||||||
|
|
||||||
sm.new(zprocess)!
|
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
|
||||||
}
|
|
||||||
|
|
||||||
start_post()!
|
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('mycelium did not install properly.')
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) install_start(args InstallArgs) ! {
|
|
||||||
switch(self.name)
|
|
||||||
self.install(args)!
|
|
||||||
self.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) stop() ! {
|
|
||||||
switch(self.name)
|
|
||||||
stop_pre()!
|
|
||||||
for zprocess in startupcmd()!{
|
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
|
||||||
sm.stop(zprocess.name)!
|
|
||||||
}
|
|
||||||
stop_post()!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) restart() ! {
|
|
||||||
switch(self.name)
|
|
||||||
self.stop()!
|
|
||||||
self.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) running() !bool {
|
|
||||||
switch(self.name)
|
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
|
||||||
for zprocess in startupcmd()!{
|
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
|
||||||
r:=sm.running(zprocess.name)!
|
|
||||||
if r==false{
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return running()!
|
|
||||||
}
|
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct InstallArgs{
|
|
||||||
pub mut:
|
|
||||||
reset bool
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) install(args InstallArgs) ! {
|
|
||||||
switch(self.name)
|
|
||||||
if args.reset || (!installed()!) {
|
|
||||||
install()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) build() ! {
|
|
||||||
switch(self.name)
|
|
||||||
build()!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) destroy() ! {
|
|
||||||
switch(self.name)
|
|
||||||
self.stop() or {}
|
|
||||||
destroy()!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//switch instance to be used for mycelium
|
|
||||||
pub fn switch(name string) {
|
|
||||||
mycelium_default = name
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//helpers
|
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct DefaultConfigArgs{
|
|
||||||
instance string = 'default'
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
module mycelium
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
!!hero_code.generate_installer
|
!!hero_code.generate_installer
|
||||||
name: "mycelium"
|
name: "mycelium_installer"
|
||||||
classname: "MyceliumInstaller"
|
classname: "MyceliumInstaller"
|
||||||
hasconfig: true
|
hasconfig: true
|
||||||
singleton: false
|
singleton: false
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
module mycelium
|
module mycelium_installer
|
||||||
|
|
||||||
import freeflowuniverse.herolib.osal
|
import freeflowuniverse.herolib.osal
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
import freeflowuniverse.herolib.installers.sysadmintools.zinit as zinit_installer
|
import freeflowuniverse.herolib.installers.infra.zinit_installer
|
||||||
import freeflowuniverse.herolib.clients.mycelium
|
import freeflowuniverse.herolib.clients.mycelium
|
||||||
import freeflowuniverse.herolib.develop.gittools
|
import freeflowuniverse.herolib.develop.gittools
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
@@ -78,8 +78,8 @@ fn ulist_get() !ulist.UList {
|
|||||||
// uploads to S3 server if configured
|
// uploads to S3 server if configured
|
||||||
fn upload() ! {
|
fn upload() ! {
|
||||||
// installers.upload(
|
// installers.upload(
|
||||||
// cmdname: 'mycelium'
|
// cmdname: 'mycelium_installer'
|
||||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium'
|
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/mycelium_installer'
|
||||||
// )!
|
// )!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +125,9 @@ fn build() ! {
|
|||||||
if myplatform != .ubuntu {
|
if myplatform != .ubuntu {
|
||||||
return error('only support ubuntu for now')
|
return error('only support ubuntu for now')
|
||||||
}
|
}
|
||||||
rust.install()!
|
|
||||||
|
mut rs := rust.get()!
|
||||||
|
rs.install()!
|
||||||
|
|
||||||
console.print_header('build mycelium')
|
console.print_header('build mycelium')
|
||||||
|
|
||||||
@@ -0,0 +1,279 @@
|
|||||||
|
module mycelium_installer
|
||||||
|
|
||||||
|
import freeflowuniverse.herolib.core.base
|
||||||
|
import freeflowuniverse.herolib.core.playbook
|
||||||
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
|
import time
|
||||||
|
|
||||||
|
__global (
|
||||||
|
mycelium_installer_global map[string]&MyceliumInstaller
|
||||||
|
mycelium_installer_default string
|
||||||
|
)
|
||||||
|
|
||||||
|
/////////FACTORY
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct ArgsGet {
|
||||||
|
pub mut:
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
|
mut args := args_
|
||||||
|
if args.name == '' {
|
||||||
|
args.name = 'default'
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
||||||
|
mut context := base.context()!
|
||||||
|
mut args := args_get(args_)
|
||||||
|
mut obj := MyceliumInstaller{}
|
||||||
|
if args.name !in mycelium_installer_global {
|
||||||
|
if !exists(args)! {
|
||||||
|
set(obj)!
|
||||||
|
} else {
|
||||||
|
heroscript := context.hero_config_get('mycelium_installer', args.name)!
|
||||||
|
mut obj_ := heroscript_loads(heroscript)!
|
||||||
|
set_in_mem(obj_)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mycelium_installer_global[args.name] or {
|
||||||
|
println(mycelium_installer_global)
|
||||||
|
// bug if we get here because should be in globals
|
||||||
|
panic('could not get config for mycelium_installer with name, is bug:${args.name}')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// register the config for the future
|
||||||
|
pub fn set(o MyceliumInstaller) ! {
|
||||||
|
set_in_mem(o)!
|
||||||
|
mut context := base.context()!
|
||||||
|
heroscript := heroscript_dumps(o)!
|
||||||
|
context.hero_config_set('mycelium_installer', o.name, heroscript)!
|
||||||
|
}
|
||||||
|
|
||||||
|
// does the config exists?
|
||||||
|
pub fn exists(args_ ArgsGet) !bool {
|
||||||
|
mut context := base.context()!
|
||||||
|
mut args := args_get(args_)
|
||||||
|
return context.hero_config_exists('mycelium_installer', args.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(args_ ArgsGet) ! {
|
||||||
|
mut args := args_get(args_)
|
||||||
|
mut context := base.context()!
|
||||||
|
context.hero_config_delete('mycelium_installer', args.name)!
|
||||||
|
if args.name in mycelium_installer_global {
|
||||||
|
// del mycelium_installer_global[args.name]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// only sets in mem, does not set as config
|
||||||
|
fn set_in_mem(o MyceliumInstaller) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
|
mycelium_installer_global[o.name] = &o2
|
||||||
|
mycelium_installer_default = o.name
|
||||||
|
}
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct PlayArgs {
|
||||||
|
pub mut:
|
||||||
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
|
plbook ?playbook.PlayBook
|
||||||
|
reset bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut args := args_
|
||||||
|
|
||||||
|
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||||
|
|
||||||
|
mut install_actions := plbook.find(filter: 'mycelium_installer.configure')!
|
||||||
|
if install_actions.len > 0 {
|
||||||
|
for install_action in install_actions {
|
||||||
|
heroscript := install_action.heroscript()
|
||||||
|
mut obj2 := heroscript_loads(heroscript)!
|
||||||
|
set(obj2)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mut other_actions := plbook.find(filter: 'mycelium_installer.')!
|
||||||
|
for other_action in other_actions {
|
||||||
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
reset := p.get_default_false('reset')
|
||||||
|
if other_action.name == 'destroy' || reset {
|
||||||
|
console.print_debug('install action mycelium_installer.destroy')
|
||||||
|
destroy()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action mycelium_installer.install')
|
||||||
|
install()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut mycelium_installer_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${mycelium_installer_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action mycelium_installer.${other_action.name}')
|
||||||
|
mycelium_installer_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action mycelium_installer.${other_action.name}')
|
||||||
|
mycelium_installer_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action mycelium_installer.${other_action.name}')
|
||||||
|
mycelium_installer_obj.restart()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
|
// unknown
|
||||||
|
// screen
|
||||||
|
// zinit
|
||||||
|
// tmux
|
||||||
|
// systemd
|
||||||
|
match cat {
|
||||||
|
.zinit {
|
||||||
|
console.print_debug('startupmanager: zinit')
|
||||||
|
return startupmanager.get(cat: .zinit)!
|
||||||
|
}
|
||||||
|
.systemd {
|
||||||
|
console.print_debug('startupmanager: systemd')
|
||||||
|
return startupmanager.get(cat: .systemd)!
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.print_debug('startupmanager: auto')
|
||||||
|
return startupmanager.get()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
|
pub fn (mut self MyceliumInstaller) reload() ! {
|
||||||
|
switch(self.name)
|
||||||
|
self = obj_init(self)!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) start() ! {
|
||||||
|
switch(self.name)
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.print_header('mycelium_installer start')
|
||||||
|
|
||||||
|
if !installed()! {
|
||||||
|
install()!
|
||||||
|
}
|
||||||
|
|
||||||
|
configure()!
|
||||||
|
|
||||||
|
start_pre()!
|
||||||
|
|
||||||
|
for zprocess in startupcmd()! {
|
||||||
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
|
console.print_debug('starting mycelium_installer with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
|
sm.new(zprocess)!
|
||||||
|
|
||||||
|
sm.start(zprocess.name)!
|
||||||
|
}
|
||||||
|
|
||||||
|
start_post()!
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('mycelium_installer did not install properly.')
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) install_start(args InstallArgs) ! {
|
||||||
|
switch(self.name)
|
||||||
|
self.install(args)!
|
||||||
|
self.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) stop() ! {
|
||||||
|
switch(self.name)
|
||||||
|
stop_pre()!
|
||||||
|
for zprocess in startupcmd()! {
|
||||||
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
sm.stop(zprocess.name)!
|
||||||
|
}
|
||||||
|
stop_post()!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) restart() ! {
|
||||||
|
switch(self.name)
|
||||||
|
self.stop()!
|
||||||
|
self.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) running() !bool {
|
||||||
|
switch(self.name)
|
||||||
|
|
||||||
|
// walk over the generic processes, if not running return
|
||||||
|
for zprocess in startupcmd()! {
|
||||||
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
r := sm.running(zprocess.name)!
|
||||||
|
if r == false {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return running()!
|
||||||
|
}
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct InstallArgs {
|
||||||
|
pub mut:
|
||||||
|
reset bool
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) install(args InstallArgs) ! {
|
||||||
|
switch(self.name)
|
||||||
|
if args.reset || (!installed()!) {
|
||||||
|
install()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) build() ! {
|
||||||
|
switch(self.name)
|
||||||
|
build()!
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut self MyceliumInstaller) destroy() ! {
|
||||||
|
switch(self.name)
|
||||||
|
self.stop() or {}
|
||||||
|
destroy()!
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for mycelium_installer
|
||||||
|
pub fn switch(name string) {
|
||||||
|
mycelium_installer_default = name
|
||||||
|
}
|
||||||
|
|
||||||
|
// helpers
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct DefaultConfigArgs {
|
||||||
|
instance string = 'default'
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module mycelium
|
module mycelium_installer
|
||||||
|
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
import freeflowuniverse.herolib.osal.tun
|
import freeflowuniverse.herolib.osal.tun
|
||||||
Reference in New Issue
Block a user