fix: simplify meilisearch destroy action
- Remove unnecessary code from the `destroy` function in the `meilisearchinstaller_actions.v` file. - NOTE: Couldn't test it due to the new hero update, don't know how even send the configs, WIP.
This commit is contained in:
@@ -151,33 +151,7 @@ fn build() ! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn destroy() ! {
|
fn destroy() ! {
|
||||||
// mut systemdfactory := systemd.new()!
|
osal.process_kill_recursive(name: 'meilisearch')!
|
||||||
// systemdfactory.destroy("zinit")!
|
osal.cmd_delete('meilisearch')!
|
||||||
|
osal.package_remove('meilisearch') or { println('') }
|
||||||
// osal.process_kill_recursive(name:'zinit')!
|
|
||||||
// osal.cmd_delete('zinit')!
|
|
||||||
|
|
||||||
// osal.package_remove('
|
|
||||||
// podman
|
|
||||||
// conmon
|
|
||||||
// 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
|
|
||||||
// ")!
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
module meilisearchinstaller
|
|
||||||
|
|
||||||
// import freeflowuniverse.herolib.osal
|
|
||||||
// import freeflowuniverse.herolib.ui.console
|
|
||||||
// import freeflowuniverse.herolib.core.texttools
|
|
||||||
// import freeflowuniverse.herolib.osal.zinit
|
|
||||||
// import freeflowuniverse.herolib.installers.ulist
|
|
||||||
// // import freeflowuniverse.herolib.installers.lang.rust
|
|
||||||
// import os
|
|
||||||
|
|
||||||
// fn installed_() !bool {
|
|
||||||
// res := os.execute('${osal.profile_path_source_and()!} meilisearch -V')
|
|
||||||
// if res.exit_code != 0 {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
|
||||||
// if r.len != 1 {
|
|
||||||
// return error("couldn't parse meilisearch version.\n${res.output}")
|
|
||||||
// }
|
|
||||||
// r2 := r[0].all_after('meilisearch').trim(' ')
|
|
||||||
// if texttools.version(version) != texttools.version(r2) {
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn install_() ! {
|
|
||||||
// console.print_header('install meilisearch')
|
|
||||||
// mut url := ''
|
|
||||||
|
|
||||||
// if core.is_linux_arm()! {
|
|
||||||
// url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-aarch64'
|
|
||||||
// } else if core.is_linux_intel()! {
|
|
||||||
// url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-linux-amd64'
|
|
||||||
// } else if core.is_osx_arm()! {
|
|
||||||
// url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-apple-silicon'
|
|
||||||
// } else if core.is_osx_intel()! {
|
|
||||||
// url = 'https://github.com/meilisearch/meilisearch/releases/download/v${version}/meilisearch-macos-amd64'
|
|
||||||
// } else {
|
|
||||||
// return error('unsported platform')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// mut dest := osal.download(
|
|
||||||
// url: url
|
|
||||||
// minsize_kb: 100000
|
|
||||||
// expand_dir: '/tmp/meilisearch'
|
|
||||||
// )!
|
|
||||||
|
|
||||||
// // dest.moveup_single_subdir()!
|
|
||||||
|
|
||||||
// mut binpath := dest.file_get('meilisearch')!
|
|
||||||
// osal.cmd_add(
|
|
||||||
// cmdname: 'meilisearch'
|
|
||||||
// source: binpath.path
|
|
||||||
// )!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn build_() ! {
|
|
||||||
// // mut installer := get()!
|
|
||||||
// // url := 'https://github.com/threefoldtech/meilisearch'
|
|
||||||
|
|
||||||
// // console.print_header('compile meilisearch')
|
|
||||||
// // rust.install()!
|
|
||||||
// // mut dest_on_os := '${os.home_dir()}/hero/bin'
|
|
||||||
// // if core.is_linux()! {
|
|
||||||
// // dest_on_os = '/usr/local/bin'
|
|
||||||
// // }
|
|
||||||
// // console.print_debug(' - dest path for meilisearchs is on: ${dest_on_os}')
|
|
||||||
// // //osal.package_install('pkg-config,openssl')!
|
|
||||||
// // cmd := '
|
|
||||||
// // echo "start meilisearch installer"
|
|
||||||
// // set +ex
|
|
||||||
// // source ~/.cargo/env > /dev/null 2>&1
|
|
||||||
|
|
||||||
// // //TODO
|
|
||||||
|
|
||||||
// // cargo install meilisearch
|
|
||||||
|
|
||||||
// // cp ${os.home_dir()}/.cargo/bin/mdb* ${dest_on_os}/
|
|
||||||
// // '
|
|
||||||
// // defer {
|
|
||||||
// // destroy()!
|
|
||||||
// // }
|
|
||||||
// // osal.execute_stdout(cmd)!
|
|
||||||
// // osal.done_set('install_meilisearch', 'OK')!
|
|
||||||
// // console.print_header('meilisearch installed')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // get the Upload List of the files
|
|
||||||
// fn ulist_get() !ulist.UList {
|
|
||||||
// // mut installer := get()!
|
|
||||||
// // optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
|
||||||
// return ulist.UList{}
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // uploads to S3 server if configured
|
|
||||||
// fn upload_() ! {
|
|
||||||
// // mut installer := get()!
|
|
||||||
// // installers.upload(
|
|
||||||
// // cmdname: 'meilisearch'
|
|
||||||
// // source: '${gitpath}/target/x86_64-unknown-linux-musl/release/meilisearch'
|
|
||||||
// // )!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn startupcmd() ![]zinit.ZProcessNewArgs {
|
|
||||||
// mut res := []zinit.ZProcessNewArgs{}
|
|
||||||
// mut installer := get()!
|
|
||||||
// mut env := 'development'
|
|
||||||
// if installer.production {
|
|
||||||
// env = 'production'
|
|
||||||
// }
|
|
||||||
// res << zinit.ZProcessNewArgs{
|
|
||||||
// name: 'meilisearch'
|
|
||||||
// cmd: 'meilisearch --no-analytics --http-addr ${installer.host}:${installer.port} --env ${env} --db-path ${installer.path} --master-key ${installer.masterkey}'
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return res
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn running_() !bool {
|
|
||||||
// mut installer := get()!
|
|
||||||
// // THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
|
||||||
// // this checks health of meilisearch
|
|
||||||
// // curl http://localhost:3333/api/v1/s --oauth2-bearer 1234 works
|
|
||||||
// // url:='http://127.0.0.1:${cfg.port}/api/v1'
|
|
||||||
// // mut conn := httpconnection.new(name: 'meilisearch', url: url)!
|
|
||||||
|
|
||||||
// // if cfg.secret.len > 0 {
|
|
||||||
// // conn.default_header.add(.authorization, 'Bearer ${cfg.secret}')
|
|
||||||
// // }
|
|
||||||
// // conn.default_header.add(.content_type, 'application/json')
|
|
||||||
// // console.print_debug("curl -X 'GET' '${url}'/tags --oauth2-bearer ${cfg.secret}")
|
|
||||||
// // r := conn.get_json_dict(prefix: 'tags', debug: false) or {return false}
|
|
||||||
// // println(r)
|
|
||||||
// // if true{panic("ssss")}
|
|
||||||
// // tags := r['Tags'] or { return false }
|
|
||||||
// // console.print_debug(tags)
|
|
||||||
// // console.print_debug('meilisearch is answering.')
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn start_pre() ! {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn start_post() ! {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn stop_pre() ! {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn stop_post() ! {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn destroy_() ! {
|
|
||||||
// // mut systemdfactory := systemd.new()!
|
|
||||||
// // systemdfactory.destroy("meilisearch")!
|
|
||||||
|
|
||||||
// osal.process_kill_recursive(name: 'meilisearch')!
|
|
||||||
|
|
||||||
// osal.cmd_delete('meilisearch')!
|
|
||||||
|
|
||||||
// osal.package_remove('
|
|
||||||
// meilisearch
|
|
||||||
// ') or { println('') }
|
|
||||||
|
|
||||||
// // osal.rm("
|
|
||||||
// // ")!
|
|
||||||
// }
|
|
||||||
@@ -3,289 +3,277 @@ 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.paramsparser
|
|
||||||
|
|
||||||
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 args:=args_
|
mut args := args_
|
||||||
if args.name == ""{
|
if args.name == '' {
|
||||||
args.name = "default"
|
args.name = 'default'
|
||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args_ ArgsGet) !&MeilisearchServer {
|
pub fn get(args_ ArgsGet) !&MeilisearchServer {
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
mut obj := MeilisearchServer{}
|
mut obj := MeilisearchServer{}
|
||||||
if !(args.name in meilisearchinstaller_global) {
|
if args.name !in meilisearchinstaller_global {
|
||||||
if ! exists(args)!{
|
if !exists(args)! {
|
||||||
set(obj)!
|
set(obj)!
|
||||||
}else{
|
} else {
|
||||||
heroscript := context.hero_config_get("meilisearchinstaller",args.name)!
|
heroscript := context.hero_config_get('meilisearchinstaller', args.name)!
|
||||||
mut obj_:=heroscript_loads(heroscript)!
|
mut obj_ := heroscript_loads(heroscript)!
|
||||||
set_in_mem(obj_)!
|
set_in_mem(obj_)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meilisearchinstaller_global[args.name] or {
|
return meilisearchinstaller_global[args.name] or {
|
||||||
println(meilisearchinstaller_global)
|
println(meilisearchinstaller_global)
|
||||||
//bug if we get here because should be in globals
|
// bug if we get here because should be in globals
|
||||||
panic("could not get config for meilisearchinstaller with name, is bug:${args.name}")
|
panic('could not get config for meilisearchinstaller with name, is bug:${args.name}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//register the config for the future
|
// register the config for the future
|
||||||
pub fn set(o MeilisearchServer)! {
|
pub fn set(o MeilisearchServer) ! {
|
||||||
set_in_mem(o)!
|
set_in_mem(o)!
|
||||||
mut context := base.context()!
|
mut context := base.context()!
|
||||||
heroscript := heroscript_dumps(o)!
|
heroscript := heroscript_dumps(o)!
|
||||||
context.hero_config_set("meilisearchinstaller", o.name, heroscript)!
|
context.hero_config_set('meilisearchinstaller', o.name, heroscript)!
|
||||||
}
|
}
|
||||||
|
|
||||||
//does the config exists?
|
// does the config exists?
|
||||||
pub fn exists(args_ ArgsGet)! bool {
|
pub fn exists(args_ ArgsGet) !bool {
|
||||||
mut context := base.context()!
|
mut context := base.context()!
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
return context.hero_config_exists("meilisearchinstaller", args.name)
|
return context.hero_config_exists('meilisearchinstaller', args.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(args_ ArgsGet)! {
|
pub fn delete(args_ ArgsGet) ! {
|
||||||
mut args := args_get(args_)
|
mut args := args_get(args_)
|
||||||
mut context:=base.context()!
|
mut context := base.context()!
|
||||||
context.hero_config_delete("meilisearchinstaller",args.name)!
|
context.hero_config_delete('meilisearchinstaller', args.name)!
|
||||||
if args.name in meilisearchinstaller_global {
|
if args.name in meilisearchinstaller_global {
|
||||||
//del meilisearchinstaller_global[args.name]
|
// del meilisearchinstaller_global[args.name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//only sets in mem, does not set as config
|
// only sets in mem, does not set as config
|
||||||
fn set_in_mem(o MeilisearchServer)! {
|
fn set_in_mem(o MeilisearchServer) ! {
|
||||||
mut o2:=obj_init(o)!
|
mut o2 := obj_init(o)!
|
||||||
meilisearchinstaller_global[o.name] = &o2
|
meilisearchinstaller_global[o.name] = &o2
|
||||||
meilisearchinstaller_default = o.name
|
meilisearchinstaller_default = o.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@[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 args := args_
|
||||||
mut args:=args_
|
|
||||||
|
|
||||||
|
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||||
|
|
||||||
mut plbook := args.plbook or {
|
mut install_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
|
||||||
playbook.new(text: args.heroscript)!
|
if install_actions.len > 0 {
|
||||||
}
|
for install_action in install_actions {
|
||||||
|
heroscript := install_action.heroscript()
|
||||||
mut install_actions := plbook.find(filter: 'meilisearchinstaller.configure')!
|
mut obj2 := heroscript_loads(heroscript)!
|
||||||
if install_actions.len > 0 {
|
set(obj2)!
|
||||||
for install_action in install_actions {
|
}
|
||||||
heroscript:=install_action.heroscript()
|
}
|
||||||
mut obj2:=heroscript_loads(heroscript)!
|
|
||||||
set(obj2)!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
|
mut other_actions := plbook.find(filter: 'meilisearchinstaller.')!
|
||||||
for other_action in other_actions {
|
for other_action in other_actions {
|
||||||
if other_action.name in ["destroy","install","build"]{
|
if other_action.name in ['destroy', 'install', 'build'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
reset:=p.get_default_false("reset")
|
reset := p.get_default_false('reset')
|
||||||
if other_action.name == "destroy" || reset{
|
if other_action.name == 'destroy' || reset {
|
||||||
console.print_debug("install action meilisearchinstaller.destroy")
|
console.print_debug('install action meilisearchinstaller.destroy')
|
||||||
destroy()!
|
destroy()!
|
||||||
}
|
}
|
||||||
if other_action.name == "install"{
|
if other_action.name == 'install' {
|
||||||
console.print_debug("install action meilisearchinstaller.install")
|
console.print_debug('install action meilisearchinstaller.install')
|
||||||
install()!
|
install()!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if other_action.name in ["start","stop","restart"]{
|
if other_action.name in ['start', 'stop', 'restart'] {
|
||||||
mut p := other_action.params
|
mut p := other_action.params
|
||||||
name := p.get('name')!
|
name := p.get('name')!
|
||||||
mut meilisearchinstaller_obj:=get(name:name)!
|
mut meilisearchinstaller_obj := get(name: name)!
|
||||||
console.print_debug("action object:\n${meilisearchinstaller_obj}")
|
console.print_debug('action object:\n${meilisearchinstaller_obj}')
|
||||||
if other_action.name == "start"{
|
if other_action.name == 'start' {
|
||||||
console.print_debug("install action meilisearchinstaller.${other_action.name}")
|
console.print_debug('install action meilisearchinstaller.${other_action.name}')
|
||||||
meilisearchinstaller_obj.start()!
|
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()!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 ///////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
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()!
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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)!
|
||||||
}
|
}
|
||||||
|
|
||||||
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(args InstallArgs) ! {
|
pub fn (mut self MeilisearchServer) install_start(args InstallArgs) ! {
|
||||||
switch(self.name)
|
switch(self.name)
|
||||||
self.install(args)!
|
self.install(args)!
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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 || (!installed()!) {
|
if args.reset || (!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()!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helpers
|
||||||
//helpers
|
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
pub struct DefaultConfigArgs{
|
pub struct DefaultConfigArgs {
|
||||||
instance string = 'default'
|
instance string = 'default'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,281 +0,0 @@
|
|||||||
module meilisearchinstaller
|
|
||||||
|
|
||||||
// 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 time
|
|
||||||
|
|
||||||
// __global (
|
|
||||||
// meilisearchinstaller_global map[string]&MeilisearchServer
|
|
||||||
// meilisearchinstaller_default string
|
|
||||||
// )
|
|
||||||
|
|
||||||
// /////////FACTORY
|
|
||||||
|
|
||||||
// @[params]
|
|
||||||
// pub struct ArgsGet {
|
|
||||||
// pub mut:
|
|
||||||
// name string
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn args_get(args_ ArgsGet) ArgsGet {
|
|
||||||
// mut model := args_
|
|
||||||
// if model.name == '' {
|
|
||||||
// model.name = meilisearchinstaller_default
|
|
||||||
// }
|
|
||||||
// if model.name == '' {
|
|
||||||
// model.name = 'default'
|
|
||||||
// }
|
|
||||||
// return model
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn get(args_ ArgsGet) !&MeilisearchServer {
|
|
||||||
// mut args := args_get(args_)
|
|
||||||
// if args.name !in meilisearchinstaller_global {
|
|
||||||
// if args.name == 'default' {
|
|
||||||
// if !config_exists(args) {
|
|
||||||
// if default {
|
|
||||||
// mut context := base.context() or { panic('bug') }
|
|
||||||
// context.hero_config_set('meilisearchinstaller', model.name, heroscript_default()!)!
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// load(args)!
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return meilisearchinstaller_global[args.name] or {
|
|
||||||
// println(meilisearchinstaller_global)
|
|
||||||
// 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) ! {
|
|
||||||
// mut o2 := obj_init(o)!
|
|
||||||
// meilisearchinstaller_global[o.name] = &o2
|
|
||||||
// meilisearchinstaller_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() or { panic('bug') }
|
|
||||||
// return context.hero_config_exists('meilisearchinstaller', 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('meilisearchinstaller', model.name)!
|
|
||||||
// play(heroscript: heroscript)!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // save the config to the filesystem in the context
|
|
||||||
// pub fn save(o MeilisearchServer) ! {
|
|
||||||
// mut context := base.context()!
|
|
||||||
// heroscript := encoderhero.encode[MeilisearchServer](o)!
|
|
||||||
// context.hero_config_set('meilisearchinstaller', model.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: '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.')!
|
|
||||||
// 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 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 ///////////////////////////////////
|
|
||||||
// ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// // load from disk and make sure is properly intialized
|
|
||||||
// pub fn (mut self MeilisearchServer) reload() ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// self = obj_init(self)!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 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 MeilisearchServer) start() ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// if self.running()! {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// console.print_header('meilisearchinstaller start')
|
|
||||||
|
|
||||||
// if !installed_()! {
|
|
||||||
// install_()!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// configure()!
|
|
||||||
|
|
||||||
// start_pre()!
|
|
||||||
|
|
||||||
// for zprocess in startupcmd()! {
|
|
||||||
// mut sm := startupmanager_get(zprocess.startuptype)!
|
|
||||||
|
|
||||||
// console.print_debug('starting meilisearchinstaller 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('meilisearchinstaller did not install properly.')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) install_start(model InstallArgs) ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// self.install(model)!
|
|
||||||
// self.start()!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) 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 MeilisearchServer) restart() ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// self.stop()!
|
|
||||||
// self.start()!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) 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
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // switch instance to be used for meilisearchinstaller
|
|
||||||
// pub fn switch(name string) {
|
|
||||||
// meilisearchinstaller_default = name
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) install(args InstallArgs) ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// if args.reset {
|
|
||||||
// destroy_()!
|
|
||||||
// }
|
|
||||||
// if !(installed_()!) {
|
|
||||||
// install_()!
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) build() ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// build_()!
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn (mut self MeilisearchServer) destroy() ! {
|
|
||||||
// switch(self.name)
|
|
||||||
// self.stop() or {}
|
|
||||||
// destroy_()!
|
|
||||||
// }
|
|
||||||
@@ -25,6 +25,21 @@ fn obj_init(mycfg_ MeilisearchServer) !MeilisearchServer {
|
|||||||
return error('masterkey is empty')
|
return error('masterkey is empty')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mycfg.path == '' {
|
||||||
|
mycfg.path = '/tmp/meilisearch'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.host == '' {
|
||||||
|
mycfg.host = 'localhost'
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.port == 0 {
|
||||||
|
mycfg.port = 7700
|
||||||
|
}
|
||||||
|
|
||||||
|
if mycfg.name == '' {
|
||||||
|
mycfg.name = 'default'
|
||||||
|
}
|
||||||
return mycfg
|
return mycfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user