161 lines
3.3 KiB
V
161 lines
3.3 KiB
V
|
|
module imagemagick
|
|
|
|
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 (
|
|
imagemagick_global map[string]&ImageMagick
|
|
imagemagick_default string
|
|
)
|
|
|
|
/////////FACTORY
|
|
|
|
@[params]
|
|
pub struct ArgsGet{
|
|
pub mut:
|
|
name string
|
|
}
|
|
|
|
pub fn get(args_ ArgsGet) !&ImageMagick {
|
|
return &ImageMagick{}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//////////////////////////# 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 ImageMagick) start() ! {
|
|
switch(self.name)
|
|
if self.running()!{
|
|
return
|
|
}
|
|
|
|
console.print_header('imagemagick start')
|
|
|
|
if ! installed()!{
|
|
install()!
|
|
}
|
|
|
|
configure()!
|
|
|
|
start_pre()!
|
|
|
|
for zprocess in startupcmd()!{
|
|
mut sm:=startupmanager_get(zprocess.startuptype)!
|
|
|
|
console.print_debug('starting imagemagick 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('imagemagick did not install properly.')
|
|
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) install_start(model InstallArgs) ! {
|
|
switch(self.name)
|
|
self.install(model)!
|
|
self.start()!
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) 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 ImageMagick) restart() ! {
|
|
switch(self.name)
|
|
self.stop()!
|
|
self.start()!
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) running() !bool {
|
|
switch(self.name)
|
|
|
|
//walk over the generic processes, if not running return
|
|
for zprocess in startupcmd()!{
|
|
mut sm:=startupmanager_get(zprocess.startuptype)!
|
|
r:=sm.running(zprocess.name)!
|
|
if r==false{
|
|
return false
|
|
}
|
|
}
|
|
return running()!
|
|
}
|
|
|
|
@[params]
|
|
pub struct InstallArgs{
|
|
pub mut:
|
|
reset bool
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) install(model InstallArgs) ! {
|
|
switch(self.name)
|
|
if model.reset || (!installed()!) {
|
|
install()!
|
|
}
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) build() ! {
|
|
switch(self.name)
|
|
build()!
|
|
}
|
|
|
|
pub fn (mut self ImageMagick) destroy() ! {
|
|
switch(self.name)
|
|
self.stop() or {}
|
|
destroy()!
|
|
}
|
|
|
|
|
|
|
|
//switch instance to be used for imagemagick
|
|
pub fn switch(name string) {
|
|
imagemagick_default = name
|
|
}
|