wip: fix gitea & postgresql installers
Co-authored-by: omda <mahmmoud.hassanein@gmail.com>
This commit is contained in:
@@ -2,10 +2,9 @@ module postgresql
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import time
|
||||
|
||||
__global (
|
||||
@@ -15,94 +14,91 @@ __global (
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
// set the model in mem and the config on the filesystem
|
||||
pub fn set(o Postgresql) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
postgresql_global[o.name] = &o2
|
||||
postgresql_default = o.name
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
// check we find the config on the filesystem
|
||||
pub fn exists(args_ ArgsGet) bool {
|
||||
mut model := args_get(args_)
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = postgresql_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&Postgresql {
|
||||
mut args := args_get(args_)
|
||||
if args.name !in postgresql_global {
|
||||
if !config_exists() {
|
||||
if default {
|
||||
config_save()!
|
||||
}
|
||||
}
|
||||
config_load()!
|
||||
}
|
||||
return postgresql_global[args.name] or {
|
||||
println(postgresql_global)
|
||||
panic('bug in get from factory: ')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('postgresql', model.name)
|
||||
return context.hero_config_exists('postgresql', args.name)
|
||||
}
|
||||
|
||||
// load the config error if it doesn't exist
|
||||
pub fn load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('postgresql', model.name)!
|
||||
mut heroscript := context.hero_config_get('postgresql', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
// save the config to the filesystem in the context
|
||||
pub fn save(o Postgresql) ! {
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
heroscript := encoderhero.encode[Postgresql](o)!
|
||||
context.hero_config_set('postgresql', model.name, heroscript)!
|
||||
context.hero_config_set('postgresql', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o Postgresql) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
postgresql_global['default'] = &o2
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
|
||||
start bool
|
||||
stop bool
|
||||
restart bool
|
||||
delete bool
|
||||
configure bool // make sure there is at least one installed
|
||||
}
|
||||
|
||||
pub fn play(args_ PlayArgs) ! {
|
||||
mut model := args_
|
||||
mut args := args_
|
||||
|
||||
if model.heroscript == '' {
|
||||
model.heroscript = heroscript_default()!
|
||||
if args.heroscript == '' {
|
||||
args.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := model.plbook or { playbook.new(text: model.heroscript)! }
|
||||
mut plbook := args.plbook or { playbook.new(text: args.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.')!
|
||||
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 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()!
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'postgresql.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,12 +107,6 @@ pub fn play(args_ PlayArgs) ! {
|
||||
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self Postgresql) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
||||
// unknown
|
||||
// screen
|
||||
@@ -139,6 +129,12 @@ fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManag
|
||||
}
|
||||
}
|
||||
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self Postgresql) reload() ! {
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self Postgresql) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
@@ -176,9 +172,9 @@ pub fn (mut self Postgresql) start() ! {
|
||||
return error('postgresql did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self Postgresql) install_start(model InstallArgs) ! {
|
||||
pub fn (mut self Postgresql) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(model)!
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
@@ -209,7 +205,7 @@ pub fn (mut self Postgresql) running() !bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return running()!
|
||||
return running_()!
|
||||
}
|
||||
|
||||
@[params]
|
||||
@@ -218,15 +214,21 @@ pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn install(args InstallArgs) ! {
|
||||
if args.reset {
|
||||
destroy()!
|
||||
}
|
||||
if !(installed_()!) {
|
||||
pub fn (mut self Postgresql) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed_()!) {
|
||||
install_()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy() ! {
|
||||
pub fn (mut self Postgresql) destroy() ! {
|
||||
switch(self.name)
|
||||
|
||||
self.stop() or {}
|
||||
destroy_()!
|
||||
}
|
||||
|
||||
// switch instance to be used for postgresql
|
||||
pub fn switch(name string) {
|
||||
postgresql_default = name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user