postgresql & new docs
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
#!/usr/bin/env -S v -n -w -cg -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
|
|
||||||
import freeflowuniverse.herolib.installers.lang.rust
|
import freeflowuniverse.herolib.installers.lang.rust
|
||||||
import freeflowuniverse.herolib.installers.lang.python
|
import freeflowuniverse.herolib.installers.lang.python
|
||||||
import freeflowuniverse.herolib.installers.lang.nodejs
|
import freeflowuniverse.herolib.installers.lang.nodejs
|
||||||
import freeflowuniverse.herolib.installers.lang.golang
|
import freeflowuniverse.herolib.installers.lang.golang
|
||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
|
|
||||||
core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights
|
core.interactive_set()! // make sure the sudo works so we can do things even if it requires those rights
|
||||||
|
|
||||||
|
|
||||||
// import freeflowuniverse.herolib.data.dbfs
|
// import freeflowuniverse.herolib.data.dbfs
|
||||||
// import freeflowuniverse.herolib.installers.lang.vlang
|
// import freeflowuniverse.herolib.installers.lang.vlang
|
||||||
@@ -39,4 +37,4 @@ core.interactive_set()! //make sure the sudo works so we can do things even if i
|
|||||||
// rust.install(reset:false)!
|
// rust.install(reset:false)!
|
||||||
// python.install(reset:false)!
|
// python.install(reset:false)!
|
||||||
// nodejs.install(reset:false)!
|
// nodejs.install(reset:false)!
|
||||||
golang.install(reset:false)!
|
golang.install(reset: false)!
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
struct DeploymentStateDB {
|
struct DeploymentStateDB {
|
||||||
@@ -12,21 +11,21 @@ struct DeploymentState {
|
|||||||
zdbs []ZDBDeployed
|
zdbs []ZDBDeployed
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut db DeploymentStateDB) set(deployment_name string, key string, val string)! {
|
pub fn (mut db DeploymentStateDB) set(deployment_name string, key string, val string) ! {
|
||||||
// store e.g. \n separated list of all keys per deployment_name
|
// store e.g. \n separated list of all keys per deployment_name
|
||||||
// encrypt
|
// encrypt
|
||||||
db.data['${deployment_name}_${key}'] = val
|
db.data['${deployment_name}_${key}'] = val
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (db DeploymentStateDB) get(deployment_name string, key string)!string {
|
pub fn (db DeploymentStateDB) get(deployment_name string, key string) !string {
|
||||||
return db.data['${deployment_name}_${key}'] or { return error('key not found') }
|
return db.data['${deployment_name}_${key}'] or { return error('key not found') }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut db DeploymentStateDB) delete(deployment_name string, key string)! {
|
pub fn (mut db DeploymentStateDB) delete(deployment_name string, key string) ! {
|
||||||
db.data.delete('${deployment_name}_${key}')
|
db.data.delete('${deployment_name}_${key}')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (db DeploymentStateDB) keys(deployment_name string)![]string {
|
pub fn (db DeploymentStateDB) keys(deployment_name string) ![]string {
|
||||||
mut keys := []string{}
|
mut keys := []string{}
|
||||||
for k, _ in db.data {
|
for k, _ in db.data {
|
||||||
if k.starts_with('${deployment_name}_') {
|
if k.starts_with('${deployment_name}_') {
|
||||||
@@ -36,7 +35,7 @@ pub fn (db DeploymentStateDB) keys(deployment_name string)![]string {
|
|||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (db DeploymentStateDB) load(deployment_name string)!DeploymentState {
|
pub fn (db DeploymentStateDB) load(deployment_name string) !DeploymentState {
|
||||||
mut state := DeploymentState{
|
mut state := DeploymentState{
|
||||||
name: deployment_name
|
name: deployment_name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env -S v -gc none -no-retry-compilation -d use_openssl -enable-globals -cg run
|
#!/usr/bin/env -S v -gc none -no-retry-compilation -d use_openssl -enable-globals -cg run
|
||||||
//#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals -cg run
|
|
||||||
|
|
||||||
|
//#!/usr/bin/env -S v -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals -cg run
|
||||||
import freeflowuniverse.herolib.threefold.gridproxy
|
import freeflowuniverse.herolib.threefold.gridproxy
|
||||||
import freeflowuniverse.herolib.threefold.tfgrid3deployer
|
import freeflowuniverse.herolib.threefold.tfgrid3deployer
|
||||||
import freeflowuniverse.herolib.installers.threefold.griddriver
|
import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module mailclient
|
module mailclient
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
@@ -6,116 +5,102 @@ import freeflowuniverse.herolib.core.playbook
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
mailclient_global map[string]&MailClient
|
mailclient_global map[string]&MailClient
|
||||||
mailclient_default string
|
mailclient_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = mailclient_default
|
model.name = mailclient_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&MailClient {
|
pub fn get(args_ ArgsGet) !&MailClient {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in mailclient_global) {
|
if args.name !in mailclient_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("mailclient",model.name,heroscript_default()!)!
|
context.hero_config_set('mailclient', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mailclient_global[args.name] or {
|
return mailclient_global[args.name] or {
|
||||||
println(mailclient_global)
|
println(mailclient_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o MailClient) ! {
|
||||||
//set the model in mem and the config on the filesystem
|
mut o2 := obj_init(o)!
|
||||||
pub fn set(o MailClient)! {
|
mailclient_global[o.name] = &o2
|
||||||
mut o2:=obj_init(o)!
|
mailclient_default = o.name
|
||||||
mailclient_global[o.name] = &o2
|
|
||||||
mailclient_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("mailclient",model.name)
|
return context.hero_config_exists('mailclient', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("mailclient",model.name)!
|
mut heroscript := context.hero_config_get('mailclient', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o MailClient)! {
|
pub fn save(o MailClient) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[MailClient](o)!
|
heroscript := encoderhero.encode[MailClient](o)!
|
||||||
context.hero_config_set("mailclient",model.name,heroscript)!
|
context.hero_config_set('mailclient', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
|
||||||
model.heroscript = heroscript_default()!
|
|
||||||
}
|
|
||||||
mut plbook := model.plbook or {
|
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'mailclient.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action mailclient.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if model.heroscript == '' {
|
||||||
|
model.heroscript = heroscript_default()!
|
||||||
|
}
|
||||||
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
|
|
||||||
|
mut configure_actions := plbook.find(filter: 'mailclient.configure')!
|
||||||
|
if configure_actions.len > 0 {
|
||||||
|
for config_action in configure_actions {
|
||||||
|
mut p := config_action.params
|
||||||
|
mycfg := cfg_play(p)!
|
||||||
|
console.print_debug('install action mailclient.configure\n${mycfg}')
|
||||||
|
set(mycfg)!
|
||||||
|
save(mycfg)!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module meilisearch
|
module meilisearch
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
@@ -6,116 +5,102 @@ import freeflowuniverse.herolib.core.playbook
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
meilisearch_global map[string]&MeilisearchClient
|
meilisearch_global map[string]&MeilisearchClient
|
||||||
meilisearch_default string
|
meilisearch_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = meilisearch_default
|
model.name = meilisearch_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&MeilisearchClient {
|
pub fn get(args_ ArgsGet) !&MeilisearchClient {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in meilisearch_global) {
|
if args.name !in meilisearch_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("meilisearch",model.name,heroscript_default()!)!
|
context.hero_config_set('meilisearch', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meilisearch_global[args.name] or {
|
return meilisearch_global[args.name] or {
|
||||||
println(meilisearch_global)
|
println(meilisearch_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o MeilisearchClient) ! {
|
||||||
//set the model in mem and the config on the filesystem
|
mut o2 := obj_init(o)!
|
||||||
pub fn set(o MeilisearchClient)! {
|
meilisearch_global[o.name] = &o2
|
||||||
mut o2:=obj_init(o)!
|
meilisearch_default = o.name
|
||||||
meilisearch_global[o.name] = &o2
|
|
||||||
meilisearch_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("meilisearch",model.name)
|
return context.hero_config_exists('meilisearch', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("meilisearch",model.name)!
|
mut heroscript := context.hero_config_get('meilisearch', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o MeilisearchClient)! {
|
pub fn save(o MeilisearchClient) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[MeilisearchClient](o)!
|
heroscript := encoderhero.encode[MeilisearchClient](o)!
|
||||||
context.hero_config_set("meilisearch",model.name,heroscript)!
|
context.hero_config_set('meilisearch', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
|
||||||
model.heroscript = heroscript_default()!
|
|
||||||
}
|
|
||||||
mut plbook := model.plbook or {
|
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'meilisearch.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action meilisearch.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if model.heroscript == '' {
|
||||||
|
model.heroscript = heroscript_default()!
|
||||||
|
}
|
||||||
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
|
|
||||||
|
mut configure_actions := plbook.find(filter: 'meilisearch.configure')!
|
||||||
|
if configure_actions.len > 0 {
|
||||||
|
for config_action in configure_actions {
|
||||||
|
mut p := config_action.params
|
||||||
|
mycfg := cfg_play(p)!
|
||||||
|
console.print_debug('install action meilisearch.configure\n${mycfg}')
|
||||||
|
set(mycfg)!
|
||||||
|
save(mycfg)!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module mycelium
|
module mycelium
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
@@ -6,79 +5,66 @@ import freeflowuniverse.herolib.core.playbook
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
mycelium_global map[string]&Mycelium
|
mycelium_global map[string]&Mycelium
|
||||||
mycelium_default string
|
mycelium_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o Mycelium) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
//set the model in mem and the config on the filesystem
|
mycelium_global[o.name] = &o2
|
||||||
pub fn set(o Mycelium)! {
|
mycelium_default = o.name
|
||||||
mut o2:=obj_init(o)!
|
|
||||||
mycelium_global[o.name] = &o2
|
|
||||||
mycelium_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("mycelium",model.name)
|
return context.hero_config_exists('mycelium', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("mycelium",model.name)!
|
mut heroscript := context.hero_config_get('mycelium', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o Mycelium)! {
|
pub fn save(o Mycelium) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[Mycelium](o)!
|
heroscript := encoderhero.encode[Mycelium](o)!
|
||||||
context.hero_config_set("mycelium",model.name,heroscript)!
|
context.hero_config_set('mycelium', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
|
||||||
model.heroscript = heroscript_default()!
|
|
||||||
}
|
|
||||||
mut plbook := model.plbook or {
|
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'mycelium.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action mycelium.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if model.heroscript == '' {
|
||||||
|
model.heroscript = heroscript_default()!
|
||||||
|
}
|
||||||
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
|
|
||||||
|
mut configure_actions := plbook.find(filter: 'mycelium.configure')!
|
||||||
|
if configure_actions.len > 0 {
|
||||||
|
for config_action in configure_actions {
|
||||||
|
mut p := config_action.params
|
||||||
|
mycfg := cfg_play(p)!
|
||||||
|
console.print_debug('install action mycelium.configure\n${mycfg}')
|
||||||
|
set(mycfg)!
|
||||||
|
save(mycfg)!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,48 @@
|
|||||||
|
|
||||||
module openai
|
module openai
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
openai_global map[string]&OpenAI
|
openai_global map[string]&OpenAI
|
||||||
openai_default string
|
openai_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = openai_default
|
model.name = openai_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&OpenAI {
|
pub fn get(args_ ArgsGet) !&OpenAI {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in openai_global) {
|
if args.name !in openai_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("openai",model.name,heroscript_default()!)!
|
context.hero_config_set('openai', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return openai_global[args.name] or {
|
return openai_global[args.name] or {
|
||||||
println(openai_global)
|
println(openai_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
!!hero_code.generate_client
|
!!hero_code.generate_client
|
||||||
name: "postgresql_client"
|
name: "postgresql_client"
|
||||||
classname: "PostgresClient"
|
classname: "PostgresClient"
|
||||||
hasconfig: false
|
hasconfig: true
|
||||||
singleton: true
|
singleton: false
|
||||||
default: true
|
default: true
|
||||||
title: ""
|
title: ""
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module postgres
|
module postgresql_client
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import db.pg
|
import db.pg
|
||||||
@@ -49,8 +49,8 @@ import freeflowuniverse.herolib.ui.console
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
struct LocalConfig {
|
// struct LocalConfig {
|
||||||
name string
|
// name string
|
||||||
path string
|
// path string
|
||||||
passwd string
|
// passwd string
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
module postgres
|
module postgresql_client
|
||||||
|
|
||||||
import db.pg
|
import db.pg
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
@@ -6,26 +6,24 @@ import freeflowuniverse.herolib.osal
|
|||||||
import os
|
import os
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) check() ! {
|
pub fn (mut self PostgresClient) check() ! {
|
||||||
mut db := self.db
|
mut db := self.db()!
|
||||||
db.exec('SELECT version();') or { return error('can\t select version from database.\n${self}') }
|
db.exec('SELECT version();') or { return error('can\t select version from database.\n${self}') }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) exec(c_ string) ![]pg.Row {
|
pub fn (mut self PostgresClient) exec(c_ string) ![]pg.Row {
|
||||||
mut db := self.db
|
mut db := self.db()!
|
||||||
mut c := c_
|
mut c := c_
|
||||||
if !(c.trim_space().ends_with(';')) {
|
if !(c.trim_space().ends_with(';')) {
|
||||||
c += ';'
|
c += ';'
|
||||||
}
|
}
|
||||||
|
|
||||||
config := self.config()!
|
|
||||||
return db.exec(c) or {
|
return db.exec(c) or {
|
||||||
return error('can\t execute query on ${config.host}:${config.dbname}.\n${c}\n${err}')
|
return error('can\t execute query on ${self.host}:${self.name}.\n${c}\n${err}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) db_exists(name_ string) !bool {
|
pub fn (mut self PostgresClient) db_exists(name_ string) !bool {
|
||||||
mut db := self.db
|
mut db := self.db()!
|
||||||
r := db.exec("SELECT datname FROM pg_database WHERE datname='${name_}';")!
|
r := db.exec("SELECT datname FROM pg_database WHERE datname='${name_}';")!
|
||||||
if r.len == 1 {
|
if r.len == 1 {
|
||||||
// console.print_header(' db exists: ${name_}')
|
// console.print_header(' db exists: ${name_}')
|
||||||
@@ -37,36 +35,32 @@ pub fn (mut self PostgresClient[Config]) db_exists(name_ string) !bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) db_create(name_ string) ! {
|
pub fn (mut self PostgresClient) db_create(name_ string) ! {
|
||||||
name := texttools.name_fix(name_)
|
name := texttools.name_fix(name_)
|
||||||
mut db := self.db
|
mut db := self.db()!
|
||||||
db_exists := self.db_exists(name_)!
|
if !self.db_exists(name)! {
|
||||||
if !db_exists {
|
|
||||||
console.print_header(' db create: ${name}')
|
console.print_header(' db create: ${name}')
|
||||||
db.exec('CREATE DATABASE ${name};')!
|
db.exec('CREATE DATABASE ${name};')!
|
||||||
}
|
}
|
||||||
db_exists2 := self.db_exists(name_)!
|
if !self.db_exists(name)! {
|
||||||
if !db_exists2 {
|
|
||||||
return error('Could not create db: ${name_}, could not find in DB.')
|
return error('Could not create db: ${name_}, could not find in DB.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) db_delete(name_ string) ! {
|
pub fn (mut self PostgresClient) db_delete(name_ string) ! {
|
||||||
mut db := self.db
|
mut db := self.db()!
|
||||||
name := texttools.name_fix(name_)
|
name := texttools.name_fix(name_)
|
||||||
self.check()!
|
self.check()!
|
||||||
db_exists := self.db_exists(name_)!
|
if self.db_exists(name)! {
|
||||||
if db_exists {
|
|
||||||
console.print_header(' db delete: ${name_}')
|
console.print_header(' db delete: ${name_}')
|
||||||
db.exec('DROP DATABASE ${name};')!
|
db.exec('DROP DATABASE ${name};')!
|
||||||
}
|
}
|
||||||
db_exists2 := self.db_exists(name_)!
|
if self.db_exists(name)! {
|
||||||
if db_exists2 {
|
return error('Could not delete db: ${name_}, db was still there.')
|
||||||
return error('Could not delete db: ${name_}, could not find in DB.')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) db_names() ![]string {
|
pub fn (mut self PostgresClient) db_names() ![]string {
|
||||||
mut res := []string{}
|
mut res := []string{}
|
||||||
sqlstr := "SELECT datname FROM pg_database WHERE datistemplate = false and datname != 'postgres' and datname != 'root';"
|
sqlstr := "SELECT datname FROM pg_database WHERE datistemplate = false and datname != 'postgres' and datname != 'root';"
|
||||||
for row in self.exec(sqlstr)! {
|
for row in self.exec(sqlstr)! {
|
||||||
@@ -83,7 +77,7 @@ pub mut:
|
|||||||
dest string
|
dest string
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self PostgresClient[Config]) backup(args BackupParams) ! {
|
pub fn (mut self PostgresClient) backup(args BackupParams) ! {
|
||||||
if args.dest == '' {
|
if args.dest == '' {
|
||||||
return error('specify the destination please')
|
return error('specify the destination please')
|
||||||
}
|
}
|
||||||
@@ -96,10 +90,9 @@ pub fn (mut self PostgresClient[Config]) backup(args BackupParams) ! {
|
|||||||
self.backup(dbname: dbname, dest: args.dest)!
|
self.backup(dbname: dbname, dest: args.dest)!
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config := self.config()!
|
|
||||||
cmd := '
|
cmd := '
|
||||||
export PGPASSWORD=\'${config.password}\'
|
export PGPASSWORD=\'${self.password}\'
|
||||||
pg_dump -h ${config.host} -p ${config.port} -U ${config.user} --dbname=${args.dbname} --format=c > "${args.dest}/${args.dbname}.bak"
|
pg_dump -h ${self.host} -p ${self.port} -U ${self.user} --dbname=${args.dbname} --format=c > "${args.dest}/${args.dbname}.bak"
|
||||||
' // console.print_debug(cmd)
|
' // console.print_debug(cmd)
|
||||||
|
|
||||||
osal.exec(cmd: cmd, stdout: true)!
|
osal.exec(cmd: cmd, stdout: true)!
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
module postgres
|
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
|
||||||
import freeflowuniverse.herolib.ui
|
|
||||||
import freeflowuniverse.herolib.ui.console
|
|
||||||
|
|
||||||
@[params]
|
|
||||||
pub struct Config {
|
|
||||||
pub mut:
|
|
||||||
instance string = 'default'
|
|
||||||
user string = 'root'
|
|
||||||
port int = 5432
|
|
||||||
host string = 'localhost'
|
|
||||||
password string
|
|
||||||
dbname string = 'postgres'
|
|
||||||
heroscript string
|
|
||||||
reset bool
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn configure(instance string, cfg_ Config) !PostgresClient[Config] {
|
|
||||||
mut config := cfg_
|
|
||||||
|
|
||||||
mut server := PostgresClient[Config]{}
|
|
||||||
server.init('postgres', instance, .set, config)!
|
|
||||||
return get(instance)!
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn configure_interactive(args_ Config, mut session base.Session) ! {
|
|
||||||
mut args := args_
|
|
||||||
mut myui := ui.new()!
|
|
||||||
|
|
||||||
console.clear()
|
|
||||||
console.print_debug('\n## Configure Postgres Client')
|
|
||||||
console.print_debug('============================\n\n')
|
|
||||||
|
|
||||||
instance := myui.ask_question(
|
|
||||||
question: 'name for postgres client'
|
|
||||||
default: args.instance
|
|
||||||
)!
|
|
||||||
|
|
||||||
args.user = myui.ask_question(
|
|
||||||
question: 'user'
|
|
||||||
minlen: 3
|
|
||||||
default: args.user
|
|
||||||
)!
|
|
||||||
|
|
||||||
args.password = myui.ask_question(
|
|
||||||
question: 'password'
|
|
||||||
minlen: 3
|
|
||||||
default: args.password
|
|
||||||
)!
|
|
||||||
|
|
||||||
args.dbname = myui.ask_question(
|
|
||||||
question: 'dbname'
|
|
||||||
minlen: 3
|
|
||||||
default: args.dbname
|
|
||||||
)!
|
|
||||||
|
|
||||||
args.host = myui.ask_question(
|
|
||||||
question: 'host'
|
|
||||||
minlen: 3
|
|
||||||
default: args.host
|
|
||||||
)!
|
|
||||||
mut port := myui.ask_question(
|
|
||||||
question: 'port'
|
|
||||||
default: '${args.port}'
|
|
||||||
)!
|
|
||||||
args.port = port.int()
|
|
||||||
|
|
||||||
mut client := PostgresClient[Config]{}
|
|
||||||
client.init('postgres', instance, .set, args)!
|
|
||||||
}
|
|
||||||
|
|
||||||
// pub fn play_session(mut session base.Session) ! {
|
|
||||||
// for mut action in session.plbook.find(filter: 'postgresclient.define')! {
|
|
||||||
// mut p := action.params
|
|
||||||
// mut args := config()
|
|
||||||
// panic('implement')
|
|
||||||
// // args.instance = p.get_default('name','')!
|
|
||||||
// // if args.instance == ""{
|
|
||||||
// // args.instance = p.get_default('instance', 'default')!
|
|
||||||
// // }
|
|
||||||
// // args.mail_from = p.get('mail_from')!
|
|
||||||
// // args.smtp_addr = p.get('smtp_addr')!
|
|
||||||
// // args.smtp_login = p.get('smtp_login')!
|
|
||||||
// // args.smtp_passwd = p.get('smtp_passwd')!
|
|
||||||
// // args.smpt_port = p.get_int('smpt_port')!
|
|
||||||
// // mut c:=configurator(args.instance,session:session)!
|
|
||||||
// // c.set(args)!
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
module postgres
|
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
|
||||||
import freeflowuniverse.herolib.ui as gui
|
|
||||||
import freeflowuniverse.herolib.ui.console
|
|
||||||
import db.pg
|
|
||||||
|
|
||||||
pub struct PostgresClient[T] {
|
|
||||||
base.BaseConfig[T]
|
|
||||||
pub mut:
|
|
||||||
db pg.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(instance string) !PostgresClient[Config] {
|
|
||||||
mut self := PostgresClient[Config]{}
|
|
||||||
self.init('postgres', instance, .get)!
|
|
||||||
config := self.config()!
|
|
||||||
|
|
||||||
mut db := pg.connect(
|
|
||||||
host: config.host
|
|
||||||
user: config.user
|
|
||||||
port: config.port
|
|
||||||
password: config.password
|
|
||||||
dbname: config.dbname
|
|
||||||
)!
|
|
||||||
|
|
||||||
self.db = db
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,107 @@
|
|||||||
|
|
||||||
module postgresql_client
|
module postgresql_client
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
import freeflowuniverse.herolib.core
|
||||||
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
postgresql_client_global map[string]&PostgresClient
|
postgresql_client_global map[string]&PostgresClient
|
||||||
postgresql_client_default string
|
postgresql_client_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
@[params]
|
||||||
|
pub struct ArgsGet {
|
||||||
|
pub mut:
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
|
mut model := args_
|
||||||
|
if model.name == '' {
|
||||||
|
model.name = postgresql_client_default
|
||||||
|
}
|
||||||
|
if model.name == '' {
|
||||||
|
model.name = 'default'
|
||||||
|
}
|
||||||
|
return model
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(args_ ArgsGet) !&PostgresClient {
|
||||||
|
mut args := args_get(args_)
|
||||||
|
if args.name !in postgresql_client_global {
|
||||||
|
if args.name == 'default' {
|
||||||
|
if !exists(args)! {
|
||||||
|
if default {
|
||||||
|
mut context := base.context() or { panic('bug') }
|
||||||
|
context.hero_config_set('postgresql_client', args.name, heroscript_default()!)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
load(args)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return postgresql_client_global[args.name] or {
|
||||||
|
println(postgresql_client_global)
|
||||||
|
panic('could not get config for ${args.name}.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o PostgresClient) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
|
postgresql_client_global[o.name] = &o2
|
||||||
|
postgresql_client_default = o.name
|
||||||
|
}
|
||||||
|
|
||||||
|
// check we find the config on the filesystem
|
||||||
|
pub fn exists(args_ ArgsGet) !bool {
|
||||||
|
mut model := args_get(args_)
|
||||||
|
mut context := base.context()!
|
||||||
|
return context.hero_config_exists('postgresql_client', model.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// load the config error if it doesn't exist
|
||||||
|
pub fn load(args_ ArgsGet) ! {
|
||||||
|
mut model := args_get(args_)
|
||||||
|
mut context := base.context()!
|
||||||
|
mut heroscript := context.hero_config_get('postgresql_client', model.name)!
|
||||||
|
play(heroscript: heroscript)!
|
||||||
|
}
|
||||||
|
|
||||||
|
// save the config to the filesystem in the context
|
||||||
|
pub fn save(o PostgresClient) ! {
|
||||||
|
mut context := base.context()!
|
||||||
|
heroscript := encoderhero.encode[PostgresClient](o)!
|
||||||
|
context.hero_config_set('postgresql_client', o.name, heroscript)!
|
||||||
|
}
|
||||||
|
|
||||||
|
@[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 model := args_
|
||||||
|
|
||||||
|
if model.heroscript == '' {
|
||||||
|
model.heroscript = heroscript_default()!
|
||||||
|
}
|
||||||
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
|
|
||||||
|
mut configure_actions := plbook.find(filter: 'postgresql_client.configure')!
|
||||||
|
if configure_actions.len > 0 {
|
||||||
|
for config_action in configure_actions {
|
||||||
|
mut p := config_action.params
|
||||||
|
mycfg := cfg_play(p)!
|
||||||
|
console.print_debug('install action postgresql_client.configure\n${mycfg}')
|
||||||
|
set(mycfg)!
|
||||||
|
save(mycfg)!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,27 +2,71 @@ module postgresql_client
|
|||||||
|
|
||||||
import freeflowuniverse.herolib.data.paramsparser
|
import freeflowuniverse.herolib.data.paramsparser
|
||||||
import os
|
import os
|
||||||
|
import db.pg
|
||||||
|
|
||||||
pub const version = '0.0.0'
|
pub const version = '0.0.0'
|
||||||
const singleton = true
|
const singleton = false
|
||||||
const default = true
|
const default = true
|
||||||
|
|
||||||
|
pub fn heroscript_default() !string {
|
||||||
|
heroscript := "
|
||||||
|
!!postgresql_client.configure
|
||||||
|
name:'default'
|
||||||
|
user: 'root'
|
||||||
|
port: 5432
|
||||||
|
host: 'localhost'
|
||||||
|
password: ''
|
||||||
|
dbname: 'postgres'
|
||||||
|
"
|
||||||
|
return heroscript
|
||||||
|
}
|
||||||
|
|
||||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||||
|
|
||||||
@[heap]
|
@[heap]
|
||||||
pub struct PostgresClient {
|
pub struct PostgresClient {
|
||||||
|
mut:
|
||||||
|
db_ ?pg.DB
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string = 'default'
|
||||||
mail_from string
|
user string = 'root'
|
||||||
mail_password string @[secret]
|
port int = 5432
|
||||||
mail_port int
|
host string = 'localhost'
|
||||||
mail_server string
|
password string
|
||||||
mail_username string
|
dbname string = 'postgres'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cfg_play(p paramsparser.Params) !PostgresClient {
|
||||||
|
mut mycfg := PostgresClient{
|
||||||
|
name: p.get_default('name', 'default')!
|
||||||
|
user: p.get_default('user', 'root')!
|
||||||
|
port: p.get_int_default('port', 5432)!
|
||||||
|
host: p.get_default('host', 'localhost')!
|
||||||
|
password: p.get_default('password', '')!
|
||||||
|
dbname: p.get_default('dbname', 'postgres')!
|
||||||
|
}
|
||||||
|
set(mycfg)!
|
||||||
|
return mycfg
|
||||||
}
|
}
|
||||||
|
|
||||||
fn obj_init(obj_ PostgresClient) !PostgresClient {
|
fn obj_init(obj_ PostgresClient) !PostgresClient {
|
||||||
// never call get here, only thing we can do here is work on object itself
|
// never call get here, only thing we can do here is work on object itself
|
||||||
mut obj := obj_
|
mut obj := obj_
|
||||||
panic('implement')
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut self PostgresClient) db() !pg.DB {
|
||||||
|
// console.print_debug(args)
|
||||||
|
mut db := self.db_ or {
|
||||||
|
mut db_ := pg.connect(
|
||||||
|
host: self.host
|
||||||
|
user: self.user
|
||||||
|
port: self.port
|
||||||
|
password: self.password
|
||||||
|
dbname: self.dbname
|
||||||
|
)!
|
||||||
|
db_
|
||||||
|
}
|
||||||
|
|
||||||
|
return db
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,76 +1,113 @@
|
|||||||
# postgres client
|
# PostgreSQL Client
|
||||||
|
|
||||||
## use hero to work with postgres
|
The PostgreSQL client provides a simple interface to interact with PostgreSQL databases through HeroScript.
|
||||||
|
|
||||||
```bash
|
## Configuration
|
||||||
|
|
||||||
Usage: hero postgres [flags] [commands]
|
The PostgreSQL client can be configured using HeroScript. Configuration settings are stored on the filesystem for future use.
|
||||||
|
|
||||||
manage postgresql
|
### Basic Configuration Example
|
||||||
|
|
||||||
Flags:
|
|
||||||
-help Prints help information.
|
|
||||||
-man Prints the auto-generated manpage.
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
exec execute a query
|
|
||||||
check check the postgresql connection
|
|
||||||
configure configure a postgresl connection.
|
|
||||||
backup backup
|
|
||||||
print print configure info.
|
|
||||||
list list databases
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## configure
|
|
||||||
|
|
||||||
the postgres configuration is stored on the filesystem for further use, can be configured as follows
|
|
||||||
|
|
||||||
```v
|
```v
|
||||||
import freeflowuniverse.herolib.clients.postgres
|
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
|
||||||
|
|
||||||
postgres.configure(name:'default',
|
import freeflowuniverse.herolib.core
|
||||||
user :'root'
|
import os
|
||||||
port : 5432
|
import freeflowuniverse.herolib.clients.postgresql_client
|
||||||
host : 'localhost'
|
|
||||||
password : 'ssss'
|
|
||||||
dbname :'postgres')!
|
|
||||||
|
|
||||||
mut db:=postgres.get(name:'default')!
|
heroscript := "
|
||||||
|
!!postgresql_client.configure
|
||||||
|
name:'test'
|
||||||
|
user: 'root'
|
||||||
|
port: 5432
|
||||||
|
host: 'localhost'
|
||||||
|
password: '1234'
|
||||||
|
dbname: 'postgres'
|
||||||
|
"
|
||||||
|
|
||||||
|
// Process the heroscript
|
||||||
|
postgresql_client.play(heroscript:heroscript)!
|
||||||
|
|
||||||
|
// Get the configured client
|
||||||
|
mut db_client := postgresql_client.get(name:"test")!
|
||||||
|
|
||||||
|
println(db_client)
|
||||||
```
|
```
|
||||||
|
|
||||||
## configure through heroscript
|
### Configuration Parameters
|
||||||
|
|
||||||
|
| Parameter | Description | Default Value |
|
||||||
|
|-----------|-------------|---------------|
|
||||||
|
| name | Unique identifier for this configuration | 'default' |
|
||||||
|
| user | PostgreSQL user | 'root' |
|
||||||
|
| port | PostgreSQL server port | 5432 |
|
||||||
|
| host | PostgreSQL server host | 'localhost' |
|
||||||
|
| password | PostgreSQL user password | '' |
|
||||||
|
| dbname | Default database name | 'postgres' |
|
||||||
|
|
||||||
|
## Database Operations
|
||||||
|
|
||||||
|
### Check Connection
|
||||||
|
|
||||||
```v
|
```v
|
||||||
import freeflowuniverse.herolib.clients.postgres
|
// Check if connection is working
|
||||||
|
db_client.check()!
|
||||||
heroscript:='
|
|
||||||
!!postgresclient.define name:'default'
|
|
||||||
//TO IMPLEMENT
|
|
||||||
'
|
|
||||||
|
|
||||||
|
|
||||||
postgres.configure(heroscript:heroscript)!
|
|
||||||
|
|
||||||
|
|
||||||
//can also be done through get directly
|
|
||||||
mut cl:=postgres.get(reset:true,name:'default',heroscript:heroscript)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Database Management
|
||||||
## some postgresql cmds
|
|
||||||
|
|
||||||
```v
|
```v
|
||||||
import freeflowuniverse.herolib.clients.postgres
|
// Check if database exists
|
||||||
|
exists := db_client.db_exists('mydb')!
|
||||||
|
|
||||||
mut cl:=postgres.get()! //will default get postgres client with name 'default'
|
// Create database
|
||||||
|
db_client.db_create('mydb')!
|
||||||
|
|
||||||
cl.db_exists("mydb")!
|
// Delete database
|
||||||
|
db_client.db_delete('mydb')!
|
||||||
|
|
||||||
|
// List all databases
|
||||||
|
db_names := db_client.db_names()!
|
||||||
```
|
```
|
||||||
|
|
||||||
## use the good module of v
|
### Query Execution
|
||||||
|
|
||||||
- [https://modules.vlang.io/db.pg.html#DB.exec](https://modules.vlang.io/db.pg.html#DB.exec)
|
```v
|
||||||
|
// Execute a query
|
||||||
|
rows := db_client.exec('SELECT * FROM mytable;')!
|
||||||
|
|
||||||
|
// Query without semicolon is automatically appended
|
||||||
|
rows := db_client.exec('SELECT * FROM mytable')!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backup Functionality
|
||||||
|
|
||||||
|
The client provides functionality to backup databases:
|
||||||
|
|
||||||
|
```v
|
||||||
|
// Backup a specific database
|
||||||
|
db_client.backup(dbname: 'mydb', dest: '/path/to/backup/dir')!
|
||||||
|
|
||||||
|
// Backup all databases
|
||||||
|
db_client.backup(dest: '/path/to/backup/dir')!
|
||||||
|
```
|
||||||
|
|
||||||
|
Backups are created in custom PostgreSQL format (.bak files) which can be restored using pg_restore.
|
||||||
|
|
||||||
|
## Default Configuration
|
||||||
|
|
||||||
|
If no configuration is provided, the client uses these default settings:
|
||||||
|
|
||||||
|
```v
|
||||||
|
heroscript := "
|
||||||
|
!!postgresql_client.configure
|
||||||
|
name:'default'
|
||||||
|
user: 'root'
|
||||||
|
port: 5432
|
||||||
|
host: 'localhost'
|
||||||
|
password: ''
|
||||||
|
dbname: 'postgres'
|
||||||
|
"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can override these defaults by providing your own configuration using the HeroScript configure command.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
module rclone
|
module rclone
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
@@ -6,79 +5,66 @@ import freeflowuniverse.herolib.core.playbook
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
rclone_global map[string]&RCloneClient
|
rclone_global map[string]&RCloneClient
|
||||||
rclone_default string
|
rclone_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o RCloneClient) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
//set the model in mem and the config on the filesystem
|
rclone_global[o.name] = &o2
|
||||||
pub fn set(o RCloneClient)! {
|
rclone_default = o.name
|
||||||
mut o2:=obj_init(o)!
|
|
||||||
rclone_global[o.name] = &o2
|
|
||||||
rclone_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("rclone",model.name)
|
return context.hero_config_exists('rclone', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("rclone",model.name)!
|
mut heroscript := context.hero_config_get('rclone', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o RCloneClient)! {
|
pub fn save(o RCloneClient) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[RCloneClient](o)!
|
heroscript := encoderhero.encode[RCloneClient](o)!
|
||||||
context.hero_config_set("rclone",model.name,heroscript)!
|
context.hero_config_set('rclone', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
|
||||||
model.heroscript = heroscript_default()!
|
|
||||||
}
|
|
||||||
mut plbook := model.plbook or {
|
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'rclone.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action rclone.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if model.heroscript == '' {
|
||||||
|
model.heroscript = heroscript_default()!
|
||||||
|
}
|
||||||
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
|
|
||||||
|
mut configure_actions := plbook.find(filter: 'rclone.configure')!
|
||||||
|
if configure_actions.len > 0 {
|
||||||
|
for config_action in configure_actions {
|
||||||
|
mut p := config_action.params
|
||||||
|
mycfg := cfg_play(p)!
|
||||||
|
console.print_debug('install action rclone.configure\n${mycfg}')
|
||||||
|
set(mycfg)!
|
||||||
|
save(mycfg)!
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
|
|
||||||
module sendgrid
|
module sendgrid
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
sendgrid_global map[string]&SendGrid
|
sendgrid_global map[string]&SendGrid
|
||||||
sendgrid_default string
|
sendgrid_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,12 @@
|
|||||||
|
|
||||||
module zerodb_client
|
module zerodb_client
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
zerodb_client_global map[string]&ZeroDBClient
|
zerodb_client_global map[string]&ZeroDBClient
|
||||||
zerodb_client_default string
|
zerodb_client_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub enum Cat {
|
|||||||
installer
|
installer
|
||||||
}
|
}
|
||||||
|
|
||||||
//creates the heroscript from the GenModel as part of GenerateArgs
|
// creates the heroscript from the GenModel as part of GenerateArgs
|
||||||
pub fn gen_model_set(args GenerateArgs) ! {
|
pub fn gen_model_set(args GenerateArgs) ! {
|
||||||
console.print_debug('Code generator set: ${args}')
|
console.print_debug('Code generator set: ${args}')
|
||||||
model := args.model or { return error('model is none') }
|
model := args.model or { return error('model is none') }
|
||||||
@@ -41,7 +41,7 @@ pub fn gen_model_set(args GenerateArgs) ! {
|
|||||||
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
|
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//loads the heroscript and return the model
|
// loads the heroscript and return the model
|
||||||
pub fn gen_model_get(path string, create bool) !GenModel {
|
pub fn gen_model_get(path string, create bool) !GenModel {
|
||||||
console.print_debug('play installer code for path: ${path}')
|
console.print_debug('play installer code for path: ${path}')
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ pub fn get(args_ ArgsGet) !&${model.classname} {
|
|||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in ${model.name}_global) {
|
if !(args.name in ${model.name}_global) {
|
||||||
if args.name=="default"{
|
if args.name=="default"{
|
||||||
if ! config_exists(args){
|
if ! exists!(args){
|
||||||
if default{
|
if default{
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context:=base.context() or { panic("bug") }
|
||||||
context.hero_config_set("${model.name}",model.name,heroscript_default()!)!
|
context.hero_config_set("${model.name}",args.name,heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
@@ -57,7 +57,7 @@ pub fn get(args_ ArgsGet) !&${model.classname} {
|
|||||||
}
|
}
|
||||||
return ${model.name}_global[args.name] or {
|
return ${model.name}_global[args.name] or {
|
||||||
println(${model.name}_global)
|
println(${model.name}_global)
|
||||||
panic("could not get config for ??{args.name} with name:??{model.name}")
|
panic("could not get config for ??{args.name}.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +73,9 @@ pub fn set(o ${model.classname})! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
//check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet)!bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context:=base.context()!
|
||||||
return context.hero_config_exists("${model.name}",model.name)
|
return context.hero_config_exists("${model.name}",model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ pub fn load(args_ ArgsGet) ! {
|
|||||||
pub fn save(o ${model.classname})! {
|
pub fn save(o ${model.classname})! {
|
||||||
mut context:=base.context()!
|
mut context:=base.context()!
|
||||||
heroscript := encoderhero.encode[${model.classname}](o)!
|
heroscript := encoderhero.encode[${model.classname}](o)!
|
||||||
context.hero_config_set("${model.name}",model.name,heroscript)!
|
context.hero_config_set("${model.name}",o.name,heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
^^[params]
|
^^[params]
|
||||||
@@ -272,7 +272,7 @@ pub fn (mut self ${model.classname}) restart() ! {
|
|||||||
pub fn (mut self ${model.classname}) running() !bool {
|
pub fn (mut self ${model.classname}) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
//walk over the generic processes, if not running_ return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()!{
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r:=sm.running(zprocess.name)!
|
||||||
@@ -280,7 +280,7 @@ pub fn (mut self ${model.classname}) running() !bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running_()!
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ pub mut:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@if model.hasconfig
|
@if model.hasconfig
|
||||||
fn cfg_play(p paramsparser.Params) ! {
|
fn cfg_play(p paramsparser.Params) !${model.classname} {
|
||||||
//THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
|
//THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
|
||||||
mut mycfg := ${model.classname}{
|
mut mycfg := ${model.classname}{
|
||||||
name: p.get_default('name', 'default')!
|
name: p.get_default('name', 'default')!
|
||||||
@@ -123,6 +123,7 @@ fn cfg_play(p paramsparser.Params) ! {
|
|||||||
mail_username: p.get('mail_username')!
|
mail_username: p.get('mail_username')!
|
||||||
}
|
}
|
||||||
set(mycfg)!
|
set(mycfg)!
|
||||||
|
return mycfg
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ module core
|
|||||||
|
|
||||||
import base
|
import base
|
||||||
|
|
||||||
//check if we are interactive in current context
|
// check if we are interactive in current context
|
||||||
pub fn interactive()!bool{
|
pub fn interactive() !bool {
|
||||||
mut c:=base.context()!
|
mut c := base.context()!
|
||||||
if c.config.interactive{
|
if c.config.interactive {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interactive_set()!{
|
pub fn interactive_set() ! {
|
||||||
mut c:=base.context()!
|
mut c := base.context()!
|
||||||
c.config.interactive = true
|
c.config.interactive = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,3 @@ fn test_memdb_exists() {
|
|||||||
memdb_set('empty_key', '')
|
memdb_set('empty_key', '')
|
||||||
assert memdb_exists('empty_key') == false
|
assert memdb_exists('empty_key') == false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import os
|
|||||||
// import freeflowuniverse.herolib.ui.console
|
// import freeflowuniverse.herolib.ui.console
|
||||||
// Returns the enum value that matches the provided string for PlatformType
|
// Returns the enum value that matches the provided string for PlatformType
|
||||||
|
|
||||||
|
|
||||||
pub enum PlatformType {
|
pub enum PlatformType {
|
||||||
unknown
|
unknown
|
||||||
osx
|
osx
|
||||||
@@ -25,7 +24,6 @@ pub fn platform_enum_from_string(platform string) PlatformType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns the enum value that matches the provided string for CPUType
|
// Returns the enum value that matches the provided string for CPUType
|
||||||
pub fn cputype_enum_from_string(cputype string) CPUType {
|
pub fn cputype_enum_from_string(cputype string) CPUType {
|
||||||
return match cputype.to_lower() {
|
return match cputype.to_lower() {
|
||||||
@@ -54,7 +52,7 @@ pub fn cmd_exists(cmd string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn platform()! PlatformType {
|
pub fn platform() !PlatformType {
|
||||||
mut platform_ := PlatformType.unknown
|
mut platform_ := PlatformType.unknown
|
||||||
platform_ = platform_enum_from_string(memdb_get('platformtype'))
|
platform_ = platform_enum_from_string(memdb_get('platformtype'))
|
||||||
if platform_ != PlatformType.unknown {
|
if platform_ != PlatformType.unknown {
|
||||||
@@ -77,18 +75,18 @@ pub fn platform()! PlatformType {
|
|||||||
return platform_
|
return platform_
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cputype()! CPUType {
|
pub fn cputype() !CPUType {
|
||||||
mut cputype_ := CPUType.unknown
|
mut cputype_ := CPUType.unknown
|
||||||
cputype_ = cputype_enum_from_string(memdb_get('cputype'))
|
cputype_ = cputype_enum_from_string(memdb_get('cputype'))
|
||||||
if cputype_ != CPUType.unknown {
|
if cputype_ != CPUType.unknown {
|
||||||
return cputype_
|
return cputype_
|
||||||
}
|
}
|
||||||
res := os.execute('uname -m')
|
res := os.execute('uname -m')
|
||||||
if res.exit_code >0{
|
if res.exit_code > 0 {
|
||||||
return error("can't execute uname -m")
|
return error("can't execute uname -m")
|
||||||
}
|
}
|
||||||
sys_info := res.output
|
sys_info := res.output
|
||||||
|
|
||||||
cputype_ = match sys_info.to_lower().trim_space() {
|
cputype_ = match sys_info.to_lower().trim_space() {
|
||||||
'x86_64' {
|
'x86_64' {
|
||||||
CPUType.intel
|
CPUType.intel
|
||||||
@@ -110,37 +108,37 @@ pub fn cputype()! CPUType {
|
|||||||
return cputype_
|
return cputype_
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_osx()! bool {
|
pub fn is_osx() !bool {
|
||||||
return platform()! == .osx
|
return platform()! == .osx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_osx_arm()! bool {
|
pub fn is_osx_arm() !bool {
|
||||||
return platform()! == .osx && cputype()! == .arm
|
return platform()! == .osx && cputype()! == .arm
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_osx_intel()! bool {
|
pub fn is_osx_intel() !bool {
|
||||||
return platform()! == .osx && cputype()! == .intel
|
return platform()! == .osx && cputype()! == .intel
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_ubuntu()! bool {
|
pub fn is_ubuntu() !bool {
|
||||||
return platform()! == .ubuntu
|
return platform()! == .ubuntu
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_linux()! bool {
|
pub fn is_linux() !bool {
|
||||||
return platform()! == .ubuntu || platform()! == .arch || platform()! == .suse
|
return platform()! == .ubuntu || platform()! == .arch || platform()! == .suse
|
||||||
|| platform()! == .alpine
|
|| platform()! == .alpine
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_linux_arm()!bool {
|
pub fn is_linux_arm() !bool {
|
||||||
// console.print_debug("islinux:${is_linux()!} cputype:${cputype()!}")
|
// console.print_debug("islinux:${is_linux()!} cputype:${cputype()!}")
|
||||||
return is_linux()! && cputype()! == .arm
|
return is_linux()! && cputype()! == .arm
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_linux_intel()! bool {
|
pub fn is_linux_intel() !bool {
|
||||||
return is_linux()! && cputype()! == .intel
|
return is_linux()! && cputype()! == .intel
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hostname()!string {
|
pub fn hostname() !string {
|
||||||
res := os.execute('hostname')
|
res := os.execute('hostname')
|
||||||
if res.exit_code > 0 {
|
if res.exit_code > 0 {
|
||||||
return error("can't get hostname. Error.")
|
return error("can't get hostname. Error.")
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
module core
|
module core
|
||||||
|
|
||||||
fn test_platform()! {
|
fn test_platform() ! {
|
||||||
assert platform()! != .unknown
|
assert platform()! != .unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_cputype()! {
|
fn test_cputype() ! {
|
||||||
assert cputype()! != .unknown
|
assert cputype()! != .unknown
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,19 @@ And CPU architectures:
|
|||||||
|
|
||||||
The core module provides essential functionality used by other Hero framework components. Key features include:
|
The core module provides essential functionality used by other Hero framework components. Key features include:
|
||||||
|
|
||||||
|
### Interactivity Check & Influence on delete
|
||||||
|
|
||||||
|
```
|
||||||
|
import freeflowuniverse.herolib.installers.lang.golang
|
||||||
|
import freeflowuniverse.herolib.core
|
||||||
|
|
||||||
|
core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights
|
||||||
|
|
||||||
|
//this will allow files which are in sudo area to still get them removed but its important interactive is set on the context.
|
||||||
|
golang.install(reset:false)!
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Platform Detection
|
### Platform Detection
|
||||||
```v
|
```v
|
||||||
// Check platform type
|
// Check platform type
|
||||||
@@ -74,13 +87,41 @@ value := core.memdb_get('key')
|
|||||||
|
|
||||||
### Sudo Operations
|
### Sudo Operations
|
||||||
|
|
||||||
|
The sudo operations module provides comprehensive permission management and command elevation handling:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
// Check sudo requirements
|
// Check if sudo is required for the current user
|
||||||
if core.sudo_required()! {
|
if core.sudo_required()! {
|
||||||
// Handle sudo requirements
|
// Handle sudo requirements
|
||||||
|
// Returns false if user is root or on macOS
|
||||||
|
// Returns true if user has sudo privileges
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify path permissions
|
// Verify path permissions and accessibility
|
||||||
path := core.sudo_path_check('/protected/path', true)!
|
path := core.sudo_path_check('/path/to/check')! {
|
||||||
```
|
// Returns the path if accessible
|
||||||
|
// Errors if path requires sudo rights
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a path is accessible without sudo
|
||||||
|
if core.sudo_path_ok('/usr/local/bin')! {
|
||||||
|
// Returns false for protected directories like:
|
||||||
|
// /usr/, /boot, /etc, /root/
|
||||||
|
// Returns true if path is accessible
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check and modify commands that require sudo
|
||||||
|
cmd := core.sudo_cmd_check('ufw enable')! {
|
||||||
|
// Automatically adds 'sudo' prefix if:
|
||||||
|
// 1. Command requires elevated privileges
|
||||||
|
// 2. User doesn't have sudo rights
|
||||||
|
// 3. Running in interactive mode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if current process has sudo rights
|
||||||
|
if core.sudo_rights_check()! {
|
||||||
|
// Returns true if:
|
||||||
|
// - Running as root user
|
||||||
|
// - Has necessary sudo privileges
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -3,23 +3,23 @@ module core
|
|||||||
import base
|
import base
|
||||||
import os
|
import os
|
||||||
|
|
||||||
//check path is accessible, e.g. do we need sudo and are we sudo
|
// check path is accessible, e.g. do we need sudo and are we sudo
|
||||||
// if ok then will just return the same path string as output
|
// if ok then will just return the same path string as output
|
||||||
pub fn sudo_path_check(path string)!string{
|
pub fn sudo_path_check(path string) !string {
|
||||||
if sudo_path_ok(path)!{
|
if sudo_path_ok(path)! {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
return error("Can't write/delete path:${path} because of no rights.")
|
return error("Can't write/delete path:${path} because of no rights.")
|
||||||
}
|
}
|
||||||
|
|
||||||
//return false if we can't work on the path
|
// return false if we can't work on the path
|
||||||
pub fn sudo_path_ok(path string)!bool{
|
pub fn sudo_path_ok(path string) !bool {
|
||||||
if sudo_rights_check()!{
|
if sudo_rights_check()! {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Check if path is in protected directories
|
// Check if path is in protected directories
|
||||||
for item in ["/usr/","/boot","/etc","/root/"]{
|
for item in ['/usr/', '/boot', '/etc', '/root/'] {
|
||||||
if path.starts_with(item){
|
if path.starts_with(item) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,23 +27,20 @@ pub fn sudo_path_ok(path string)!bool{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we know cmd requires sudo rights
|
||||||
//if we know cmd requires sudo rights
|
pub fn sudo_cmd(cmd string) !bool {
|
||||||
pub fn sudo_cmd(cmd string)!bool{
|
cmd2 := cmd.split(' ')[0]
|
||||||
cmd2:=cmd.split(" ")[0]
|
if cmd2 == 'ufw' {
|
||||||
if cmd2 in [
|
|
||||||
"ufw"
|
|
||||||
] {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//TODO: need many more checks
|
// TODO: need many more checks
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//if sudo required and we are interactive then we will put sudo in front of returned cmd
|
// if sudo required and we are interactive then we will put sudo in front of returned cmd
|
||||||
pub fn sudo_cmd_check(cmd string)!string{
|
pub fn sudo_cmd_check(cmd string) !string {
|
||||||
// If we have sudo rights, no need to add sudo prefix
|
// If we have sudo rights, no need to add sudo prefix
|
||||||
if sudo_rights_check()!{
|
if sudo_rights_check()! {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,29 +51,27 @@ pub fn sudo_cmd_check(cmd string)!string{
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
if interactive()!{
|
if interactive()! {
|
||||||
return "sudo ${cmd}"
|
return 'sudo ${cmd}'
|
||||||
}
|
}
|
||||||
|
|
||||||
return error("can't execute the cmd, because no sudo rights.\ncmd:'${cmd}'")
|
return error("can't execute the cmd, because no sudo rights.\ncmd:'${cmd}'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check of we have sudo rights, if yes return true
|
||||||
|
pub fn sudo_rights_check() !bool {
|
||||||
//check of we have sudo rights, if yes return true
|
|
||||||
pub fn sudo_rights_check() ! bool {
|
|
||||||
// Check if the user is root
|
// Check if the user is root
|
||||||
if os.getenv('USER') == 'root' {
|
if os.getenv('USER') == 'root' {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
//TOOD: we can do more
|
// TOOD: we can do more
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to check if sudo is required (i.e., if the user is root or has sudo privileges)
|
// Method to check if sudo is required (i.e., if the user is root or has sudo privileges)
|
||||||
pub fn sudo_required()!bool {
|
pub fn sudo_required() !bool {
|
||||||
// Check if the user is root
|
// Check if the user is root
|
||||||
if sudo_rights_check()!{
|
if sudo_rights_check()! {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
platform_ := platform()!
|
platform_ := platform()!
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module core
|
module core
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import base
|
import base
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ fn init_context() ! {
|
|||||||
c.save()!
|
c.save()!
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_sudo_required()! {
|
fn test_sudo_required() ! {
|
||||||
init_context()!
|
init_context()!
|
||||||
// Test if sudo requirement detection works
|
// Test if sudo requirement detection works
|
||||||
required := sudo_required()!
|
required := sudo_required()!
|
||||||
@@ -35,33 +36,30 @@ fn test_sudo_path_ok() {
|
|||||||
fn test_sudo_path_protected() {
|
fn test_sudo_path_protected() {
|
||||||
init_context()!
|
init_context()!
|
||||||
// Test path permission checks for protected paths
|
// Test path permission checks for protected paths
|
||||||
p := "/usr/local"
|
p := '/usr/local'
|
||||||
|
|
||||||
// Protected paths should require sudo
|
// Protected paths should require sudo
|
||||||
assert sudo_path_ok(p)! == false
|
assert sudo_path_ok(p)! == false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn test_sudo_cmd_check() {
|
fn test_sudo_cmd_check() {
|
||||||
init_context()!
|
init_context()!
|
||||||
assert interactive()!, 'interactive mode should be set'
|
assert interactive()!, 'interactive mode should be set'
|
||||||
|
|
||||||
// Test command sudo requirement checking for non-sudo command
|
// Test command sudo requirement checking for non-sudo command
|
||||||
cmd := 'echo test'
|
cmd := 'echo test'
|
||||||
|
|
||||||
result := sudo_cmd_check(cmd)!
|
result := sudo_cmd_check(cmd)!
|
||||||
assert result == cmd
|
assert result == cmd
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_sudo_cmd_check_sudo_required()! {
|
fn test_sudo_cmd_check_sudo_required() ! {
|
||||||
init_context()!
|
init_context()!
|
||||||
assert interactive()!, 'interactive mode should be set'
|
assert interactive()!, 'interactive mode should be set'
|
||||||
|
|
||||||
// Test command sudo requirement checking for sudo-required command
|
// Test command sudo requirement checking for sudo-required command
|
||||||
cmd := 'ufw something'
|
cmd := 'ufw something'
|
||||||
|
|
||||||
result := sudo_cmd_check(cmd)!
|
result := sudo_cmd_check(cmd)!
|
||||||
assert result == 'sudo ${cmd}'
|
assert result == 'sudo ${cmd}'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,21 +120,21 @@ fn (mut parser Parser) next() {
|
|||||||
// move further and reset the state
|
// move further and reset the state
|
||||||
fn (mut parser Parser) next_start() ! {
|
fn (mut parser Parser) next_start() ! {
|
||||||
// means we need to add paragraph because we don't know what comes next
|
// means we need to add paragraph because we don't know what comes next
|
||||||
if parser.doc.last()!is elements.Paragraph {
|
if parser.doc.last() !is elements.Paragraph {
|
||||||
parser.doc.paragraph_new(mut parser.doc, '')
|
parser.doc.paragraph_new(mut parser.doc, '')
|
||||||
}
|
}
|
||||||
parser.next()
|
parser.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut parser Parser) next_start_lf() ! {
|
fn (mut parser Parser) next_start_lf() ! {
|
||||||
if parser.doc.last()!is elements.Paragraph {
|
if parser.doc.last() !is elements.Paragraph {
|
||||||
parser.doc.paragraph_new(mut parser.doc, '\n')
|
parser.doc.paragraph_new(mut parser.doc, '\n')
|
||||||
}
|
}
|
||||||
parser.next()
|
parser.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut parser Parser) ensure_last_is_paragraph() ! {
|
fn (mut parser Parser) ensure_last_is_paragraph() ! {
|
||||||
if parser.doc.last()!is elements.Paragraph {
|
if parser.doc.last() !is elements.Paragraph {
|
||||||
parser.doc.paragraph_new(mut parser.doc, '')
|
parser.doc.paragraph_new(mut parser.doc, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ pub fn redis_install(args_ RedisInstallArgs) ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn configfilepath(args RedisInstallArgs) string {
|
fn configfilepath(args RedisInstallArgs) string {
|
||||||
if core.is_linux() or {panic(err)} {
|
if core.is_linux() or { panic(err) } {
|
||||||
return '/etc/redis/redis.conf'
|
return '/etc/redis/redis.conf'
|
||||||
} else {
|
} else {
|
||||||
return '${args.datadir}/redis.conf'
|
return '${args.datadir}/redis.conf'
|
||||||
|
|||||||
@@ -1,301 +1,281 @@
|
|||||||
|
|
||||||
module meilisearchinstaller
|
module meilisearchinstaller
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
meilisearchinstaller_global map[string]&MeilisearchServer
|
meilisearchinstaller_global map[string]&MeilisearchServer
|
||||||
meilisearchinstaller_default string
|
meilisearchinstaller_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = meilisearchinstaller_default
|
model.name = meilisearchinstaller_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&MeilisearchServer {
|
pub fn get(args_ ArgsGet) !&MeilisearchServer {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in meilisearchinstaller_global) {
|
if args.name !in meilisearchinstaller_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("meilisearchinstaller",model.name,heroscript_default()!)!
|
context.hero_config_set('meilisearchinstaller', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meilisearchinstaller_global[args.name] or {
|
return meilisearchinstaller_global[args.name] or {
|
||||||
println(meilisearchinstaller_global)
|
println(meilisearchinstaller_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o MeilisearchServer) ! {
|
||||||
//set the model in mem and the config on the filesystem
|
mut o2 := obj_init(o)!
|
||||||
pub fn set(o MeilisearchServer)! {
|
meilisearchinstaller_global[o.name] = &o2
|
||||||
mut o2:=obj_init(o)!
|
meilisearchinstaller_default = o.name
|
||||||
meilisearchinstaller_global[o.name] = &o2
|
|
||||||
meilisearchinstaller_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("meilisearchinstaller",model.name)
|
return context.hero_config_exists('meilisearchinstaller', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("meilisearchinstaller",model.name)!
|
mut heroscript := context.hero_config_get('meilisearchinstaller', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o MeilisearchServer)! {
|
pub fn save(o MeilisearchServer) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[MeilisearchServer](o)!
|
heroscript := encoderhero.encode[MeilisearchServer](o)!
|
||||||
context.hero_config_set("meilisearchinstaller",model.name,heroscript)!
|
context.hero_config_set('meilisearchinstaller', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
if model.heroscript == '' {
|
||||||
model.heroscript = heroscript_default()!
|
model.heroscript = heroscript_default()!
|
||||||
}
|
}
|
||||||
mut plbook := model.plbook or {
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action meilisearchinstaller.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
|
mut configure_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
|
||||||
for other_action in other_actions {
|
if configure_actions.len > 0 {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
for config_action in configure_actions {
|
||||||
mut p := other_action.params
|
mut p := config_action.params
|
||||||
reset:=p.get_default_false("reset")
|
mycfg := cfg_play(p)!
|
||||||
if other_action.name == "destroy" || reset{
|
console.print_debug('install action meilisearchinstaller.configure\n${mycfg}')
|
||||||
console.print_debug("install action meilisearchinstaller.destroy")
|
set(mycfg)!
|
||||||
destroy_()!
|
save(mycfg)!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
}
|
||||||
console.print_debug("install action meilisearchinstaller.install")
|
|
||||||
install_()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if other_action.name in ["start","stop","restart"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut meilisearchinstaller_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n${meilisearchinstaller_obj}")
|
|
||||||
if other_action.name == "start"{
|
|
||||||
console.print_debug("install action meilisearchinstaller.${other_action.name}")
|
|
||||||
meilisearchinstaller_obj.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
if other_action.name == "stop"{
|
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
|
||||||
console.print_debug("install action meilisearchinstaller.${other_action.name}")
|
for other_action in other_actions {
|
||||||
meilisearchinstaller_obj.stop()!
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
}
|
mut p := other_action.params
|
||||||
if other_action.name == "restart"{
|
reset := p.get_default_false('reset')
|
||||||
console.print_debug("install action meilisearchinstaller.${other_action.name}")
|
if other_action.name == 'destroy' || reset {
|
||||||
meilisearchinstaller_obj.restart()!
|
console.print_debug('install action meilisearchinstaller.destroy')
|
||||||
}
|
destroy_()!
|
||||||
}
|
}
|
||||||
}
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action meilisearchinstaller.install')
|
||||||
|
install_()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut meilisearchinstaller_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${meilisearchinstaller_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action meilisearchinstaller.${other_action.name}')
|
||||||
|
meilisearchinstaller_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action meilisearchinstaller.${other_action.name}')
|
||||||
|
meilisearchinstaller_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action meilisearchinstaller.${other_action.name}')
|
||||||
|
meilisearchinstaller_obj.restart()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self MeilisearchServer) reload() ! {
|
pub fn (mut self MeilisearchServer) reload() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self=obj_init(self)!
|
self = obj_init(self)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) start() ! {
|
pub fn (mut self MeilisearchServer) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('meilisearchinstaller start')
|
console.print_header('meilisearchinstaller start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...')
|
console.print_debug('starting meilisearchinstaller with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('meilisearchinstaller did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('meilisearchinstaller did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) install_start(model InstallArgs) ! {
|
pub fn (mut self MeilisearchServer) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) stop() ! {
|
pub fn (mut self MeilisearchServer) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) restart() ! {
|
pub fn (mut self MeilisearchServer) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) running() !bool {
|
pub fn (mut self MeilisearchServer) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for meilisearchinstaller
|
||||||
//switch instance to be used for meilisearchinstaller
|
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
meilisearchinstaller_default = name
|
meilisearchinstaller_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) install(args InstallArgs) ! {
|
pub fn (mut self MeilisearchServer) install(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) build() ! {
|
pub fn (mut self MeilisearchServer) build() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MeilisearchServer) destroy() ! {
|
pub fn (mut self MeilisearchServer) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop() or {}
|
self.stop() or {}
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,252 +1,232 @@
|
|||||||
|
|
||||||
module postgresql
|
module postgresql
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
postgresql_global map[string]&Postgresql
|
postgresql_global map[string]&Postgresql
|
||||||
postgresql_default string
|
postgresql_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o Postgresql) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
//set the model in mem and the config on the filesystem
|
postgresql_global[o.name] = &o2
|
||||||
pub fn set(o Postgresql)! {
|
postgresql_default = o.name
|
||||||
mut o2:=obj_init(o)!
|
|
||||||
postgresql_global[o.name] = &o2
|
|
||||||
postgresql_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("postgresql",model.name)
|
return context.hero_config_exists('postgresql', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("postgresql",model.name)!
|
mut heroscript := context.hero_config_get('postgresql', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o Postgresql)! {
|
pub fn save(o Postgresql) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[Postgresql](o)!
|
heroscript := encoderhero.encode[Postgresql](o)!
|
||||||
context.hero_config_set("postgresql",model.name,heroscript)!
|
context.hero_config_set('postgresql', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
if model.heroscript == '' {
|
||||||
model.heroscript = heroscript_default()!
|
model.heroscript = heroscript_default()!
|
||||||
}
|
}
|
||||||
mut plbook := model.plbook or {
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'postgresql.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action postgresql.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'postgresql.')!
|
mut configure_actions := plbook.find(filter: 'postgresql.configure')!
|
||||||
for other_action in other_actions {
|
if configure_actions.len > 0 {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
for config_action in configure_actions {
|
||||||
mut p := other_action.params
|
mut p := config_action.params
|
||||||
reset:=p.get_default_false("reset")
|
mycfg := cfg_play(p)!
|
||||||
if other_action.name == "destroy" || reset{
|
console.print_debug('install action postgresql.configure\n${mycfg}')
|
||||||
console.print_debug("install action postgresql.destroy")
|
set(mycfg)!
|
||||||
destroy_()!
|
save(mycfg)!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
}
|
||||||
console.print_debug("install action postgresql.install")
|
|
||||||
install_()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if other_action.name in ["start","stop","restart"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut postgresql_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n${postgresql_obj}")
|
|
||||||
if other_action.name == "start"{
|
|
||||||
console.print_debug("install action postgresql.${other_action.name}")
|
|
||||||
postgresql_obj.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
if other_action.name == "stop"{
|
mut other_actions := plbook.find(filter: 'postgresql.')!
|
||||||
console.print_debug("install action postgresql.${other_action.name}")
|
for other_action in other_actions {
|
||||||
postgresql_obj.stop()!
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
}
|
mut p := other_action.params
|
||||||
if other_action.name == "restart"{
|
reset := p.get_default_false('reset')
|
||||||
console.print_debug("install action postgresql.${other_action.name}")
|
if other_action.name == 'destroy' || reset {
|
||||||
postgresql_obj.restart()!
|
console.print_debug('install action postgresql.destroy')
|
||||||
}
|
destroy_()!
|
||||||
}
|
}
|
||||||
}
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action postgresql.install')
|
||||||
|
install_()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut postgresql_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${postgresql_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action postgresql.${other_action.name}')
|
||||||
|
postgresql_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action postgresql.${other_action.name}')
|
||||||
|
postgresql_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action postgresql.${other_action.name}')
|
||||||
|
postgresql_obj.restart()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self Postgresql) reload() ! {
|
pub fn (mut self Postgresql) reload() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self=obj_init(self)!
|
self = obj_init(self)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Postgresql) start() ! {
|
pub fn (mut self Postgresql) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('postgresql start')
|
console.print_header('postgresql start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting postgresql with ${zprocess.startuptype}...')
|
console.print_debug('starting postgresql with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('postgresql did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('postgresql did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Postgresql) install_start(model InstallArgs) ! {
|
pub fn (mut self Postgresql) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Postgresql) stop() ! {
|
pub fn (mut self Postgresql) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Postgresql) restart() ! {
|
pub fn (mut self Postgresql) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Postgresql) running() !bool {
|
pub fn (mut self Postgresql) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module zerodb
|
module zerodb
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
zerodb_global map[string]&ZeroDB
|
zerodb_global map[string]&ZeroDB
|
||||||
zerodb_default string
|
zerodb_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroDB) start() ! {
|
pub fn (mut self ZeroDB) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('zerodb start')
|
console.print_header('zerodb start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting zerodb with ${zprocess.startuptype}...')
|
console.print_debug('starting zerodb with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('zerodb did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('zerodb did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroDB) install_start(model InstallArgs) ! {
|
pub fn (mut self ZeroDB) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroDB) stop() ! {
|
pub fn (mut self ZeroDB) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroDB) restart() ! {
|
pub fn (mut self ZeroDB) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroDB) running() !bool {
|
pub fn (mut self ZeroDB) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module zerofs
|
module zerofs
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
zerofs_global map[string]&ZeroFS
|
zerofs_global map[string]&ZeroFS
|
||||||
zerofs_default string
|
zerofs_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroFS) start() ! {
|
pub fn (mut self ZeroFS) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('zerofs start')
|
console.print_header('zerofs start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting zerofs with ${zprocess.startuptype}...')
|
console.print_debug('starting zerofs with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('zerofs did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('zerofs did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroFS) install_start(model InstallArgs) ! {
|
pub fn (mut self ZeroFS) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroFS) stop() ! {
|
pub fn (mut self ZeroFS) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroFS) restart() ! {
|
pub fn (mut self ZeroFS) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZeroFS) running() !bool {
|
pub fn (mut self ZeroFS) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,198 +6,183 @@ import freeflowuniverse.herolib.core.texttools
|
|||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
import freeflowuniverse.herolib.installers.ulist
|
import freeflowuniverse.herolib.installers.ulist
|
||||||
import freeflowuniverse.herolib.installers.base
|
import freeflowuniverse.herolib.installers.base
|
||||||
|
|
||||||
import freeflowuniverse.herolib.osal.systemd
|
import freeflowuniverse.herolib.osal.systemd
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
|
|
||||||
import freeflowuniverse.herolib.installers.lang.golang
|
import freeflowuniverse.herolib.installers.lang.golang
|
||||||
import freeflowuniverse.herolib.installers.lang.rust
|
import freeflowuniverse.herolib.installers.lang.rust
|
||||||
import freeflowuniverse.herolib.installers.lang.python
|
import freeflowuniverse.herolib.installers.lang.python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
fn startupcmd () ![]zinit.ZProcessNewArgs{
|
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||||
mut installer := get()!
|
mut installer := get()!
|
||||||
mut res := []zinit.ZProcessNewArgs{}
|
mut res := []zinit.ZProcessNewArgs{}
|
||||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||||
// res << zinit.ZProcessNewArgs{
|
// res << zinit.ZProcessNewArgs{
|
||||||
// name: 'gitea'
|
// name: 'gitea'
|
||||||
// cmd: 'gitea server'
|
// cmd: 'gitea server'
|
||||||
// env: {
|
// env: {
|
||||||
// 'HOME': '/root'
|
// 'HOME': '/root'
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn running_() !bool {
|
fn running_() !bool {
|
||||||
mut installer := get()!
|
mut installer := get()!
|
||||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||||
// this checks health of gitea
|
// this checks health of gitea
|
||||||
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
|
// curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
|
||||||
// url:='http://127.0.0.1:${cfg.port}/api/v1'
|
// url:='http://127.0.0.1:${cfg.port}/api/v1'
|
||||||
// mut conn := httpconnection.new(name: 'gitea', url: url)!
|
// mut conn := httpconnection.new(name: 'gitea', url: url)!
|
||||||
|
|
||||||
// if cfg.secret.len > 0 {
|
// if cfg.secret.len > 0 {
|
||||||
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
|
// conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
|
||||||
// }
|
// }
|
||||||
// conn.default_header.add(.content_type, 'application/json')
|
// conn.default_header.add(.content_type, 'application/json')
|
||||||
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
|
// console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
|
||||||
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
|
// r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
|
||||||
// println(r)
|
// println(r)
|
||||||
// if true{panic("ssss")}
|
// if true{panic("ssss")}
|
||||||
// tags := r['Tags'] or { return false }
|
// tags := r['Tags'] or { return false }
|
||||||
// console.print_debug(tags)
|
// console.print_debug(tags)
|
||||||
// console.print_debug('gitea is answering.')
|
// console.print_debug('gitea is answering.')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_pre()!{
|
fn start_pre() ! {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_post()!{
|
fn start_post() ! {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_pre()!{
|
fn stop_pre() ! {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_post()!{
|
fn stop_post() ! {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////// following actions are not specific to instance of the object
|
//////////////////// following actions are not specific to instance of the object
|
||||||
|
|
||||||
// checks if a certain version or above is installed
|
// checks if a certain version or above is installed
|
||||||
fn installed_() !bool {
|
fn installed_() !bool {
|
||||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||||
// res := os.execute('${osal.profile_path_source_and()!} gitea version')
|
// res := os.execute('${osal.profile_path_source_and()!} gitea version')
|
||||||
// if res.exit_code != 0 {
|
// if res.exit_code != 0 {
|
||||||
// return false
|
// return false
|
||||||
// }
|
// }
|
||||||
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||||
// if r.len != 1 {
|
// if r.len != 1 {
|
||||||
// return error("couldn't parse gitea version.\n${res.output}")
|
// return error("couldn't parse gitea version.\n${res.output}")
|
||||||
// }
|
// }
|
||||||
// if texttools.version(version) == texttools.version(r[0]) {
|
// if texttools.version(version) == texttools.version(r[0]) {
|
||||||
// return true
|
// return true
|
||||||
// }
|
// }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the Upload List of the files
|
// get the Upload List of the files
|
||||||
fn ulist_get() !ulist.UList {
|
fn ulist_get() !ulist.UList {
|
||||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||||
return ulist.UList{}
|
return ulist.UList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//uploads to S3 server if configured
|
// uploads to S3 server if configured
|
||||||
fn upload_() ! {
|
fn upload_() ! {
|
||||||
// installers.upload(
|
// installers.upload(
|
||||||
// cmdname: 'gitea'
|
// cmdname: 'gitea'
|
||||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/gitea'
|
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/gitea'
|
||||||
// )!
|
// )!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_() ! {
|
fn install_() ! {
|
||||||
console.print_header('install gitea')
|
console.print_header('install gitea')
|
||||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
// THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||||
// mut url := ''
|
// mut url := ''
|
||||||
// if core.is_linux_arm()! {
|
// if core.is_linux_arm()! {
|
||||||
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_arm64.tar.gz'
|
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_arm64.tar.gz'
|
||||||
// } else if core.is_linux_intel()! {
|
// } else if core.is_linux_intel()! {
|
||||||
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_amd64.tar.gz'
|
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_linux_amd64.tar.gz'
|
||||||
// } else if core.is_osx_arm()! {
|
// } else if core.is_osx_arm()! {
|
||||||
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_arm64.tar.gz'
|
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_arm64.tar.gz'
|
||||||
// } else if core.is_osx_intel()! {
|
// } else if core.is_osx_intel()! {
|
||||||
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_amd64.tar.gz'
|
// url = 'https://github.com/gitea-dev/gitea/releases/download/v${version}/gitea_${version}_darwin_amd64.tar.gz'
|
||||||
// } else {
|
// } else {
|
||||||
// return error('unsported platform')
|
// return error('unsported platform')
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// mut dest := osal.download(
|
// mut dest := osal.download(
|
||||||
// url: url
|
// url: url
|
||||||
// minsize_kb: 9000
|
// minsize_kb: 9000
|
||||||
// expand_dir: '/tmp/gitea'
|
// expand_dir: '/tmp/gitea'
|
||||||
// )!
|
// )!
|
||||||
|
|
||||||
// //dest.moveup_single_subdir()!
|
// //dest.moveup_single_subdir()!
|
||||||
|
|
||||||
// mut binpath := dest.file_get('gitea')!
|
// mut binpath := dest.file_get('gitea')!
|
||||||
// osal.cmd_add(
|
// osal.cmd_add(
|
||||||
// cmdname: 'gitea'
|
// cmdname: 'gitea'
|
||||||
// source: binpath.path
|
// source: binpath.path
|
||||||
// )!
|
// )!
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_() ! {
|
fn build_() ! {
|
||||||
//url := 'https://github.com/threefoldtech/gitea'
|
// url := 'https://github.com/threefoldtech/gitea'
|
||||||
|
|
||||||
// make sure we install base on the node
|
// make sure we install base on the node
|
||||||
// if core.platform()!= .ubuntu {
|
// if core.platform()!= .ubuntu {
|
||||||
// return error('only support ubuntu for now')
|
// return error('only support ubuntu for now')
|
||||||
// }
|
// }
|
||||||
// golang.install()!
|
// golang.install()!
|
||||||
|
|
||||||
// console.print_header('build gitea')
|
// console.print_header('build gitea')
|
||||||
|
|
||||||
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
|
// gitpath := gittools.get_repo(coderoot: '/tmp/builder', url: url, reset: true, pull: true)!
|
||||||
|
|
||||||
// cmd := '
|
|
||||||
// cd ${gitpath}
|
|
||||||
// source ~/.cargo/env
|
|
||||||
// exit 1 #todo
|
|
||||||
// '
|
|
||||||
// osal.execute_stdout(cmd)!
|
|
||||||
//
|
|
||||||
// //now copy to the default bin path
|
|
||||||
// mut binpath := dest.file_get('...')!
|
|
||||||
// adds it to path
|
|
||||||
// osal.cmd_add(
|
|
||||||
// cmdname: 'griddriver2'
|
|
||||||
// source: binpath.path
|
|
||||||
// )!
|
|
||||||
|
|
||||||
|
// cmd := '
|
||||||
|
// cd ${gitpath}
|
||||||
|
// source ~/.cargo/env
|
||||||
|
// exit 1 #todo
|
||||||
|
// '
|
||||||
|
// osal.execute_stdout(cmd)!
|
||||||
|
//
|
||||||
|
// //now copy to the default bin path
|
||||||
|
// mut binpath := dest.file_get('...')!
|
||||||
|
// adds it to path
|
||||||
|
// osal.cmd_add(
|
||||||
|
// cmdname: 'griddriver2'
|
||||||
|
// source: binpath.path
|
||||||
|
// )!
|
||||||
}
|
}
|
||||||
|
|
||||||
fn destroy_() ! {
|
fn destroy_() ! {
|
||||||
|
// mut systemdfactory := systemd.new()!
|
||||||
|
// systemdfactory.destroy("zinit")!
|
||||||
|
|
||||||
// mut systemdfactory := systemd.new()!
|
// osal.process_kill_recursive(name:'zinit')!
|
||||||
// systemdfactory.destroy("zinit")!
|
// osal.cmd_delete('zinit')!
|
||||||
|
|
||||||
// osal.process_kill_recursive(name:'zinit')!
|
// osal.package_remove('
|
||||||
// osal.cmd_delete('zinit')!
|
// podman
|
||||||
|
// conmon
|
||||||
// osal.package_remove('
|
// buildah
|
||||||
// podman
|
// skopeo
|
||||||
// conmon
|
// runc
|
||||||
// buildah
|
// ')!
|
||||||
// skopeo
|
|
||||||
// runc
|
|
||||||
// ')!
|
|
||||||
|
|
||||||
// //will remove all paths where go/bin is found
|
|
||||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
|
||||||
|
|
||||||
// osal.rm("
|
|
||||||
// podman
|
|
||||||
// conmon
|
|
||||||
// buildah
|
|
||||||
// skopeo
|
|
||||||
// runc
|
|
||||||
// /var/lib/containers
|
|
||||||
// /var/lib/podman
|
|
||||||
// /var/lib/buildah
|
|
||||||
// /tmp/podman
|
|
||||||
// /tmp/conmon
|
|
||||||
// ")!
|
|
||||||
|
|
||||||
|
// //will remove all paths where go/bin is found
|
||||||
|
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||||
|
|
||||||
|
// osal.rm("
|
||||||
|
// podman
|
||||||
|
// conmon
|
||||||
|
// buildah
|
||||||
|
// skopeo
|
||||||
|
// runc
|
||||||
|
// /var/lib/containers
|
||||||
|
// /var/lib/podman
|
||||||
|
// /var/lib/buildah
|
||||||
|
// /tmp/podman
|
||||||
|
// /tmp/conmon
|
||||||
|
// ")!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module gitea
|
module gitea
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
gitea_global map[string]&GiteaInstaller
|
gitea_global map[string]&GiteaInstaller
|
||||||
gitea_default string
|
gitea_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GiteaInstaller) start() ! {
|
pub fn (mut self GiteaInstaller) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('gitea start')
|
console.print_header('gitea start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting gitea with ${zprocess.startuptype}...')
|
console.print_debug('starting gitea with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('gitea did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('gitea did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GiteaInstaller) install_start(model InstallArgs) ! {
|
pub fn (mut self GiteaInstaller) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GiteaInstaller) stop() ! {
|
pub fn (mut self GiteaInstaller) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GiteaInstaller) restart() ! {
|
pub fn (mut self GiteaInstaller) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GiteaInstaller) running() !bool {
|
pub fn (mut self GiteaInstaller) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module gitea
|
module gitea
|
||||||
|
|
||||||
import freeflowuniverse.herolib.data.paramsparser
|
import freeflowuniverse.herolib.data.paramsparser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -6,24 +7,20 @@ pub const version = '0.0.0'
|
|||||||
const singleton = true
|
const singleton = true
|
||||||
const default = true
|
const default = true
|
||||||
|
|
||||||
|
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||||
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
|
||||||
@[heap]
|
@[heap]
|
||||||
pub struct GiteaInstaller {
|
pub struct GiteaInstaller {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string = 'default'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn obj_init(obj_ GiteaInstaller) !GiteaInstaller {
|
||||||
fn obj_init(obj_ GiteaInstaller)!GiteaInstaller{
|
// never call get here, only thing we can do here is work on object itself
|
||||||
//never call get here, only thing we can do here is work on object itself
|
mut obj := obj_
|
||||||
mut obj:=obj_
|
return obj
|
||||||
return obj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//called before start if done
|
// called before start if done
|
||||||
fn configure() ! {
|
fn configure() ! {
|
||||||
//mut installer := get()!
|
// mut installer := get()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import freeflowuniverse.herolib.core.pathlib
|
|||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
pub fn install_() ! {
|
pub fn install_() ! {
|
||||||
if core.platform()!= .ubuntu || core.platform()!= .arch {
|
if core.platform() != .ubuntu || core.platform() != .arch {
|
||||||
return error('only support ubuntu and arch for now')
|
return error('only support ubuntu and arch for now')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ pub fn install_() ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start() ! {
|
pub fn start() ! {
|
||||||
if core.platform()!= .ubuntu || core.platform()!= .arch {
|
if core.platform() != .ubuntu || core.platform() != .arch {
|
||||||
return error('only support ubuntu and arch for now')
|
return error('only support ubuntu and arch for now')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,297 +1,276 @@
|
|||||||
|
|
||||||
module livekit
|
module livekit
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
livekit_global map[string]&LivekitServer
|
livekit_global map[string]&LivekitServer
|
||||||
livekit_default string
|
livekit_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = livekit_default
|
model.name = livekit_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&LivekitServer {
|
pub fn get(args_ ArgsGet) !&LivekitServer {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in livekit_global) {
|
if args.name !in livekit_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("livekit",model.name,heroscript_default()!)!
|
context.hero_config_set('livekit', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return livekit_global[args.name] or {
|
return livekit_global[args.name] or {
|
||||||
println(livekit_global)
|
println(livekit_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o LivekitServer) ! {
|
||||||
//set the model in mem and the config on the filesystem
|
mut o2 := obj_init(o)!
|
||||||
pub fn set(o LivekitServer)! {
|
livekit_global[o.name] = &o2
|
||||||
mut o2:=obj_init(o)!
|
livekit_default = o.name
|
||||||
livekit_global[o.name] = &o2
|
|
||||||
livekit_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("livekit",model.name)
|
return context.hero_config_exists('livekit', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("livekit",model.name)!
|
mut heroscript := context.hero_config_get('livekit', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o LivekitServer)! {
|
pub fn save(o LivekitServer) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[LivekitServer](o)!
|
heroscript := encoderhero.encode[LivekitServer](o)!
|
||||||
context.hero_config_set("livekit",model.name,heroscript)!
|
context.hero_config_set('livekit', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
if model.heroscript == '' {
|
||||||
model.heroscript = heroscript_default()!
|
model.heroscript = heroscript_default()!
|
||||||
}
|
}
|
||||||
mut plbook := model.plbook or {
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'livekit.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action livekit.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'livekit.')!
|
mut configure_actions := plbook.find(filter: 'livekit.configure')!
|
||||||
for other_action in other_actions {
|
if configure_actions.len > 0 {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
for config_action in configure_actions {
|
||||||
mut p := other_action.params
|
mut p := config_action.params
|
||||||
reset:=p.get_default_false("reset")
|
mycfg := cfg_play(p)!
|
||||||
if other_action.name == "destroy" || reset{
|
console.print_debug('install action livekit.configure\n${mycfg}')
|
||||||
console.print_debug("install action livekit.destroy")
|
set(mycfg)!
|
||||||
destroy_()!
|
save(mycfg)!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
}
|
||||||
console.print_debug("install action livekit.install")
|
|
||||||
install_()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if other_action.name in ["start","stop","restart"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut livekit_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n${livekit_obj}")
|
|
||||||
if other_action.name == "start"{
|
|
||||||
console.print_debug("install action livekit.${other_action.name}")
|
|
||||||
livekit_obj.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
if other_action.name == "stop"{
|
mut other_actions := plbook.find(filter: 'livekit.')!
|
||||||
console.print_debug("install action livekit.${other_action.name}")
|
for other_action in other_actions {
|
||||||
livekit_obj.stop()!
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
}
|
mut p := other_action.params
|
||||||
if other_action.name == "restart"{
|
reset := p.get_default_false('reset')
|
||||||
console.print_debug("install action livekit.${other_action.name}")
|
if other_action.name == 'destroy' || reset {
|
||||||
livekit_obj.restart()!
|
console.print_debug('install action livekit.destroy')
|
||||||
}
|
destroy_()!
|
||||||
}
|
}
|
||||||
}
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action livekit.install')
|
||||||
|
install_()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut livekit_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${livekit_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action livekit.${other_action.name}')
|
||||||
|
livekit_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action livekit.${other_action.name}')
|
||||||
|
livekit_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action livekit.${other_action.name}')
|
||||||
|
livekit_obj.restart()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self LivekitServer) reload() ! {
|
pub fn (mut self LivekitServer) reload() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self=obj_init(self)!
|
self = obj_init(self)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) start() ! {
|
pub fn (mut self LivekitServer) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('livekit start')
|
console.print_header('livekit start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting livekit with ${zprocess.startuptype}...')
|
console.print_debug('starting livekit with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('livekit did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('livekit did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) install_start(model InstallArgs) ! {
|
pub fn (mut self LivekitServer) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) stop() ! {
|
pub fn (mut self LivekitServer) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) restart() ! {
|
pub fn (mut self LivekitServer) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) running() !bool {
|
pub fn (mut self LivekitServer) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for livekit
|
||||||
//switch instance to be used for livekit
|
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
livekit_default = name
|
livekit_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) install(args InstallArgs) ! {
|
pub fn (mut self LivekitServer) install(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self LivekitServer) destroy() ! {
|
pub fn (mut self LivekitServer) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop() or {}
|
self.stop() or {}
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import os
|
|||||||
// checks if a certain version or above is installed
|
// checks if a certain version or above is installed
|
||||||
fn installed_() !bool {
|
fn installed_() !bool {
|
||||||
res := os.execute('${osal.profile_path_source_and()!} go version')
|
res := os.execute('${osal.profile_path_source_and()!} go version')
|
||||||
|
|
||||||
if res.exit_code == 0 {
|
if res.exit_code == 0 {
|
||||||
r := res.output.split_into_lines()
|
r := res.output.split_into_lines()
|
||||||
.filter(it.contains('go version'))
|
.filter(it.contains('go version'))
|
||||||
@@ -34,7 +34,7 @@ fn installed_() !bool {
|
|||||||
fn install_() ! {
|
fn install_() ! {
|
||||||
console.print_header('install golang')
|
console.print_header('install golang')
|
||||||
base.install()!
|
base.install()!
|
||||||
//destroy()!
|
// destroy()!
|
||||||
|
|
||||||
mut url := ''
|
mut url := ''
|
||||||
if core.is_linux_arm()! {
|
if core.is_linux_arm()! {
|
||||||
@@ -93,4 +93,3 @@ fn destroy_() ! {
|
|||||||
go
|
go
|
||||||
')!
|
')!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module golang
|
module golang
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
golang_global map[string]&GolangInstaller
|
golang_global map[string]&GolangInstaller
|
||||||
golang_default string
|
golang_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,74 +6,64 @@ import freeflowuniverse.herolib.core.texttools
|
|||||||
import freeflowuniverse.herolib.core.pathlib
|
import freeflowuniverse.herolib.core.pathlib
|
||||||
import freeflowuniverse.herolib.installers.ulist
|
import freeflowuniverse.herolib.installers.ulist
|
||||||
import freeflowuniverse.herolib.installers.base
|
import freeflowuniverse.herolib.installers.base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
//////////////////// following actions are not specific to instance of the object
|
//////////////////// following actions are not specific to instance of the object
|
||||||
|
|
||||||
fn installed_() !bool {
|
fn installed_() !bool {
|
||||||
|
res := os.execute('pnpm -v')
|
||||||
res := os.execute('pnpm -v')
|
if res.exit_code != 0 {
|
||||||
if res.exit_code != 0 {
|
return false
|
||||||
return false
|
}
|
||||||
}
|
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
if r.len != 1 {
|
||||||
if r.len != 1 {
|
return error("couldn't parse pnpm version.\n${res.output}")
|
||||||
return error("couldn't parse pnpm version.\n${res.output}")
|
}
|
||||||
}
|
if texttools.version(r[0]) >= texttools.version(version) {
|
||||||
if texttools.version(r[0]) >= texttools.version(version) {
|
return true
|
||||||
return true
|
}
|
||||||
}
|
return false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the Upload List of the files
|
// get the Upload List of the files
|
||||||
fn ulist_get() !ulist.UList {
|
fn ulist_get() !ulist.UList {
|
||||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||||
return ulist.UList{}
|
return ulist.UList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//uploads to S3 server if configured
|
// uploads to S3 server if configured
|
||||||
fn upload_() ! {
|
fn upload_() ! {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_() ! {
|
fn install_() ! {
|
||||||
console.print_header('install nodejs')
|
console.print_header('install nodejs')
|
||||||
osal.package_install('pnpm')!
|
osal.package_install('pnpm')!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn destroy_() ! {
|
fn destroy_() ! {
|
||||||
|
// mut systemdfactory := systemd.new()!
|
||||||
|
// systemdfactory.destroy("zinit")!
|
||||||
|
|
||||||
// mut systemdfactory := systemd.new()!
|
// osal.process_kill_recursive(name:'zinit')!
|
||||||
// systemdfactory.destroy("zinit")!
|
// osal.cmd_delete('zinit')!
|
||||||
|
|
||||||
// osal.process_kill_recursive(name:'zinit')!
|
osal.package_remove('
|
||||||
// osal.cmd_delete('zinit')!
|
|
||||||
|
|
||||||
osal.package_remove('
|
|
||||||
pnpm
|
pnpm
|
||||||
')!
|
')!
|
||||||
|
|
||||||
// //will remove all paths where go/bin is found
|
// //will remove all paths where go/bin is found
|
||||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||||
|
|
||||||
// osal.rm("
|
|
||||||
// podman
|
|
||||||
// conmon
|
|
||||||
// buildah
|
|
||||||
// skopeo
|
|
||||||
// runc
|
|
||||||
// /var/lib/containers
|
|
||||||
// /var/lib/podman
|
|
||||||
// /var/lib/buildah
|
|
||||||
// /tmp/podman
|
|
||||||
// /tmp/conmon
|
|
||||||
// ")!
|
|
||||||
|
|
||||||
|
// osal.rm("
|
||||||
|
// podman
|
||||||
|
// conmon
|
||||||
|
// buildah
|
||||||
|
// skopeo
|
||||||
|
// runc
|
||||||
|
// /var/lib/containers
|
||||||
|
// /var/lib/podman
|
||||||
|
// /var/lib/buildah
|
||||||
|
// /tmp/podman
|
||||||
|
// /tmp/conmon
|
||||||
|
// ")!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,38 @@
|
|||||||
|
|
||||||
module nodejs
|
module nodejs
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
nodejs_global map[string]&NodeJS
|
nodejs_global map[string]&NodeJS
|
||||||
nodejs_default string
|
nodejs_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,93 +6,83 @@ import freeflowuniverse.herolib.core.texttools
|
|||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
import freeflowuniverse.herolib.installers.ulist
|
import freeflowuniverse.herolib.installers.ulist
|
||||||
import freeflowuniverse.herolib.installers.base
|
import freeflowuniverse.herolib.installers.base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
//////////////////// following actions are not specific to instance of the object
|
//////////////////// following actions are not specific to instance of the object
|
||||||
|
|
||||||
// checks if a certain version or above is installed
|
// checks if a certain version or above is installed
|
||||||
fn installed_() !bool {
|
fn installed_() !bool {
|
||||||
res := os.execute('python3 --version')
|
res := os.execute('python3 --version')
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||||
if r.len != 1 {
|
if r.len != 1 {
|
||||||
return error("couldn't parse pnpm version.\n${res.output}")
|
return error("couldn't parse pnpm version.\n${res.output}")
|
||||||
}
|
}
|
||||||
if texttools.version(r[0].all_after_first("ython")) >= texttools.version(version) {
|
if texttools.version(r[0].all_after_first('ython')) >= texttools.version(version) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the Upload List of the files
|
// get the Upload List of the files
|
||||||
fn ulist_get() !ulist.UList {
|
fn ulist_get() !ulist.UList {
|
||||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||||
return ulist.UList{}
|
return ulist.UList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upload_() ! {
|
fn upload_() ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_() ! {
|
fn install_() ! {
|
||||||
console.print_header('install python')
|
console.print_header('install python')
|
||||||
base.install()!
|
base.install()!
|
||||||
|
|
||||||
osal.package_install('python3')!
|
osal.package_install('python3')!
|
||||||
pl := core.platform()!
|
pl := core.platform()!
|
||||||
if pl == .arch {
|
if pl == .arch {
|
||||||
osal.package_install('python-pipx,sqlite')!
|
osal.package_install('python-pipx,sqlite')!
|
||||||
} else if pl == .ubuntu {
|
} else if pl == .ubuntu {
|
||||||
osal.package_install('python-pipx,sqlite')!
|
osal.package_install('python-pipx,sqlite')!
|
||||||
} else if pl == .osx {
|
} else if pl == .osx {
|
||||||
osal.package_install('pipx,sqlite')!
|
osal.package_install('pipx,sqlite')!
|
||||||
|
} else {
|
||||||
} else {
|
return error('only support osx, arch & ubuntu.')
|
||||||
return error('only support osx, arch & ubuntu.')
|
}
|
||||||
}
|
osal.execute_silent('pipx install uv')!
|
||||||
osal.execute_silent("pipx install uv")!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn destroy_() ! {
|
fn destroy_() ! {
|
||||||
|
panic('implement')
|
||||||
|
|
||||||
panic("implement")
|
// mut systemdfactory := systemd.new()!
|
||||||
|
// systemdfactory.destroy("zinit")!
|
||||||
|
|
||||||
// mut systemdfactory := systemd.new()!
|
// osal.process_kill_recursive(name:'zinit')!
|
||||||
// systemdfactory.destroy("zinit")!
|
// osal.cmd_delete('zinit')!
|
||||||
|
|
||||||
// osal.process_kill_recursive(name:'zinit')!
|
// osal.package_remove('
|
||||||
// osal.cmd_delete('zinit')!
|
// podman
|
||||||
|
// conmon
|
||||||
// osal.package_remove('
|
// buildah
|
||||||
// podman
|
// skopeo
|
||||||
// conmon
|
// runc
|
||||||
// buildah
|
// ')!
|
||||||
// skopeo
|
|
||||||
// runc
|
|
||||||
// ')!
|
|
||||||
|
|
||||||
// //will remove all paths where go/bin is found
|
|
||||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
|
||||||
|
|
||||||
// osal.rm("
|
|
||||||
// podman
|
|
||||||
// conmon
|
|
||||||
// buildah
|
|
||||||
// skopeo
|
|
||||||
// runc
|
|
||||||
// /var/lib/containers
|
|
||||||
// /var/lib/podman
|
|
||||||
// /var/lib/buildah
|
|
||||||
// /tmp/podman
|
|
||||||
// /tmp/conmon
|
|
||||||
// ")!
|
|
||||||
|
|
||||||
|
// //will remove all paths where go/bin is found
|
||||||
|
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||||
|
|
||||||
|
// osal.rm("
|
||||||
|
// podman
|
||||||
|
// conmon
|
||||||
|
// buildah
|
||||||
|
// skopeo
|
||||||
|
// runc
|
||||||
|
// /var/lib/containers
|
||||||
|
// /var/lib/podman
|
||||||
|
// /var/lib/buildah
|
||||||
|
// /tmp/podman
|
||||||
|
// /tmp/conmon
|
||||||
|
// ")!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,38 @@
|
|||||||
|
|
||||||
module python
|
module python
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
python_global map[string]&Python
|
python_global map[string]&Python
|
||||||
python_default string
|
python_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,47 +6,43 @@ import freeflowuniverse.herolib.core.texttools
|
|||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
import freeflowuniverse.herolib.installers.ulist
|
import freeflowuniverse.herolib.installers.ulist
|
||||||
import freeflowuniverse.herolib.installers.base
|
import freeflowuniverse.herolib.installers.base
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
//////////////////// following actions are not specific to instance of the object
|
//////////////////// following actions are not specific to instance of the object
|
||||||
|
|
||||||
// checks if a certain version or above is installed
|
// checks if a certain version or above is installed
|
||||||
fn installed_() !bool {
|
fn installed_() !bool {
|
||||||
res := os.execute('${osal.profile_path_source_and()!} rustc -V')
|
res := os.execute('${osal.profile_path_source_and()!} rustc -V')
|
||||||
if res.exit_code != 0 {
|
if res.exit_code != 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||||
if r.len != 1 {
|
if r.len != 1 {
|
||||||
return error("couldn't parse rust version.\n${res.output}")
|
return error("couldn't parse rust version.\n${res.output}")
|
||||||
}
|
}
|
||||||
myversion := r[0].all_after_first("rustc").all_before("(")
|
myversion := r[0].all_after_first('rustc').all_before('(')
|
||||||
if texttools.version(version) == texttools.version(myversion) {
|
if texttools.version(version) == texttools.version(myversion) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the Upload List of the files
|
// get the Upload List of the files
|
||||||
fn ulist_get() !ulist.UList {
|
fn ulist_get() !ulist.UList {
|
||||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
// optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||||
return ulist.UList{}
|
return ulist.UList{}
|
||||||
}
|
}
|
||||||
|
|
||||||
//uploads to S3 server if configured
|
// uploads to S3 server if configured
|
||||||
fn upload_() ! {
|
fn upload_() ! {
|
||||||
// installers.upload(
|
// installers.upload(
|
||||||
// cmdname: 'rust'
|
// cmdname: 'rust'
|
||||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust'
|
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/rust'
|
||||||
// )!
|
// )!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_() ! {
|
fn install_() ! {
|
||||||
console.print_header('install rust')
|
console.print_header('install rust')
|
||||||
version := '1.83.0'
|
version := '1.83.0'
|
||||||
|
|
||||||
base.install()!
|
base.install()!
|
||||||
@@ -68,14 +64,13 @@ fn install_() ! {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn destroy_() ! {
|
fn destroy_() ! {
|
||||||
|
osal.package_remove('
|
||||||
osal.package_remove('
|
|
||||||
rust
|
rust
|
||||||
')!
|
')!
|
||||||
|
|
||||||
osal.exec(cmd:'
|
osal.exec(
|
||||||
|
cmd: '
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Script to uninstall Rust and Rust-related files
|
# Script to uninstall Rust and Rust-related files
|
||||||
@@ -103,13 +98,13 @@ fn destroy_() ! {
|
|||||||
|
|
||||||
echo "Rust uninstallation process completed."
|
echo "Rust uninstallation process completed."
|
||||||
|
|
||||||
',debug:false)!
|
'
|
||||||
|
debug: false
|
||||||
|
)!
|
||||||
|
|
||||||
osal.rm("
|
osal.rm('
|
||||||
rustc
|
rustc
|
||||||
rustup
|
rustup
|
||||||
cargo
|
cargo
|
||||||
")!
|
')!
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,38 @@
|
|||||||
|
|
||||||
module rust
|
module rust
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
rust_global map[string]&RustInstaller
|
rust_global map[string]&RustInstaller
|
||||||
rust_default string
|
rust_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module rust
|
module rust
|
||||||
|
|
||||||
import freeflowuniverse.herolib.data.paramsparser
|
import freeflowuniverse.herolib.data.paramsparser
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -6,24 +7,20 @@ pub const version = '1.83.0'
|
|||||||
const singleton = true
|
const singleton = true
|
||||||
const default = true
|
const default = true
|
||||||
|
|
||||||
|
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||||
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
|
||||||
@[heap]
|
@[heap]
|
||||||
pub struct RustInstaller {
|
pub struct RustInstaller {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string = 'default'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn obj_init(obj_ RustInstaller) !RustInstaller {
|
||||||
fn obj_init(obj_ RustInstaller)!RustInstaller{
|
// never call get here, only thing we can do here is work on object itself
|
||||||
//never call get here, only thing we can do here is work on object itself
|
mut obj := obj_
|
||||||
mut obj:=obj_
|
return obj
|
||||||
return obj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//called before start if done
|
// called before start if done
|
||||||
fn configure() ! {
|
fn configure() ! {
|
||||||
//mut installer := get()!
|
// mut installer := get()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module mycelium
|
module mycelium
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
mycelium_global map[string]&MyceliumInstaller
|
mycelium_global map[string]&MyceliumInstaller
|
||||||
mycelium_default string
|
mycelium_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) start() ! {
|
pub fn (mut self MyceliumInstaller) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('mycelium start')
|
console.print_header('mycelium start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('mycelium did not install properly.')
|
|
||||||
|
|
||||||
|
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(model InstallArgs) ! {
|
pub fn (mut self MyceliumInstaller) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) stop() ! {
|
pub fn (mut self MyceliumInstaller) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) restart() ! {
|
pub fn (mut self MyceliumInstaller) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self MyceliumInstaller) running() !bool {
|
pub fn (mut self MyceliumInstaller) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module yggdrasil
|
module yggdrasil
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
yggdrasil_global map[string]&YggdrasilInstaller
|
yggdrasil_global map[string]&YggdrasilInstaller
|
||||||
yggdrasil_default string
|
yggdrasil_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self YggdrasilInstaller) start() ! {
|
pub fn (mut self YggdrasilInstaller) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('yggdrasil start')
|
console.print_header('yggdrasil start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting yggdrasil with ${zprocess.startuptype}...')
|
console.print_debug('starting yggdrasil with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('yggdrasil did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('yggdrasil did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self YggdrasilInstaller) install_start(model InstallArgs) ! {
|
pub fn (mut self YggdrasilInstaller) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self YggdrasilInstaller) stop() ! {
|
pub fn (mut self YggdrasilInstaller) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self YggdrasilInstaller) restart() ! {
|
pub fn (mut self YggdrasilInstaller) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self YggdrasilInstaller) running() !bool {
|
pub fn (mut self YggdrasilInstaller) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module actrunner
|
module actrunner
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
actrunner_global map[string]&ActRunner
|
actrunner_global map[string]&ActRunner
|
||||||
actrunner_default string
|
actrunner_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ActRunner) start() ! {
|
pub fn (mut self ActRunner) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('actrunner start')
|
console.print_header('actrunner start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting actrunner with ${zprocess.startuptype}...')
|
console.print_debug('starting actrunner with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('actrunner did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('actrunner did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ActRunner) install_start(model InstallArgs) ! {
|
pub fn (mut self ActRunner) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ActRunner) stop() ! {
|
pub fn (mut self ActRunner) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ActRunner) restart() ! {
|
pub fn (mut self ActRunner) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ActRunner) running() !bool {
|
pub fn (mut self ActRunner) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module b2
|
module b2
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
b2_global map[string]&BackBase
|
b2_global map[string]&BackBase
|
||||||
b2_default string
|
b2_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self BackBase) start() ! {
|
pub fn (mut self BackBase) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('b2 start')
|
console.print_header('b2 start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting b2 with ${zprocess.startuptype}...')
|
console.print_debug('starting b2 with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('b2 did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('b2 did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self BackBase) install_start(model InstallArgs) ! {
|
pub fn (mut self BackBase) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self BackBase) stop() ! {
|
pub fn (mut self BackBase) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self BackBase) restart() ! {
|
pub fn (mut self BackBase) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self BackBase) running() !bool {
|
pub fn (mut self BackBase) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module fungistor
|
module fungistor
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
fungistor_global map[string]&FungiStor
|
fungistor_global map[string]&FungiStor
|
||||||
fungistor_default string
|
fungistor_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self FungiStor) start() ! {
|
pub fn (mut self FungiStor) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('fungistor start')
|
console.print_header('fungistor start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting fungistor with ${zprocess.startuptype}...')
|
console.print_debug('starting fungistor with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('fungistor did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('fungistor did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self FungiStor) install_start(model InstallArgs) ! {
|
pub fn (mut self FungiStor) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self FungiStor) stop() ! {
|
pub fn (mut self FungiStor) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self FungiStor) restart() ! {
|
pub fn (mut self FungiStor) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self FungiStor) running() !bool {
|
pub fn (mut self FungiStor) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module garage_s3
|
module garage_s3
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
garage_s3_global map[string]&GarageS3
|
garage_s3_global map[string]&GarageS3
|
||||||
garage_s3_default string
|
garage_s3_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GarageS3) start() ! {
|
pub fn (mut self GarageS3) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('garage_s3 start')
|
console.print_header('garage_s3 start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting garage_s3 with ${zprocess.startuptype}...')
|
console.print_debug('starting garage_s3 with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('garage_s3 did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('garage_s3 did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GarageS3) install_start(model InstallArgs) ! {
|
pub fn (mut self GarageS3) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GarageS3) stop() ! {
|
pub fn (mut self GarageS3) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GarageS3) restart() ! {
|
pub fn (mut self GarageS3) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self GarageS3) running() !bool {
|
pub fn (mut self GarageS3) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module grafana
|
module grafana
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
grafana_global map[string]&Grafana
|
grafana_global map[string]&Grafana
|
||||||
grafana_default string
|
grafana_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Grafana) start() ! {
|
pub fn (mut self Grafana) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('grafana start')
|
console.print_header('grafana start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting grafana with ${zprocess.startuptype}...')
|
console.print_debug('starting grafana with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('grafana did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('grafana did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Grafana) install_start(model InstallArgs) ! {
|
pub fn (mut self Grafana) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Grafana) stop() ! {
|
pub fn (mut self Grafana) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Grafana) restart() ! {
|
pub fn (mut self Grafana) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Grafana) running() !bool {
|
pub fn (mut self Grafana) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module prometheus
|
module prometheus
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
prometheus_global map[string]&Prometheus
|
prometheus_global map[string]&Prometheus
|
||||||
prometheus_default string
|
prometheus_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Prometheus) start() ! {
|
pub fn (mut self Prometheus) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('prometheus start')
|
console.print_header('prometheus start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting prometheus with ${zprocess.startuptype}...')
|
console.print_debug('starting prometheus with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('prometheus did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('prometheus did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Prometheus) install_start(model InstallArgs) ! {
|
pub fn (mut self Prometheus) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Prometheus) stop() ! {
|
pub fn (mut self Prometheus) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Prometheus) restart() ! {
|
pub fn (mut self Prometheus) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Prometheus) running() !bool {
|
pub fn (mut self Prometheus) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,182 +1,161 @@
|
|||||||
|
|
||||||
module rclone
|
module rclone
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
rclone_global map[string]&RClone
|
rclone_global map[string]&RClone
|
||||||
rclone_default string
|
rclone_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = rclone_default
|
model.name = rclone_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&RClone {
|
pub fn get(args_ ArgsGet) !&RClone {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in rclone_global) {
|
if args.name !in rclone_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("rclone",model.name,heroscript_default()!)!
|
context.hero_config_set('rclone', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rclone_global[args.name] or {
|
return rclone_global[args.name] or {
|
||||||
println(rclone_global)
|
println(rclone_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o RClone) ! {
|
||||||
//set the model in mem and the config on the filesystem
|
mut o2 := obj_init(o)!
|
||||||
pub fn set(o RClone)! {
|
rclone_global[o.name] = &o2
|
||||||
mut o2:=obj_init(o)!
|
rclone_default = o.name
|
||||||
rclone_global[o.name] = &o2
|
|
||||||
rclone_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("rclone",model.name)
|
return context.hero_config_exists('rclone', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("rclone",model.name)!
|
mut heroscript := context.hero_config_get('rclone', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o RClone)! {
|
pub fn save(o RClone) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[RClone](o)!
|
heroscript := encoderhero.encode[RClone](o)!
|
||||||
context.hero_config_set("rclone",model.name,heroscript)!
|
context.hero_config_set('rclone', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
if model.heroscript == '' {
|
||||||
model.heroscript = heroscript_default()!
|
model.heroscript = heroscript_default()!
|
||||||
}
|
}
|
||||||
mut plbook := model.plbook or {
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'rclone.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action rclone.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'rclone.')!
|
mut configure_actions := plbook.find(filter: 'rclone.configure')!
|
||||||
for other_action in other_actions {
|
if configure_actions.len > 0 {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
for config_action in configure_actions {
|
||||||
mut p := other_action.params
|
mut p := config_action.params
|
||||||
reset:=p.get_default_false("reset")
|
mycfg := cfg_play(p)!
|
||||||
if other_action.name == "destroy" || reset{
|
console.print_debug('install action rclone.configure\n${mycfg}')
|
||||||
console.print_debug("install action rclone.destroy")
|
set(mycfg)!
|
||||||
destroy_()!
|
save(mycfg)!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
}
|
||||||
console.print_debug("install action rclone.install")
|
|
||||||
install_()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mut other_actions := plbook.find(filter: 'rclone.')!
|
||||||
|
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 rclone.destroy')
|
||||||
|
destroy_()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action rclone.install')
|
||||||
|
install_()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self RClone) reload() ! {
|
pub fn (mut self RClone) reload() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self=obj_init(self)!
|
self = obj_init(self)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for rclone
|
||||||
//switch instance to be used for rclone
|
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
rclone_default = name
|
rclone_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self RClone) install(args InstallArgs) ! {
|
pub fn (mut self RClone) install(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self RClone) destroy() ! {
|
pub fn (mut self RClone) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub mut:
|
|||||||
// install restic will return true if it was already installed
|
// install restic will return true if it was already installed
|
||||||
pub fn build_(args BuildArgs) ! {
|
pub fn build_(args BuildArgs) ! {
|
||||||
// make sure we install base on the node
|
// make sure we install base on the node
|
||||||
if core.platform()!= .ubuntu {
|
if core.platform() != .ubuntu {
|
||||||
return error('only support ubuntu for now')
|
return error('only support ubuntu for now')
|
||||||
}
|
}
|
||||||
golang.install()!
|
golang.install()!
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module restic
|
module restic
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
restic_global map[string]&Restic
|
restic_global map[string]&Restic
|
||||||
restic_default string
|
restic_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Restic) start() ! {
|
pub fn (mut self Restic) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('restic start')
|
console.print_header('restic start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting restic with ${zprocess.startuptype}...')
|
console.print_debug('starting restic with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('restic did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('restic did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Restic) install_start(model InstallArgs) ! {
|
pub fn (mut self Restic) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Restic) stop() ! {
|
pub fn (mut self Restic) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Restic) restart() ! {
|
pub fn (mut self Restic) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Restic) running() !bool {
|
pub fn (mut self Restic) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub mut:
|
|||||||
// install s3cas will return true if it was already installed
|
// install s3cas will return true if it was already installed
|
||||||
pub fn build_(args BuildArgs) ! {
|
pub fn build_(args BuildArgs) ! {
|
||||||
// make sure we install base on the node
|
// make sure we install base on the node
|
||||||
if core.platform()!= .ubuntu {
|
if core.platform() != .ubuntu {
|
||||||
return error('only support ubuntu for now')
|
return error('only support ubuntu for now')
|
||||||
}
|
}
|
||||||
rust.install()!
|
rust.install()!
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module s3
|
module s3
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
s3_global map[string]&S3Installer
|
s3_global map[string]&S3Installer
|
||||||
s3_default string
|
s3_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self S3Installer) start() ! {
|
pub fn (mut self S3Installer) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('s3 start')
|
console.print_header('s3 start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting s3 with ${zprocess.startuptype}...')
|
console.print_debug('starting s3 with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('s3 did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('s3 did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self S3Installer) install_start(model InstallArgs) ! {
|
pub fn (mut self S3Installer) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self S3Installer) stop() ! {
|
pub fn (mut self S3Installer) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self S3Installer) restart() ! {
|
pub fn (mut self S3Installer) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self S3Installer) running() !bool {
|
pub fn (mut self S3Installer) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module zinit
|
module zinit
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
zinit_global map[string]&Zinit
|
zinit_global map[string]&Zinit
|
||||||
zinit_default string
|
zinit_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Zinit) start() ! {
|
pub fn (mut self Zinit) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('zinit start')
|
console.print_header('zinit start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting zinit with ${zprocess.startuptype}...')
|
console.print_debug('starting zinit with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('zinit did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('zinit did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Zinit) install_start(model InstallArgs) ! {
|
pub fn (mut self Zinit) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Zinit) stop() ! {
|
pub fn (mut self Zinit) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Zinit) restart() ! {
|
pub fn (mut self Zinit) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self Zinit) running() !bool {
|
pub fn (mut self Zinit) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module griddriver
|
module griddriver
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
griddriver_global map[string]&GridDriverInstaller
|
griddriver_global map[string]&GridDriverInstaller
|
||||||
griddriver_default string
|
griddriver_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module buildah
|
module buildah
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
buildah_global map[string]&BuildahInstaller
|
buildah_global map[string]&BuildahInstaller
|
||||||
buildah_default string
|
buildah_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module cloudhypervisor
|
module cloudhypervisor
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
cloudhypervisor_global map[string]&CloudHypervisor
|
cloudhypervisor_global map[string]&CloudHypervisor
|
||||||
cloudhypervisor_default string
|
cloudhypervisor_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import freeflowuniverse.herolib.ui.console
|
|||||||
// install docker will return true if it was already installed
|
// install docker will return true if it was already installed
|
||||||
pub fn install_() ! {
|
pub fn install_() ! {
|
||||||
console.print_header('package install install docker')
|
console.print_header('package install install docker')
|
||||||
if core.platform()!= .ubuntu {
|
if core.platform() != .ubuntu {
|
||||||
return error('only support ubuntu for now')
|
return error('only support ubuntu for now')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ fn install_() ! {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if core.platform()!= .ubuntu {
|
if core.platform() != .ubuntu {
|
||||||
return error('only ubuntu supported for this installer.')
|
return error('only ubuntu supported for this installer.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,38 @@
|
|||||||
|
|
||||||
module pacman
|
module pacman
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
pacman_global map[string]&PacmanInstaller
|
pacman_global map[string]&PacmanInstaller
|
||||||
pacman_default string
|
pacman_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ fn build_() ! {
|
|||||||
|
|
||||||
// https://podman.io/docs/installation#building-from-source
|
// https://podman.io/docs/installation#building-from-source
|
||||||
|
|
||||||
if core.platform()!= .ubuntu && core.platform()!= .arch {
|
if core.platform() != .ubuntu && core.platform() != .arch {
|
||||||
return error('only support ubuntu and arch for now')
|
return error('only support ubuntu and arch for now')
|
||||||
}
|
}
|
||||||
mut g := golang.get()!
|
mut g := golang.get()!
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module podman
|
module podman
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
podman_global map[string]&PodmanInstaller
|
podman_global map[string]&PodmanInstaller
|
||||||
podman_default string
|
podman_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,42 @@
|
|||||||
|
|
||||||
module youki
|
module youki
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
youki_global map[string]&YoukiInstaller
|
youki_global map[string]&YoukiInstaller
|
||||||
youki_default string
|
youki_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,255 +1,236 @@
|
|||||||
|
|
||||||
module caddy
|
module caddy
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
caddy_global map[string]&CaddyServer
|
caddy_global map[string]&CaddyServer
|
||||||
caddy_default string
|
caddy_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
// set the model in mem and the config on the filesystem
|
||||||
|
pub fn set(o CaddyServer) ! {
|
||||||
|
mut o2 := obj_init(o)!
|
||||||
//set the model in mem and the config on the filesystem
|
caddy_global[o.name] = &o2
|
||||||
pub fn set(o CaddyServer)! {
|
caddy_default = o.name
|
||||||
mut o2:=obj_init(o)!
|
|
||||||
caddy_global[o.name] = &o2
|
|
||||||
caddy_default = o.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check we find the config on the filesystem
|
// check we find the config on the filesystem
|
||||||
pub fn exists(args_ ArgsGet) bool {
|
pub fn exists(args_ ArgsGet) bool {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
return context.hero_config_exists("caddy",model.name)
|
return context.hero_config_exists('caddy', model.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the config error if it doesn't exist
|
// load the config error if it doesn't exist
|
||||||
pub fn load(args_ ArgsGet) ! {
|
pub fn load(args_ ArgsGet) ! {
|
||||||
mut model := args_get(args_)
|
mut model := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut heroscript := context.hero_config_get("caddy",model.name)!
|
mut heroscript := context.hero_config_get('caddy', model.name)!
|
||||||
play(heroscript:heroscript)!
|
play(heroscript: heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the config to the filesystem in the context
|
// save the config to the filesystem in the context
|
||||||
pub fn save(o CaddyServer)! {
|
pub fn save(o CaddyServer) ! {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
heroscript := encoderhero.encode[CaddyServer](o)!
|
heroscript := encoderhero.encode[CaddyServer](o)!
|
||||||
context.hero_config_set("caddy",model.name,heroscript)!
|
context.hero_config_set('caddy', model.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct PlayArgs {
|
pub struct PlayArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
heroscript string //if filled in then plbook will be made out of it
|
heroscript string // if filled in then plbook will be made out of it
|
||||||
plbook ?playbook.PlayBook
|
plbook ?playbook.PlayBook
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(args_ PlayArgs) ! {
|
pub fn play(args_ PlayArgs) ! {
|
||||||
|
mut model := args_
|
||||||
mut model:=args_
|
|
||||||
|
|
||||||
if model.heroscript == "" {
|
if model.heroscript == '' {
|
||||||
model.heroscript = heroscript_default()!
|
model.heroscript = heroscript_default()!
|
||||||
}
|
}
|
||||||
mut plbook := model.plbook or {
|
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||||
playbook.new(text: model.heroscript)!
|
|
||||||
}
|
|
||||||
|
|
||||||
mut configure_actions := plbook.find(filter: 'caddy.configure')!
|
|
||||||
if configure_actions.len > 0 {
|
|
||||||
for config_action in configure_actions {
|
|
||||||
mut p := config_action.params
|
|
||||||
mycfg:=cfg_play(p)!
|
|
||||||
console.print_debug("install action caddy.configure\n${mycfg}")
|
|
||||||
set(mycfg)!
|
|
||||||
save(mycfg)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'caddy.')!
|
mut configure_actions := plbook.find(filter: 'caddy.configure')!
|
||||||
for other_action in other_actions {
|
if configure_actions.len > 0 {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
for config_action in configure_actions {
|
||||||
mut p := other_action.params
|
mut p := config_action.params
|
||||||
reset:=p.get_default_false("reset")
|
mycfg := cfg_play(p)!
|
||||||
if other_action.name == "destroy" || reset{
|
console.print_debug('install action caddy.configure\n${mycfg}')
|
||||||
console.print_debug("install action caddy.destroy")
|
set(mycfg)!
|
||||||
destroy_()!
|
save(mycfg)!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
}
|
||||||
console.print_debug("install action caddy.install")
|
|
||||||
install_()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if other_action.name in ["start","stop","restart"]{
|
|
||||||
mut p := other_action.params
|
|
||||||
name := p.get('name')!
|
|
||||||
mut caddy_obj:=get(name:name)!
|
|
||||||
console.print_debug("action object:\n${caddy_obj}")
|
|
||||||
if other_action.name == "start"{
|
|
||||||
console.print_debug("install action caddy.${other_action.name}")
|
|
||||||
caddy_obj.start()!
|
|
||||||
}
|
|
||||||
|
|
||||||
if other_action.name == "stop"{
|
mut other_actions := plbook.find(filter: 'caddy.')!
|
||||||
console.print_debug("install action caddy.${other_action.name}")
|
for other_action in other_actions {
|
||||||
caddy_obj.stop()!
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
}
|
mut p := other_action.params
|
||||||
if other_action.name == "restart"{
|
reset := p.get_default_false('reset')
|
||||||
console.print_debug("install action caddy.${other_action.name}")
|
if other_action.name == 'destroy' || reset {
|
||||||
caddy_obj.restart()!
|
console.print_debug('install action caddy.destroy')
|
||||||
}
|
destroy_()!
|
||||||
}
|
}
|
||||||
}
|
if other_action.name == 'install' {
|
||||||
|
console.print_debug('install action caddy.install')
|
||||||
|
install_()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
|
mut p := other_action.params
|
||||||
|
name := p.get('name')!
|
||||||
|
mut caddy_obj := get(name: name)!
|
||||||
|
console.print_debug('action object:\n${caddy_obj}')
|
||||||
|
if other_action.name == 'start' {
|
||||||
|
console.print_debug('install action caddy.${other_action.name}')
|
||||||
|
caddy_obj.start()!
|
||||||
|
}
|
||||||
|
|
||||||
|
if other_action.name == 'stop' {
|
||||||
|
console.print_debug('install action caddy.${other_action.name}')
|
||||||
|
caddy_obj.stop()!
|
||||||
|
}
|
||||||
|
if other_action.name == 'restart' {
|
||||||
|
console.print_debug('install action caddy.${other_action.name}')
|
||||||
|
caddy_obj.restart()!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// load from disk and make sure is properly intialized
|
||||||
//load from disk and make sure is properly intialized
|
|
||||||
pub fn (mut self CaddyServer) reload() ! {
|
pub fn (mut self CaddyServer) reload() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self=obj_init(self)!
|
self = obj_init(self)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self CaddyServer) start() ! {
|
pub fn (mut self CaddyServer) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('caddy start')
|
console.print_header('caddy start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting caddy with ${zprocess.startuptype}...')
|
console.print_debug('starting caddy with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('caddy did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('caddy did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self CaddyServer) install_start(model InstallArgs) ! {
|
pub fn (mut self CaddyServer) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self CaddyServer) stop() ! {
|
pub fn (mut self CaddyServer) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self CaddyServer) restart() ! {
|
pub fn (mut self CaddyServer) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self CaddyServer) running() !bool {
|
pub fn (mut self CaddyServer) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module imagemagick
|
module imagemagick
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
imagemagick_global map[string]&ImageMagick
|
imagemagick_global map[string]&ImageMagick
|
||||||
imagemagick_default string
|
imagemagick_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ImageMagick) start() ! {
|
pub fn (mut self ImageMagick) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('imagemagick start')
|
console.print_header('imagemagick start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
|
console.print_debug('starting imagemagick with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('imagemagick did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('imagemagick did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ImageMagick) install_start(model InstallArgs) ! {
|
pub fn (mut self ImageMagick) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ImageMagick) stop() ! {
|
pub fn (mut self ImageMagick) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ImageMagick) restart() ! {
|
pub fn (mut self ImageMagick) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ImageMagick) running() !bool {
|
pub fn (mut self ImageMagick) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,137 @@
|
|||||||
|
|
||||||
module lighttpd
|
module lighttpd
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
lighttpd_global map[string]&LightHttpdInstaller
|
lighttpd_global map[string]&LightHttpdInstaller
|
||||||
lighttpd_default string
|
lighttpd_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||||
// unknown
|
// unknown
|
||||||
// screen
|
// screen
|
||||||
// zinit
|
// zinit
|
||||||
// tmux
|
// tmux
|
||||||
// systemd
|
// systemd
|
||||||
match cat{
|
match cat {
|
||||||
.zinit{
|
.zinit {
|
||||||
console.print_debug("startupmanager: zinit")
|
console.print_debug('startupmanager: zinit')
|
||||||
return startupmanager.get(cat:.zinit)!
|
return startupmanager.get(cat: .zinit)!
|
||||||
}
|
}
|
||||||
.systemd{
|
.systemd {
|
||||||
console.print_debug("startupmanager: systemd")
|
console.print_debug('startupmanager: systemd')
|
||||||
return startupmanager.get(cat:.systemd)!
|
return startupmanager.get(cat: .systemd)!
|
||||||
}else{
|
}
|
||||||
console.print_debug("startupmanager: auto")
|
else {
|
||||||
return startupmanager.get()!
|
console.print_debug('startupmanager: auto')
|
||||||
}
|
return startupmanager.get()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LightHttpdInstaller) start() ! {
|
pub fn (mut self LightHttpdInstaller) start() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if self.running()!{
|
if self.running()! {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.print_header('lighttpd start')
|
console.print_header('lighttpd start')
|
||||||
|
|
||||||
if ! installed_()!{
|
if !installed_()! {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
configure()!
|
configure()!
|
||||||
|
|
||||||
start_pre()!
|
start_pre()!
|
||||||
|
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
|
|
||||||
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
|
console.print_debug('starting lighttpd with ${zprocess.startuptype}...')
|
||||||
|
|
||||||
sm.new(zprocess)!
|
sm.new(zprocess)!
|
||||||
|
|
||||||
sm.start(zprocess.name)!
|
sm.start(zprocess.name)!
|
||||||
}
|
}
|
||||||
|
|
||||||
start_post()!
|
start_post()!
|
||||||
|
|
||||||
for _ in 0 .. 50 {
|
|
||||||
if self.running()! {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.sleep(100 * time.millisecond)
|
|
||||||
}
|
|
||||||
return error('lighttpd did not install properly.')
|
|
||||||
|
|
||||||
|
for _ in 0 .. 50 {
|
||||||
|
if self.running()! {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.sleep(100 * time.millisecond)
|
||||||
|
}
|
||||||
|
return error('lighttpd did not install properly.')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LightHttpdInstaller) install_start(model InstallArgs) ! {
|
pub fn (mut self LightHttpdInstaller) install_start(model InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(model)!
|
self.install(model)!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LightHttpdInstaller) stop() ! {
|
pub fn (mut self LightHttpdInstaller) stop() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
stop_pre()!
|
stop_pre()!
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
sm.stop(zprocess.name)!
|
sm.stop(zprocess.name)!
|
||||||
}
|
}
|
||||||
stop_post()!
|
stop_post()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LightHttpdInstaller) restart() ! {
|
pub fn (mut self LightHttpdInstaller) restart() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.stop()!
|
self.stop()!
|
||||||
self.start()!
|
self.start()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self LightHttpdInstaller) running() !bool {
|
pub fn (mut self LightHttpdInstaller) running() !bool {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
|
|
||||||
//walk over the generic processes, if not running return
|
// walk over the generic processes, if not running return
|
||||||
for zprocess in startupcmd()!{
|
for zprocess in startupcmd()! {
|
||||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||||
r:=sm.running(zprocess.name)!
|
r := sm.running(zprocess.name)!
|
||||||
if r==false{
|
if r == false {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return running()!
|
return running()!
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn install(args InstallArgs) ! {
|
pub fn install(args InstallArgs) ! {
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy() ! {
|
pub fn destroy() ! {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build() ! {
|
pub fn build() ! {
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,98 +1,81 @@
|
|||||||
|
|
||||||
module tailwind
|
module tailwind
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
tailwind_global map[string]&Tailwind
|
tailwind_global map[string]&Tailwind
|
||||||
tailwind_default string
|
tailwind_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = tailwind_default
|
model.name = tailwind_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&Tailwind {
|
pub fn get(args_ ArgsGet) !&Tailwind {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in tailwind_global) {
|
if args.name !in tailwind_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("tailwind",model.name,heroscript_default()!)!
|
context.hero_config_set('tailwind', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tailwind_global[args.name] or {
|
return tailwind_global[args.name] or {
|
||||||
println(tailwind_global)
|
println(tailwind_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for tailwind
|
||||||
//switch instance to be used for tailwind
|
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
tailwind_default = name
|
tailwind_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self Tailwind) install(args InstallArgs) ! {
|
pub fn (mut self Tailwind) install(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self Tailwind) destroy() ! {
|
pub fn (mut self Tailwind) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,102 +1,86 @@
|
|||||||
|
|
||||||
module zola
|
module zola
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core.base
|
import freeflowuniverse.herolib.core.base
|
||||||
import freeflowuniverse.herolib.core.playbook
|
import freeflowuniverse.herolib.core.playbook
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||||
import freeflowuniverse.herolib.osal.zinit
|
import freeflowuniverse.herolib.osal.zinit
|
||||||
import time
|
import time
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
zola_global map[string]&ZolaInstaller
|
zola_global map[string]&ZolaInstaller
|
||||||
zola_default string
|
zola_default string
|
||||||
)
|
)
|
||||||
|
|
||||||
/////////FACTORY
|
/////////FACTORY
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct ArgsGet{
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_get (args_ ArgsGet) ArgsGet {
|
fn args_get(args_ ArgsGet) ArgsGet {
|
||||||
mut model:=args_
|
mut model := args_
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = zola_default
|
model.name = zola_default
|
||||||
}
|
}
|
||||||
if model.name == ""{
|
if model.name == '' {
|
||||||
model.name = "default"
|
model.name = 'default'
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&ZolaInstaller {
|
pub fn get(args_ ArgsGet) !&ZolaInstaller {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
if !(args.name in zola_global) {
|
if args.name !in zola_global {
|
||||||
if args.name=="default"{
|
if args.name == 'default' {
|
||||||
if ! config_exists(args){
|
if !config_exists(args) {
|
||||||
if default{
|
if default {
|
||||||
mut context:=base.context() or { panic("bug") }
|
mut context := base.context() or { panic('bug') }
|
||||||
context.hero_config_set("zola",model.name,heroscript_default()!)!
|
context.hero_config_set('zola', model.name, heroscript_default()!)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load(args)!
|
load(args)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return zola_global[args.name] or {
|
return zola_global[args.name] or {
|
||||||
println(zola_global)
|
println(zola_global)
|
||||||
panic("could not get config for ${args.name} with name:${model.name}")
|
panic('could not get config for ${args.name} with name:${model.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct InstallArgs{
|
pub struct InstallArgs {
|
||||||
pub mut:
|
pub mut:
|
||||||
reset bool
|
reset bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch instance to be used for zola
|
||||||
//switch instance to be used for zola
|
|
||||||
pub fn switch(name string) {
|
pub fn switch(name string) {
|
||||||
zola_default = name
|
zola_default = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut self ZolaInstaller) install(args InstallArgs) ! {
|
pub fn (mut self ZolaInstaller) install(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
if args.reset {
|
if args.reset {
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
if ! (installed_()!){
|
if !(installed_()!) {
|
||||||
install_()!
|
install_()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZolaInstaller) build() ! {
|
pub fn (mut self ZolaInstaller) build() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
build_()!
|
build_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut self ZolaInstaller) destroy() ! {
|
pub fn (mut self ZolaInstaller) destroy() ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
destroy_()!
|
destroy_()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ pub fn usr_local_path() !string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return the source statement if the profile exists
|
// return the source statement if the profile exists
|
||||||
pub fn profile_path_source()! string {
|
pub fn profile_path_source() !string {
|
||||||
if hostname() or { '' } == 'rescue' {
|
if hostname() or { '' } == 'rescue' {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ pub fn profile_path_source()! string {
|
|||||||
|
|
||||||
// return source $path && .
|
// return source $path && .
|
||||||
// or empty if it doesn't exist
|
// or empty if it doesn't exist
|
||||||
pub fn profile_path_source_and()! string {
|
pub fn profile_path_source_and() !string {
|
||||||
if hostname() or { '' } == 'rescue' {
|
if hostname() or { '' } == 'rescue' {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
@@ -245,16 +245,15 @@ pub fn cmd_delete(cmd string) ! {
|
|||||||
res := cmd_path(cmd2) or { '' }
|
res := cmd_path(cmd2) or { '' }
|
||||||
if res.len > 0 {
|
if res.len > 0 {
|
||||||
if os.exists(res) {
|
if os.exists(res) {
|
||||||
if core.sudo_path_ok(res)!{
|
if core.sudo_path_ok(res)! {
|
||||||
os.rm(res)!
|
os.rm(res)!
|
||||||
}else{
|
} else {
|
||||||
if core.interactive()!{
|
if core.interactive()! {
|
||||||
execute_silent("sudo rm -rf ${res}")!
|
execute_silent('sudo rm -rf ${res}')!
|
||||||
}else{
|
} else {
|
||||||
return error("can't remove ${res} as sudo because non interactive as part of cmd delete.")
|
return error("can't remove ${res} as sudo because non interactive as part of cmd delete.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +304,7 @@ pub fn profile_paths_preferred() ![]string {
|
|||||||
return profile_files2
|
return profile_files2
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn profile_path()! string {
|
pub fn profile_path() !string {
|
||||||
if core.is_osx()! {
|
if core.is_osx()! {
|
||||||
return '${os.home_dir()}/.zprofile'
|
return '${os.home_dir()}/.zprofile'
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ fn (err JobError) msg() string {
|
|||||||
if err.error_type == .args {
|
if err.error_type == .args {
|
||||||
return 'Error in arguments:\n${err.job.cmd}'
|
return 'Error in arguments:\n${err.job.cmd}'
|
||||||
}
|
}
|
||||||
mut msg := ""
|
mut msg := ''
|
||||||
if err.job.cmd.ignore_error{
|
if err.job.cmd.ignore_error {
|
||||||
return 'Ignore error for ${err.job.cmd.scriptpath}\n'
|
return 'Ignore error for ${err.job.cmd.scriptpath}\n'
|
||||||
}else{
|
} else {
|
||||||
if err.error_type == .timeout {
|
if err.error_type == .timeout {
|
||||||
return 'Execution failed timeout\n${err.job}'
|
return 'Execution failed timeout\n${err.job}'
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ pub mut:
|
|||||||
//```
|
//```
|
||||||
// return Job .
|
// return Job .
|
||||||
pub fn exec(cmd_ Command) !Job {
|
pub fn exec(cmd_ Command) !Job {
|
||||||
mut cmd:=cmd_
|
mut cmd := cmd_
|
||||||
mut job := Job{
|
mut job := Job{
|
||||||
cmd: cmd
|
cmd: cmd
|
||||||
}
|
}
|
||||||
@@ -169,8 +169,8 @@ pub fn exec(cmd_ Command) !Job {
|
|||||||
os.execvp(scriptpath, [])!
|
os.execvp(scriptpath, [])!
|
||||||
return job
|
return job
|
||||||
}
|
}
|
||||||
if cmd.ignore_error{
|
if cmd.ignore_error {
|
||||||
cmd.retry=0
|
cmd.retry = 0
|
||||||
}
|
}
|
||||||
if !cmd.async {
|
if !cmd.async {
|
||||||
job.execute_retry() or {
|
job.execute_retry() or {
|
||||||
@@ -187,7 +187,7 @@ pub fn (mut job Job) execute_retry() ! {
|
|||||||
for x in 0 .. job.cmd.retry + 1 {
|
for x in 0 .. job.cmd.retry + 1 {
|
||||||
job.execute() or {
|
job.execute() or {
|
||||||
if x == job.cmd.retry {
|
if x == job.cmd.retry {
|
||||||
//println(job)
|
// println(job)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,25 +207,24 @@ pub fn (mut job Job) execute() ! {
|
|||||||
job.start = time.now()
|
job.start = time.now()
|
||||||
job.status = .running
|
job.status = .running
|
||||||
|
|
||||||
|
|
||||||
job.cmd.scriptpath = cmd_to_script_path(job.cmd)!
|
job.cmd.scriptpath = cmd_to_script_path(job.cmd)!
|
||||||
|
|
||||||
if job.cmd.debug{
|
if job.cmd.debug {
|
||||||
console.print_debug(job)
|
console.print_debug(job)
|
||||||
}
|
}
|
||||||
|
|
||||||
if job.cmd.debug{
|
if job.cmd.debug {
|
||||||
console.print_debug(" - process execute ${job.cmd.scriptpath}")
|
console.print_debug(' - process execute ${job.cmd.scriptpath}')
|
||||||
}
|
}
|
||||||
mut p := os.new_process(job.cmd.scriptpath)
|
mut p := os.new_process(job.cmd.scriptpath)
|
||||||
|
|
||||||
if job.cmd.work_folder.len > 0 {
|
if job.cmd.work_folder.len > 0 {
|
||||||
p.set_work_folder(job.cmd.work_folder)
|
p.set_work_folder(job.cmd.work_folder)
|
||||||
}
|
}
|
||||||
if job.cmd.environment.len > 0 {
|
if job.cmd.environment.len > 0 {
|
||||||
if job.cmd.debug{
|
if job.cmd.debug {
|
||||||
console.print_debug(" - process setargs ${job.cmd.environment}")
|
console.print_debug(' - process setargs ${job.cmd.environment}')
|
||||||
}
|
}
|
||||||
p.set_environment(job.cmd.environment)
|
p.set_environment(job.cmd.environment)
|
||||||
}
|
}
|
||||||
p.set_redirect_stdio()
|
p.set_redirect_stdio()
|
||||||
@@ -236,7 +235,7 @@ pub fn (mut job Job) execute() ! {
|
|||||||
p.run()
|
p.run()
|
||||||
job.process = p
|
job.process = p
|
||||||
|
|
||||||
//initial check, no point reading the output if we can't get the process starting
|
// initial check, no point reading the output if we can't get the process starting
|
||||||
// NOT OK TO DO BECAUSE IF PROCESS FINISHED WITHOUT ISSUE THEN NOT OK
|
// NOT OK TO DO BECAUSE IF PROCESS FINISHED WITHOUT ISSUE THEN NOT OK
|
||||||
// if ! p.is_alive() {
|
// if ! p.is_alive() {
|
||||||
// if job.cmd.debug{
|
// if job.cmd.debug{
|
||||||
@@ -290,8 +289,8 @@ pub fn (mut job Job) process() ! {
|
|||||||
// result=job.read()!
|
// result=job.read()!
|
||||||
if time.now().unix() > job.start.unix() + job.cmd.timeout * 1000 {
|
if time.now().unix() > job.start.unix() + job.cmd.timeout * 1000 {
|
||||||
// console.print_stderr("TIMEOUT TIMEOUT TIMEOUT TIMEOUT")
|
// console.print_stderr("TIMEOUT TIMEOUT TIMEOUT TIMEOUT")
|
||||||
if job.cmd.debug{
|
if job.cmd.debug {
|
||||||
console.print_stderr("***TIMEOUT TIMEOUT TIMEOUT TIMEOUT***")
|
console.print_stderr('***TIMEOUT TIMEOUT TIMEOUT TIMEOUT***')
|
||||||
}
|
}
|
||||||
p.signal_pgkill()
|
p.signal_pgkill()
|
||||||
p.close()
|
p.close()
|
||||||
@@ -306,14 +305,14 @@ pub fn (mut job Job) process() ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ! job.cmd.ignore_error && job.cmd.debug{
|
if !job.cmd.ignore_error && job.cmd.debug {
|
||||||
console.print_stderr(" - process stopped (don't know if error)")
|
console.print_stderr(" - process stopped (don't know if error)")
|
||||||
}
|
}
|
||||||
job.read()!
|
job.read()!
|
||||||
job.read()!
|
job.read()!
|
||||||
job.status = .done
|
job.status = .done
|
||||||
if p.code > 0 {
|
if p.code > 0 {
|
||||||
if job.cmd.debug{
|
if job.cmd.debug {
|
||||||
console.print_stderr(' ########## Process result code is > 0: ${p.code}')
|
console.print_stderr(' ########## Process result code is > 0: ${p.code}')
|
||||||
}
|
}
|
||||||
job.exit_code = p.code
|
job.exit_code = p.code
|
||||||
@@ -396,11 +395,11 @@ pub fn (mut job Job) close() ! {
|
|||||||
os.rm(job.cmd.scriptpath)!
|
os.rm(job.cmd.scriptpath)!
|
||||||
}
|
}
|
||||||
|
|
||||||
if job.cmd.ignore_error{
|
if job.cmd.ignore_error {
|
||||||
job.status = .done
|
job.status = .done
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if job.cmd.raise_error && job.exit_code > 0 {
|
if job.cmd.raise_error && job.exit_code > 0 {
|
||||||
return JobError{
|
return JobError{
|
||||||
job: job
|
job: job
|
||||||
error_type: .exec
|
error_type: .exec
|
||||||
@@ -449,7 +448,7 @@ pub fn cmd_exists(cmd string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_exists_profile(cmd string) bool {
|
pub fn cmd_exists_profile(cmd string) bool {
|
||||||
cmd1 := '${profile_path_source_and() or {panic(err)}} which ${cmd}'
|
cmd1 := '${profile_path_source_and() or { panic(err) }} which ${cmd}'
|
||||||
res := os.execute(cmd1)
|
res := os.execute(cmd1)
|
||||||
if res.exit_code > 0 {
|
if res.exit_code > 0 {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -39,42 +39,39 @@ pub fn dir_reset(path string) ! {
|
|||||||
// can be \n or , separated
|
// can be \n or , separated
|
||||||
pub fn rm(todelete_ string) ! {
|
pub fn rm(todelete_ string) ! {
|
||||||
for mut item in texttools.to_array(todelete_) {
|
for mut item in texttools.to_array(todelete_) {
|
||||||
if item.trim_space() == ''|| item.trim_space().starts_with("#"){
|
if item.trim_space() == '' || item.trim_space().starts_with('#') {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if item.len <2{
|
if item.len < 2 {
|
||||||
return error("not allowed to remove anything with less than 2 chars. ${item}")
|
return error('not allowed to remove anything with less than 2 chars. ${item}')
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item.replace('~', os.home_dir())
|
item = item.replace('~', os.home_dir())
|
||||||
console.print_debug(' - rm: ${item}')
|
console.print_debug(' - rm: ${item}')
|
||||||
if item.starts_with('/') {
|
if item.starts_with('/') {
|
||||||
if os.exists(item) {
|
if os.exists(item) {
|
||||||
|
|
||||||
if os.is_dir(item) {
|
if os.is_dir(item) {
|
||||||
if core.sudo_path_ok(item)!{
|
if core.sudo_path_ok(item)! {
|
||||||
//console.print_debug("rm deletedir: ${item}")
|
// console.print_debug("rm deletedir: ${item}")
|
||||||
os.rmdir_all(item)!
|
os.rmdir_all(item)!
|
||||||
}else{
|
} else {
|
||||||
if core.interactive()!{
|
if core.interactive()! {
|
||||||
execute_silent("sudo rm -rf ${item}")!
|
execute_silent('sudo rm -rf ${item}')!
|
||||||
}else{
|
} else {
|
||||||
return error("can't remove ${item} as sudo because non interactive")
|
return error("can't remove ${item} as sudo because non interactive")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//console.print_debug("rm delete file: ${item}")
|
// console.print_debug("rm delete file: ${item}")
|
||||||
if core.sudo_path_ok(item)!{
|
if core.sudo_path_ok(item)! {
|
||||||
os.rm(item)!
|
os.rm(item)!
|
||||||
}else{
|
} else {
|
||||||
if core.interactive()!{
|
if core.interactive()! {
|
||||||
execute_silent("sudo rm -f ${item}")!
|
execute_silent('sudo rm -f ${item}')!
|
||||||
}else{
|
} else {
|
||||||
return error("can't remove ${item} as sudo because non interactive")
|
return error("can't remove ${item} as sudo because non interactive")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ pub fn package_install(name_ string) ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// remove a package using the right commands per platform
|
// remove a package using the right commands per platform
|
||||||
pub fn package_remove(name_ string) ! {
|
pub fn package_remove(name_ string) ! {
|
||||||
names := texttools.to_array(name_)
|
names := texttools.to_array(name_)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
module osal
|
module osal
|
||||||
|
|
||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
|
|
||||||
fn test_package_management() {
|
fn test_package_management() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module docker
|
module docker
|
||||||
|
|
||||||
import freeflowuniverse.herolib.osal {exec}
|
import freeflowuniverse.herolib.osal { exec }
|
||||||
import freeflowuniverse.herolib.core.texttools
|
import freeflowuniverse.herolib.core.texttools
|
||||||
import freeflowuniverse.herolib.virt.utils
|
import freeflowuniverse.herolib.virt.utils
|
||||||
import freeflowuniverse.herolib.core
|
import freeflowuniverse.herolib.core
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ pub fn (mut h HetznerManager) server_reset(args ServerRebootArgs) !ResetInfo {
|
|||||||
if serveractive {
|
if serveractive {
|
||||||
for {
|
for {
|
||||||
console.print_debug('wait for server ${serverinfo.server_name} to go down.')
|
console.print_debug('wait for server ${serverinfo.server_name} to go down.')
|
||||||
if osal.ping(address: serverinfo.server_ip)!= .ok {
|
if osal.ping(address: serverinfo.server_ip) != .ok {
|
||||||
console.print_debug('server ${serverinfo.server_name} is now down, now waitig for reboot.')
|
console.print_debug('server ${serverinfo.server_name} is now down, now waitig for reboot.')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user