...
This commit is contained in:
@@ -10,174 +10,171 @@ import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.core.httpconnection
|
||||
import freeflowuniverse.herolib.installers.lang.golang
|
||||
|
||||
|
||||
import os
|
||||
|
||||
fn startupcmd () ![]zinit.ZProcessNewArgs{
|
||||
mut args := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
cmd := "coredns -conf '${args.config_path}'"
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'coredns'
|
||||
cmd: cmd
|
||||
}
|
||||
return res
|
||||
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut args := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
cmd := "coredns -conf '${args.config_path}'"
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'coredns'
|
||||
cmd: cmd
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
mut installer := get()!
|
||||
mut installer := get()!
|
||||
mut conn := httpconnection.new(name: 'coredns', url: 'http://localhost:3334')!
|
||||
r := conn.get(prefix: 'health')!
|
||||
if r.trim_space() == 'OK' {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
fn start_pre()!{
|
||||
fix()!
|
||||
fn start_pre() ! {
|
||||
fix()!
|
||||
}
|
||||
|
||||
fn start_post()!{
|
||||
set_local_dns()
|
||||
fn start_post() ! {
|
||||
set_local_dns()
|
||||
}
|
||||
|
||||
fn stop_pre()!{
|
||||
|
||||
fn stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post()!{
|
||||
|
||||
fn stop_post() ! {
|
||||
}
|
||||
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()!} coredns version')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().starts_with('CoreDNS-'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse coredns version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after_first('CoreDNS-')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
res := os.execute('${osal.profile_path_source_and()!} coredns version')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.trim_space().starts_with('CoreDNS-'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse coredns version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after_first('CoreDNS-')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//get the Upload List of the files
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
//optionally build a UList which is all paths which are result of building, is then used e.g. in upload
|
||||
return ulist.UList{}
|
||||
// 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
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'coredns'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/coredns'
|
||||
// )!
|
||||
|
||||
// installers.upload(
|
||||
// cmdname: 'coredns'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/coredns'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install coredns')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_arm64.tgz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_amd64.tgz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_arm64.tgz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_amd64.tgz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
console.print_header('install coredns')
|
||||
build()! // because we need the plugins
|
||||
// mut url := ''
|
||||
// if core.is_linux_arm()! {
|
||||
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_arm64.tgz'
|
||||
// } else if core.is_linux_intel()! {
|
||||
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_linux_amd64.tgz'
|
||||
// } else if core.is_osx_arm()! {
|
||||
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_arm64.tgz'
|
||||
// } else if core.is_osx_intel()! {
|
||||
// url = 'https://github.com/coredns/coredns/releases/download/v${version}/coredns_${version}_darwin_amd64.tgz'
|
||||
// } else {
|
||||
// return error('unsported platform')
|
||||
// }
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 13000
|
||||
expand_dir: '/tmp/coredns'
|
||||
)!
|
||||
// mut dest := osal.download(
|
||||
// url: url
|
||||
// minsize_kb: 13000
|
||||
// expand_dir: '/tmp/coredns'
|
||||
// )!
|
||||
|
||||
mut binpath := dest.file_get('coredns')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'coredns'
|
||||
source: binpath.path
|
||||
)!
|
||||
// mut binpath := dest.file_get('coredns')!
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'coredns'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
}
|
||||
|
||||
fn build() ! {
|
||||
url := 'https://github.com/coredns/coredns'
|
||||
url := 'https://github.com/coredns/coredns'
|
||||
|
||||
if core.platform()! != .ubuntu {
|
||||
return error('only support ubuntu for now')
|
||||
}
|
||||
mut g:=golang.get()!
|
||||
g.install()!
|
||||
if core.platform()! != .ubuntu {
|
||||
return error('only support ubuntu for now')
|
||||
}
|
||||
mut g := golang.get()!
|
||||
g.install()!
|
||||
|
||||
console.print_header('build coredns')
|
||||
console.print_header('build coredns')
|
||||
|
||||
mut gs := gittools.new(coderoot: '~/code')!
|
||||
mut gs := gittools.new()!
|
||||
|
||||
gitpath := gs.get_repo(url: url, reset: true, pull: true)!
|
||||
gitpath := gs.get_path(
|
||||
pull: true
|
||||
reset: true
|
||||
url: url
|
||||
)!
|
||||
|
||||
cmd := '
|
||||
// set the plugins file on right location
|
||||
pluginsfile := $tmpl('templates/plugin.cfg')
|
||||
mut path := pathlib.get_file(path: '${gitpath}/plugin.cfg', create: true)!
|
||||
path.write(pluginsfile)!
|
||||
|
||||
cmd := '
|
||||
cd ${gitpath}
|
||||
make
|
||||
'
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
//now copy to the default bin path
|
||||
// mut binpath := dest.file_get('...')!
|
||||
// adds it to path
|
||||
// osal.cmd_add(
|
||||
// cmdname: 'griddriver2'
|
||||
// source: binpath.path
|
||||
// )!
|
||||
osal.execute_stdout(cmd)!
|
||||
|
||||
// now copy to the default bin path
|
||||
mut codedir := pathlib.get_dir(path: '${gitpath}', create: false)!
|
||||
mut binpath := codedir.file_get('coredns')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'coredns'
|
||||
source: binpath.path
|
||||
)!
|
||||
}
|
||||
|
||||
fn destroy() ! {
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
// osal.process_kill_recursive(name:'zinit')!
|
||||
// osal.cmd_delete('zinit')!
|
||||
|
||||
// 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
|
||||
// ")!
|
||||
// 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
|
||||
// ")!
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ pub fn configure() ! {
|
||||
|
||||
set_global_dns()
|
||||
|
||||
|
||||
if args.config_url.len > 0 {
|
||||
mut repo := gs.get_repo(
|
||||
url: args.config_url
|
||||
@@ -42,17 +41,15 @@ pub fn configure() ! {
|
||||
mut path := pathlib.get_file(path: args.config_path, create: true)!
|
||||
path.write(mycorefile)!
|
||||
|
||||
if args.example{
|
||||
example_configure() !
|
||||
if args.example {
|
||||
example_configure()!
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn example_configure() ! {
|
||||
mut args := get()!
|
||||
|
||||
myipaddr:=osal.ipaddr_pub_get()!
|
||||
|
||||
myipaddr := osal.ipaddr_pub_get_check()!
|
||||
|
||||
exampledbfile := $tmpl('templates/ourexample.org')
|
||||
|
||||
|
||||
@@ -4,288 +4,277 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
coredns_global map[string]&CoreDNS
|
||||
coredns_default string
|
||||
coredns_global map[string]&CoreDNS
|
||||
coredns_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut args:=args_
|
||||
if args.name == ""{
|
||||
args.name = "default"
|
||||
}
|
||||
return args
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&CoreDNS {
|
||||
mut context:=base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := CoreDNS{}
|
||||
if !(args.name in coredns_global) {
|
||||
if ! exists(args)!{
|
||||
set(obj)!
|
||||
}else{
|
||||
heroscript := context.hero_config_get("coredns",args.name)!
|
||||
mut obj_:=heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return coredns_global[args.name] or {
|
||||
println(coredns_global)
|
||||
//bug if we get here because should be in globals
|
||||
panic("could not get config for coredns with name, is bug:${args.name}")
|
||||
}
|
||||
pub fn get(args_ ArgsGet) !&CoreDNS {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := CoreDNS{}
|
||||
if args.name !in coredns_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('coredns', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return coredns_global[args.name] or {
|
||||
println(coredns_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for coredns with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
//register the config for the future
|
||||
pub fn set(o CoreDNS)! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set("coredns", o.name, heroscript)!
|
||||
// register the config for the future
|
||||
pub fn set(o CoreDNS) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('coredns', o.name, heroscript)!
|
||||
}
|
||||
|
||||
//does the config exists?
|
||||
pub fn exists(args_ ArgsGet)! bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists("coredns", args.name)
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('coredns', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet)! {
|
||||
mut args := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
context.hero_config_delete("coredns",args.name)!
|
||||
if args.name in coredns_global {
|
||||
//del coredns_global[args.name]
|
||||
}
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('coredns', args.name)!
|
||||
if args.name in coredns_global {
|
||||
// del coredns_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
//only sets in mem, does not set as config
|
||||
fn set_in_mem(o CoreDNS)! {
|
||||
mut o2:=obj_init(o)!
|
||||
coredns_global[o.name] = &o2
|
||||
coredns_default = o.name
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o CoreDNS) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
coredns_global[o.name] = &o2
|
||||
coredns_default = o.name
|
||||
}
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
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 {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'coredns.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript:=install_action.heroscript()
|
||||
mut obj2:=heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'coredns.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'coredns.')!
|
||||
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 coredns.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action coredns.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut coredns_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${coredns_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action coredns.${other_action.name}")
|
||||
coredns_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action coredns.${other_action.name}")
|
||||
coredns_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action coredns.${other_action.name}")
|
||||
coredns_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'coredns.')!
|
||||
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 coredns.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action coredns.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut coredns_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${coredns_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action coredns.${other_action.name}')
|
||||
coredns_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action coredns.${other_action.name}')
|
||||
coredns_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action coredns.${other_action.name}')
|
||||
coredns_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load from disk and make sure is properly intialized
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self CoreDNS) reload() ! {
|
||||
switch(self.name)
|
||||
self=obj_init(self)!
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('coredns start')
|
||||
console.print_header('coredns start')
|
||||
|
||||
if ! installed()!{
|
||||
install()!
|
||||
}
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting coredns with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting coredns with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('coredns did not install properly.')
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('coredns did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
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 CoreDNS) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) running() !bool {
|
||||
switch(self.name)
|
||||
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()!
|
||||
// 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 struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self CoreDNS) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for coredns
|
||||
// switch instance to be used for coredns
|
||||
pub fn switch(name string) {
|
||||
coredns_default = name
|
||||
coredns_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -5,58 +5,58 @@ import net
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
fn is_systemd_resolved_active() bool {
|
||||
result := os.execute('systemctl is-active systemd-resolved')
|
||||
return result.exit_code == 0 && result.output.trim_space() == 'active'
|
||||
result := os.execute('systemctl is-active systemd-resolved')
|
||||
return result.exit_code == 0 && result.output.trim_space() == 'active'
|
||||
}
|
||||
|
||||
fn disable_systemd_resolved() {
|
||||
console.print_debug('Stopping and disabling systemd-resolved...')
|
||||
os.execute('sudo systemctl stop systemd-resolved')
|
||||
os.execute('sudo systemctl disable systemd-resolved')
|
||||
os.execute('sudo systemctl mask systemd-resolved')
|
||||
console.print_debug('Stopping and disabling systemd-resolved...')
|
||||
os.execute('sudo systemctl stop systemd-resolved')
|
||||
os.execute('sudo systemctl disable systemd-resolved')
|
||||
os.execute('sudo systemctl mask systemd-resolved')
|
||||
}
|
||||
|
||||
fn is_dns_port_free() bool {
|
||||
result := os.execute("sudo ss -tunlp | grep ':53 '")
|
||||
return result.exit_code != 0
|
||||
result := os.execute("sudo ss -tunlp | grep ':53 '")
|
||||
return result.exit_code != 0
|
||||
}
|
||||
|
||||
fn set_local_dns() {
|
||||
console.print_debug('Updating /etc/resolv.conf to use local DNS...')
|
||||
os.execute('sudo rm -f /etc/resolv.conf')
|
||||
os.write_file('/etc/resolv.conf', 'nameserver 127.0.0.1\n') or {
|
||||
console.print_debug('Failed to update /etc/resolv.conf')
|
||||
return
|
||||
}
|
||||
console.print_debug('/etc/resolv.conf updated successfully.')
|
||||
console.print_debug('Updating /etc/resolv.conf to use local DNS...')
|
||||
os.execute('sudo rm -f /etc/resolv.conf')
|
||||
os.write_file('/etc/resolv.conf', 'nameserver 127.0.0.1\n') or {
|
||||
console.print_debug('Failed to update /etc/resolv.conf')
|
||||
return
|
||||
}
|
||||
console.print_debug('/etc/resolv.conf updated successfully.')
|
||||
}
|
||||
|
||||
fn set_global_dns() {
|
||||
console.print_debug('Updating /etc/resolv.conf to use local DNS...')
|
||||
os.execute('sudo rm -f /etc/resolv.conf')
|
||||
os.write_file('/etc/resolv.conf', 'nameserver 8.8.8.8\n') or {
|
||||
console.print_debug('Failed to update /etc/resolv.conf')
|
||||
return
|
||||
}
|
||||
console.print_debug('/etc/resolv.conf updated successfully for global.')
|
||||
console.print_debug('Updating /etc/resolv.conf to use local DNS...')
|
||||
os.execute('sudo rm -f /etc/resolv.conf')
|
||||
os.write_file('/etc/resolv.conf', 'nameserver 8.8.8.8\n') or {
|
||||
console.print_debug('Failed to update /etc/resolv.conf')
|
||||
return
|
||||
}
|
||||
console.print_debug('/etc/resolv.conf updated successfully for global.')
|
||||
}
|
||||
|
||||
pub fn fix()! {
|
||||
console.print_debug('Checking if systemd-resolved is active...')
|
||||
if is_systemd_resolved_active() {
|
||||
disable_systemd_resolved()
|
||||
} else {
|
||||
println('systemd-resolved is already disabled.')
|
||||
}
|
||||
pub fn fix() ! {
|
||||
console.print_debug('Checking if systemd-resolved is active...')
|
||||
if is_systemd_resolved_active() {
|
||||
disable_systemd_resolved()
|
||||
} else {
|
||||
println('systemd-resolved is already disabled.')
|
||||
}
|
||||
|
||||
console.print_debug('Checking if DNS UDP port 53 is free...')
|
||||
if is_dns_port_free() {
|
||||
console.print_debug('UDP port 53 is free.')
|
||||
} else {
|
||||
console.print_debug('UDP port 53 is still in use. Ensure CoreDNS or another service is properly set up.')
|
||||
return
|
||||
}
|
||||
console.print_debug('Checking if DNS UDP port 53 is free...')
|
||||
if is_dns_port_free() {
|
||||
console.print_debug('UDP port 53 is free.')
|
||||
} else {
|
||||
console.print_debug('UDP port 53 is still in use. Ensure CoreDNS or another service is properly set up.')
|
||||
return
|
||||
}
|
||||
|
||||
set_global_dns()
|
||||
console.print_debug('Setup complete. Ensure CoreDNS is running.')
|
||||
set_global_dns()
|
||||
console.print_debug('Setup complete. Ensure CoreDNS is running.')
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module coredns
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
@@ -7,36 +8,32 @@ pub const version = '1.12.0'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct CoreDNS {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
config_path string
|
||||
config_url string // path to Corefile through e.g. git url, will pull it if it is not local yet
|
||||
dnszones_path string // path to where all the dns zones are
|
||||
dnszones_url string // path on git url pull if needed (is comma or \n separated list)
|
||||
name string = 'default'
|
||||
config_path string
|
||||
config_url string // path to Corefile through e.g. git url, will pull it if it is not local yet
|
||||
dnszones_path string // path to where all the dns zones are
|
||||
dnszones_url string // path on git url pull if needed (is comma or \n separated list)
|
||||
plugins string // list of plugins to build CoreDNS with (is comma or \n separated list)
|
||||
example bool = true // if true we will install examples
|
||||
example bool = true // if true we will install examples
|
||||
}
|
||||
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ CoreDNS)!CoreDNS{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ CoreDNS) !CoreDNS {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj CoreDNS) !string {
|
||||
return encoderhero.encode[CoreDNS ](obj)!
|
||||
return encoderhero.encode[CoreDNS](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !CoreDNS {
|
||||
mut obj := encoderhero.decode[CoreDNS](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[CoreDNS](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
log
|
||||
errors
|
||||
health :3334
|
||||
auto ${args.dnszones_path} {
|
||||
reload 30s
|
||||
}
|
||||
redis {
|
||||
address localhost:6379
|
||||
connect_timeout 100
|
||||
read_timeout 100
|
||||
ttl 360
|
||||
prefix dns:
|
||||
}
|
||||
}
|
||||
|
||||
68
lib/installers/infra/coredns/templates/plugin.cfg
Normal file
68
lib/installers/infra/coredns/templates/plugin.cfg
Normal file
@@ -0,0 +1,68 @@
|
||||
# Directives are registered in the order they should be executed.
|
||||
#
|
||||
# Ordering is VERY important. Every plugin will feel the effects of all other
|
||||
# plugin below (after) them during a request, but they must not care what plugin
|
||||
# above them are doing.
|
||||
|
||||
# How to rebuild with updated plugin configurations: Modify the list below and
|
||||
# run `go generate && go build`
|
||||
|
||||
# The parser takes the input format of:
|
||||
#
|
||||
# <plugin-name>:<package-name>
|
||||
# Or
|
||||
# <plugin-name>:<fully-qualified-package-name>
|
||||
#
|
||||
# External plugin example:
|
||||
#
|
||||
# log:github.com/coredns/coredns/plugin/log
|
||||
# Local plugin example:
|
||||
# log:log
|
||||
#etcd:etcd
|
||||
|
||||
root:root
|
||||
metadata:metadata
|
||||
geoip:geoip
|
||||
cancel:cancel
|
||||
tls:tls
|
||||
timeouts:timeouts
|
||||
multisocket:multisocket
|
||||
reload:reload
|
||||
nsid:nsid
|
||||
bufsize:bufsize
|
||||
bind:bind
|
||||
debug:debug
|
||||
trace:trace
|
||||
ready:ready
|
||||
health:health
|
||||
pprof:pprof
|
||||
prometheus:metrics
|
||||
errors:errors
|
||||
log:log
|
||||
dnstap:dnstap
|
||||
local:local
|
||||
dns64:dns64
|
||||
acl:acl
|
||||
any:any
|
||||
chaos:chaos
|
||||
loadbalance:loadbalance
|
||||
tsig:tsig
|
||||
cache:cache
|
||||
rewrite:rewrite
|
||||
header:header
|
||||
dnssec:dnssec
|
||||
autopath:autopath
|
||||
minimal:minimal
|
||||
template:template
|
||||
transfer:transfer
|
||||
hosts:hosts
|
||||
file:file
|
||||
secondary:secondary
|
||||
loop:loop
|
||||
forward:forward
|
||||
erratic:erratic
|
||||
whoami:whoami
|
||||
on:github.com/coredns/caddy/onevent
|
||||
sign:sign
|
||||
view:view
|
||||
redis:github.com/codysnider/coredns-redis
|
||||
@@ -4,288 +4,277 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
mycelium_global map[string]&MyceliumInstaller
|
||||
mycelium_default string
|
||||
mycelium_installer_global map[string]&MyceliumInstaller
|
||||
mycelium_installer_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut args:=args_
|
||||
if args.name == ""{
|
||||
args.name = "default"
|
||||
}
|
||||
return args
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
||||
mut context:=base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MyceliumInstaller{}
|
||||
if !(args.name in mycelium_global) {
|
||||
if ! exists(args)!{
|
||||
set(obj)!
|
||||
}else{
|
||||
heroscript := context.hero_config_get("mycelium",args.name)!
|
||||
mut obj_:=heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_global[args.name] or {
|
||||
println(mycelium_global)
|
||||
//bug if we get here because should be in globals
|
||||
panic("could not get config for mycelium with name, is bug:${args.name}")
|
||||
}
|
||||
pub fn get(args_ ArgsGet) !&MyceliumInstaller {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MyceliumInstaller{}
|
||||
if args.name !in mycelium_installer_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('mycelium', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mycelium_installer_global[args.name] or {
|
||||
println(mycelium_installer_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for mycelium with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
//register the config for the future
|
||||
pub fn set(o MyceliumInstaller)! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set("mycelium", o.name, heroscript)!
|
||||
// register the config for the future
|
||||
pub fn set(o MyceliumInstaller) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('mycelium', o.name, heroscript)!
|
||||
}
|
||||
|
||||
//does the config exists?
|
||||
pub fn exists(args_ ArgsGet)! bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists("mycelium", args.name)
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('mycelium', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet)! {
|
||||
mut args := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
context.hero_config_delete("mycelium",args.name)!
|
||||
if args.name in mycelium_global {
|
||||
//del mycelium_global[args.name]
|
||||
}
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('mycelium', args.name)!
|
||||
if args.name in mycelium_installer_global {
|
||||
// del mycelium_installer_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
//only sets in mem, does not set as config
|
||||
fn set_in_mem(o MyceliumInstaller)! {
|
||||
mut o2:=obj_init(o)!
|
||||
mycelium_global[o.name] = &o2
|
||||
mycelium_default = o.name
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MyceliumInstaller) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
mycelium_installer_global[o.name] = &o2
|
||||
mycelium_installer_default = o.name
|
||||
}
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
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 {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript:=install_action.heroscript()
|
||||
mut obj2:=heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'mycelium.')!
|
||||
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 mycelium.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action mycelium.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut mycelium_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${mycelium_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action mycelium.${other_action.name}")
|
||||
mycelium_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'mycelium.')!
|
||||
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 mycelium.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action mycelium.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut mycelium_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${mycelium_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action mycelium.${other_action.name}')
|
||||
mycelium_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load from disk and make sure is properly intialized
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self MyceliumInstaller) reload() ! {
|
||||
switch(self.name)
|
||||
self=obj_init(self)!
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('mycelium start')
|
||||
console.print_header('mycelium start')
|
||||
|
||||
if ! installed()!{
|
||||
install()!
|
||||
}
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting mycelium with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('mycelium did not install properly.')
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('mycelium did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
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 MyceliumInstaller) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) running() !bool {
|
||||
switch(self.name)
|
||||
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()!
|
||||
// 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 struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) build() ! {
|
||||
switch(self.name)
|
||||
build()!
|
||||
switch(self.name)
|
||||
build()!
|
||||
}
|
||||
|
||||
pub fn (mut self MyceliumInstaller) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for mycelium
|
||||
// switch instance to be used for mycelium
|
||||
pub fn switch(name string) {
|
||||
mycelium_default = name
|
||||
mycelium_installer_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import crypto.bcrypt
|
||||
// generate_htpasswd creates an Apache-style htpasswd entry for the given user and password
|
||||
// using bcrypt hashing with configurable cost (default 12)
|
||||
fn generate_htpasswd(user string, password string) !string {
|
||||
|
||||
|
||||
// Generate bcrypt hash
|
||||
hashed_password := bcrypt.generate_from_password(password.bytes(), 12) or {
|
||||
return error('Failed to hash password: ${err}')
|
||||
@@ -16,4 +14,4 @@ fn generate_htpasswd(user string, password string) !string {
|
||||
|
||||
// Return final formatted string
|
||||
return '${user}:${hashed_password}'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,125 +3,110 @@ module traefik
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
|
||||
|
||||
import os
|
||||
|
||||
fn startupcmd () ![]zinit.ZProcessNewArgs{
|
||||
mut installer := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'traefik'
|
||||
cmd: 'traefik'
|
||||
}
|
||||
fn startupcmd() ![]zinit.ZProcessNewArgs {
|
||||
mut installer := get()!
|
||||
mut res := []zinit.ZProcessNewArgs{}
|
||||
res << zinit.ZProcessNewArgs{
|
||||
name: 'traefik'
|
||||
cmd: 'traefik'
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
fn running() !bool {
|
||||
cmd:="traefik healthcheck"
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
cmd := 'traefik healthcheck'
|
||||
res := os.execute(cmd)
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fn start_pre()!{
|
||||
|
||||
fn start_pre() ! {
|
||||
}
|
||||
|
||||
fn start_post()!{
|
||||
|
||||
fn start_post() ! {
|
||||
}
|
||||
|
||||
fn stop_pre()!{
|
||||
|
||||
fn stop_pre() ! {
|
||||
}
|
||||
|
||||
fn stop_post()!{
|
||||
|
||||
fn stop_post() ! {
|
||||
}
|
||||
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed() !bool {
|
||||
res := os.execute('${osal.profile_path_source_and()!} traefik version')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.contains("Version"))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse traefik version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after("Version:")) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
res := os.execute('${osal.profile_path_source_and()!} traefik version')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
r := res.output.split_into_lines().filter(it.contains('Version'))
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse traefik version.\n${res.output}")
|
||||
}
|
||||
if texttools.version(version) == texttools.version(r[0].all_after('Version:')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//get the Upload List of the files
|
||||
// get the Upload List of the files
|
||||
fn ulist_get() !ulist.UList {
|
||||
return ulist.UList{}
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn upload() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'traefik'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/traefik'
|
||||
// )!
|
||||
|
||||
// installers.upload(
|
||||
// cmdname: 'traefik'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/traefik'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install() ! {
|
||||
console.print_header('install traefik')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_linux_arm64.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_linux_amd64.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_darwin_arm64.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_darwin_arm64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
console.print_header('install traefik')
|
||||
mut url := ''
|
||||
if core.is_linux_arm()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_linux_arm64.tar.gz'
|
||||
} else if core.is_linux_intel()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_linux_amd64.tar.gz'
|
||||
} else if core.is_osx_arm()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_darwin_arm64.tar.gz'
|
||||
} else if core.is_osx_intel()! {
|
||||
url = 'https://github.com/traefik/traefik/releases/download/v${version}/traefik_v${version}_darwin_arm64.tar.gz'
|
||||
} else {
|
||||
return error('unsported platform')
|
||||
}
|
||||
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 20000
|
||||
expand_dir: '/tmp/traefik'
|
||||
)!
|
||||
mut dest := osal.download(
|
||||
url: url
|
||||
minsize_kb: 20000
|
||||
expand_dir: '/tmp/traefik'
|
||||
)!
|
||||
|
||||
mut binpath := dest.file_get('traefik')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'traefik'
|
||||
source: binpath.path
|
||||
)!
|
||||
mut binpath := dest.file_get('traefik')!
|
||||
osal.cmd_add(
|
||||
cmdname: 'traefik'
|
||||
source: binpath.path
|
||||
)!
|
||||
}
|
||||
|
||||
|
||||
fn destroy() ! {
|
||||
osal.process_kill_recursive(name: 'traefik')!
|
||||
osal.cmd_delete('traefik')!
|
||||
|
||||
osal.process_kill_recursive(name:'traefik')!
|
||||
osal.cmd_delete('traefik')!
|
||||
|
||||
osal.package_remove('
|
||||
osal.package_remove('
|
||||
traefik
|
||||
')!
|
||||
|
||||
osal.rm("
|
||||
osal.rm('
|
||||
traefik
|
||||
")!
|
||||
|
||||
|
||||
')!
|
||||
}
|
||||
|
||||
|
||||
@@ -4,284 +4,272 @@ import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
traefik_global map[string]&TraefikServer
|
||||
traefik_default string
|
||||
traefik_global map[string]&TraefikServer
|
||||
traefik_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet{
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get (args_ ArgsGet) ArgsGet {
|
||||
mut args:=args_
|
||||
if args.name == ""{
|
||||
args.name = "default"
|
||||
}
|
||||
return args
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&TraefikServer {
|
||||
mut context:=base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := TraefikServer{}
|
||||
if !(args.name in traefik_global) {
|
||||
if ! exists(args)!{
|
||||
set(obj)!
|
||||
}else{
|
||||
heroscript := context.hero_config_get("traefik",args.name)!
|
||||
mut obj_:=heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return traefik_global[args.name] or {
|
||||
println(traefik_global)
|
||||
//bug if we get here because should be in globals
|
||||
panic("could not get config for traefik with name, is bug:${args.name}")
|
||||
}
|
||||
pub fn get(args_ ArgsGet) !&TraefikServer {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := TraefikServer{}
|
||||
if args.name !in traefik_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('traefik', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return traefik_global[args.name] or {
|
||||
println(traefik_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for traefik with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
//register the config for the future
|
||||
pub fn set(o TraefikServer)! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set("traefik", o.name, heroscript)!
|
||||
// register the config for the future
|
||||
pub fn set(o TraefikServer) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('traefik', o.name, heroscript)!
|
||||
}
|
||||
|
||||
//does the config exists?
|
||||
pub fn exists(args_ ArgsGet)! bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists("traefik", args.name)
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('traefik', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet)! {
|
||||
mut args := args_get(args_)
|
||||
mut context:=base.context()!
|
||||
context.hero_config_delete("traefik",args.name)!
|
||||
if args.name in traefik_global {
|
||||
//del traefik_global[args.name]
|
||||
}
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('traefik', args.name)!
|
||||
if args.name in traefik_global {
|
||||
// del traefik_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
//only sets in mem, does not set as config
|
||||
fn set_in_mem(o TraefikServer)! {
|
||||
mut o2:=obj_init(o)!
|
||||
traefik_global[o.name] = &o2
|
||||
traefik_default = o.name
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o TraefikServer) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
traefik_global[o.name] = &o2
|
||||
traefik_default = o.name
|
||||
}
|
||||
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string //if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
}
|
||||
|
||||
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 {
|
||||
playbook.new(text: args.heroscript)!
|
||||
}
|
||||
|
||||
mut install_actions := plbook.find(filter: 'traefik.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript:=install_action.heroscript()
|
||||
mut obj2:=heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
mut install_actions := plbook.find(filter: 'traefik.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
|
||||
mut other_actions := plbook.find(filter: 'traefik.')!
|
||||
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 traefik.destroy")
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == "install"{
|
||||
console.print_debug("install action traefik.install")
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ["start","stop","restart"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut traefik_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n${traefik_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action traefik.${other_action.name}")
|
||||
traefik_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action traefik.${other_action.name}")
|
||||
traefik_obj.stop()!
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action traefik.${other_action.name}")
|
||||
traefik_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'traefik.')!
|
||||
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 traefik.destroy')
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action traefik.install')
|
||||
install()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut traefik_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${traefik_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action traefik.${other_action.name}')
|
||||
traefik_obj.start()!
|
||||
}
|
||||
|
||||
if other_action.name == 'stop' {
|
||||
console.print_debug('install action traefik.${other_action.name}')
|
||||
traefik_obj.stop()!
|
||||
}
|
||||
if other_action.name == 'restart' {
|
||||
console.print_debug('install action traefik.${other_action.name}')
|
||||
traefik_obj.restart()!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////# 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()!
|
||||
}
|
||||
}
|
||||
// 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()!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load from disk and make sure is properly intialized
|
||||
// load from disk and make sure is properly intialized
|
||||
pub fn (mut self TraefikServer) reload() ! {
|
||||
switch(self.name)
|
||||
self=obj_init(self)!
|
||||
switch(self.name)
|
||||
self = obj_init(self)!
|
||||
}
|
||||
|
||||
pub fn (mut self TraefikServer) start() ! {
|
||||
switch(self.name)
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
switch(self.name)
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
|
||||
console.print_header('traefik start')
|
||||
console.print_header('traefik start')
|
||||
|
||||
if ! installed()!{
|
||||
install()!
|
||||
}
|
||||
if !installed()! {
|
||||
install()!
|
||||
}
|
||||
|
||||
configure()!
|
||||
configure()!
|
||||
|
||||
start_pre()!
|
||||
start_pre()!
|
||||
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
for zprocess in startupcmd()! {
|
||||
mut sm := startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('starting traefik with ${zprocess.startuptype}...')
|
||||
console.print_debug('starting traefik with ${zprocess.startuptype}...')
|
||||
|
||||
sm.new(zprocess)!
|
||||
sm.new(zprocess)!
|
||||
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
sm.start(zprocess.name)!
|
||||
}
|
||||
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('traefik did not install properly.')
|
||||
start_post()!
|
||||
|
||||
for _ in 0 .. 50 {
|
||||
if self.running()! {
|
||||
return
|
||||
}
|
||||
time.sleep(100 * time.millisecond)
|
||||
}
|
||||
return error('traefik did not install properly.')
|
||||
}
|
||||
|
||||
pub fn (mut self TraefikServer) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self TraefikServer) stop() ! {
|
||||
switch(self.name)
|
||||
stop_pre()!
|
||||
for zprocess in startupcmd()!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
sm.stop(zprocess.name)!
|
||||
}
|
||||
stop_post()!
|
||||
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 TraefikServer) restart() ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
}
|
||||
|
||||
pub fn (mut self TraefikServer) running() !bool {
|
||||
switch(self.name)
|
||||
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()!
|
||||
// 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 struct InstallArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
reset bool
|
||||
}
|
||||
|
||||
pub fn (mut self TraefikServer) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
switch(self.name)
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut self TraefikServer) destroy() ! {
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
switch(self.name)
|
||||
self.stop() or {}
|
||||
destroy()!
|
||||
}
|
||||
|
||||
|
||||
|
||||
//switch instance to be used for traefik
|
||||
// switch instance to be used for traefik
|
||||
pub fn switch(name string) {
|
||||
traefik_default = name
|
||||
traefik_default = name
|
||||
}
|
||||
|
||||
|
||||
//helpers
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs{
|
||||
instance string = 'default'
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
module traefik
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
@@ -9,46 +10,43 @@ pub const version = '3.3.3'
|
||||
const singleton = true
|
||||
const default = true
|
||||
|
||||
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
@[heap]
|
||||
pub struct TraefikServer {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
// homedir string
|
||||
// configpath string
|
||||
// username string
|
||||
password string @[secret]
|
||||
// title string
|
||||
// host string
|
||||
// port int
|
||||
name string = 'default'
|
||||
// homedir string
|
||||
// configpath string
|
||||
// username string
|
||||
password string @[secret]
|
||||
// title string
|
||||
// host string
|
||||
// port int
|
||||
}
|
||||
|
||||
|
||||
|
||||
//your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ TraefikServer)!TraefikServer{
|
||||
mut mycfg:=mycfg_
|
||||
return mycfg
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ TraefikServer) !TraefikServer {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
//called before start if done
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
mut installer := get()!
|
||||
htaccesscode:=generate_htpasswd("admin",installer.password)!
|
||||
mut mycode := $tmpl('templates/traefik.toml')
|
||||
mut path := pathlib.get_file(path: "/etc/traefik/traefik.toml", create: true)!
|
||||
path.write(mycode)!
|
||||
console.print_debug(mycode)
|
||||
mut installer := get()!
|
||||
htaccesscode := generate_htpasswd('admin', installer.password)!
|
||||
mut mycode := $tmpl('templates/traefik.toml')
|
||||
mut path := pathlib.get_file(path: '/etc/traefik/traefik.toml', create: true)!
|
||||
path.write(mycode)!
|
||||
console.print_debug(mycode)
|
||||
}
|
||||
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj TraefikServer) !string {
|
||||
return encoderhero.encode[TraefikServer ](obj)!
|
||||
return encoderhero.encode[TraefikServer](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !TraefikServer {
|
||||
mut obj := encoderhero.decode[TraefikServer](heroscript)!
|
||||
return obj
|
||||
mut obj := encoderhero.decode[TraefikServer](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user