138 lines
2.6 KiB
V
138 lines
2.6 KiB
V
module restic
|
|
|
|
import freeflowuniverse.herolib.core.base
|
|
import freeflowuniverse.herolib.core.playbook
|
|
import freeflowuniverse.herolib.ui.console
|
|
import freeflowuniverse.herolib.sysadmin.startupmanager
|
|
import freeflowuniverse.herolib.osal.zinit
|
|
import time
|
|
|
|
__global (
|
|
restic_global map[string]&Restic
|
|
restic_default string
|
|
)
|
|
|
|
/////////FACTORY
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
fn startupmanager_get(cat zinit.StartupManagerType) !startupmanager.StartupManager {
|
|
// unknown
|
|
// screen
|
|
// zinit
|
|
// tmux
|
|
// systemd
|
|
match cat {
|
|
.zinit {
|
|
console.print_debug('startupmanager: zinit')
|
|
return startupmanager.get(cat: .zinit)!
|
|
}
|
|
.systemd {
|
|
console.print_debug('startupmanager: systemd')
|
|
return startupmanager.get(cat: .systemd)!
|
|
}
|
|
else {
|
|
console.print_debug('startupmanager: auto')
|
|
return startupmanager.get()!
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn (mut self Restic) start() ! {
|
|
switch(self.name)
|
|
if self.running()! {
|
|
return
|
|
}
|
|
|
|
console.print_header('restic start')
|
|
|
|
if !installed_()! {
|
|
install_()!
|
|
}
|
|
|
|
configure()!
|
|
|
|
start_pre()!
|
|
|
|
for zprocess in startupcmd()! {
|
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
|
|
|
console.print_debug('starting restic with ${zprocess.startuptype}...')
|
|
|
|
sm.new(zprocess)!
|
|
|
|
sm.start(zprocess.name)!
|
|
}
|
|
|
|
start_post()!
|
|
|
|
for _ in 0 .. 50 {
|
|
if self.running()! {
|
|
return
|
|
}
|
|
time.sleep(100 * time.millisecond)
|
|
}
|
|
return error('restic did not install properly.')
|
|
}
|
|
|
|
pub fn (mut self Restic) install_start(model InstallArgs) ! {
|
|
switch(self.name)
|
|
self.install(model)!
|
|
self.start()!
|
|
}
|
|
|
|
pub fn (mut self Restic) stop() ! {
|
|
switch(self.name)
|
|
stop_pre()!
|
|
for zprocess in startupcmd()! {
|
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
|
sm.stop(zprocess.name)!
|
|
}
|
|
stop_post()!
|
|
}
|
|
|
|
pub fn (mut self Restic) restart() ! {
|
|
switch(self.name)
|
|
self.stop()!
|
|
self.start()!
|
|
}
|
|
|
|
pub fn (mut self Restic) running() !bool {
|
|
switch(self.name)
|
|
|
|
// walk over the generic processes, if not running return
|
|
for zprocess in startupcmd()! {
|
|
mut sm := startupmanager_get(zprocess.startuptype)!
|
|
r := sm.running(zprocess.name)!
|
|
if r == false {
|
|
return false
|
|
}
|
|
}
|
|
return running()!
|
|
}
|
|
|
|
@[params]
|
|
pub struct InstallArgs {
|
|
pub mut:
|
|
reset bool
|
|
}
|
|
|
|
pub fn install(args InstallArgs) ! {
|
|
if args.reset {
|
|
destroy()!
|
|
}
|
|
if !(installed_()!) {
|
|
install_()!
|
|
}
|
|
}
|
|
|
|
pub fn destroy() ! {
|
|
destroy_()!
|
|
}
|
|
|
|
pub fn build() ! {
|
|
build_()!
|
|
}
|