wip: fix gitea & postgresql installers

Co-authored-by: omda <mahmmoud.hassanein@gmail.com>
This commit is contained in:
2025-01-05 19:29:54 +02:00
parent d5d5eab855
commit f7309f2433
10 changed files with 585 additions and 480 deletions

View File

@@ -2,18 +2,107 @@ module gitea
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
import freeflowuniverse.herolib.osal.zinit
import freeflowuniverse.herolib.ui.console
import time
__global (
gitea_global map[string]&GiteaInstaller
gitea_global map[string]&GiteaServer
gitea_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string = 'default'
}
fn args_get(args_ ArgsGet) ArgsGet {
mut args := args_
if args.name == '' {
args.name = gitea_default
}
if args.name == '' {
args.name = 'default'
}
return args
}
pub fn get(args_ ArgsGet) !&GiteaServer {
mut args := args_get(args_)
if args.name !in gitea_global {
if !config_exists() {
if default {
config_save()!
}
}
config_load()!
}
return gitea_global[args.name] or {
println(gitea_global)
panic('failed to get gitea server for ${args.name}')
}
}
fn config_exists(args_ ArgsGet) bool {
mut args := args_get(args_)
mut context := base.context() or { panic('bug') }
return context.hero_config_exists('gitea', args.name)
}
fn config_load(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()!
mut heroscript := context.hero_config_get('gitea', args.name)!
play(heroscript: heroscript)!
}
fn config_save(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()!
context.hero_config_set('gitea', args.name, heroscript_default()!)!
}
fn set(o GiteaServer) ! {
mut o2 := obj_init(o)!
gitea_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 args := args_
if args.heroscript == '' {
args.heroscript = heroscript_default()!
}
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut install_actions := plbook.find(filter: 'gitea.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
mut p := install_action.params
cfg_play(p)!
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -40,7 +129,13 @@ fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManag
}
}
pub fn (mut self GiteaInstaller) start() ! {
// load from disk and make sure is properly intialized
pub fn (mut self GiteaServer) reload() ! {
switch(self.name)
self = obj_init(self)!
}
pub fn (mut self GiteaServer) start() ! {
switch(self.name)
if self.running()! {
return
@@ -48,8 +143,8 @@ pub fn (mut self GiteaInstaller) start() ! {
console.print_header('gitea start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,13 +172,13 @@ pub fn (mut self GiteaInstaller) start() ! {
return error('gitea did not install properly.')
}
pub fn (mut self GiteaInstaller) install_start(model InstallArgs) ! {
pub fn (mut self GiteaServer) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
pub fn (mut self GiteaInstaller) stop() ! {
pub fn (mut self GiteaServer) stop() ! {
switch(self.name)
stop_pre()!
for zprocess in startupcmd()! {
@@ -93,13 +188,13 @@ pub fn (mut self GiteaInstaller) stop() ! {
stop_post()!
}
pub fn (mut self GiteaInstaller) restart() ! {
pub fn (mut self GiteaServer) restart() ! {
switch(self.name)
self.stop()!
self.start()!
}
pub fn (mut self GiteaInstaller) running() !bool {
pub fn (mut self GiteaServer) running() !bool {
switch(self.name)
// walk over the generic processes, if not running return
@@ -119,19 +214,26 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self GiteaServer) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self GiteaServer) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self GiteaServer) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for gitea
pub fn switch(name string) {
gitea_default = name
}