feat: Add reset functionality to startup commands
- Add `reset` boolean parameter to `StartArgs` struct - Pass `reset` parameter to `startupcmd` calls - Update service creation logic to handle `reset` flag - Modify `install_start` and `restart` to pass `reset` parameter
This commit is contained in:
@@ -113,7 +113,11 @@ fn (mut m ModuleMeta) check() ! {
|
||||
}
|
||||
mut module_path := m.path.replace('/', '.')
|
||||
if module_path.contains('incubaid.herolib.lib.') {
|
||||
// Path is inside lib/ directory (e.g., lib/installers/horus/coordinator)
|
||||
module_path = module_path.split('incubaid.herolib.lib.')[1]
|
||||
} else if module_path.contains('incubaid.herolib.') {
|
||||
// Path is directly under herolib root (e.g., zeko)
|
||||
module_path = module_path.split('incubaid.herolib.')[1]
|
||||
} else {
|
||||
return error('path should be inside incubaid.herolib, so that module_path can be determined, now is: ${m.path}')
|
||||
}
|
||||
|
||||
@@ -20,19 +20,29 @@ import incubaid.herolib.installers.lang.python
|
||||
import os
|
||||
|
||||
@if args.startupmanager
|
||||
fn (self &${args.classname}) startupcmd() ![]startupmanager.ZProcessNewArgs {
|
||||
^^[params]
|
||||
pub struct StartArgs {
|
||||
pub mut:
|
||||
reset bool
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) startupcmd(args StartArgs) ![]startupmanager.ZProcessNewArgs {
|
||||
mut res := []startupmanager.ZProcessNewArgs{}
|
||||
|
||||
reset := args.reset
|
||||
|
||||
//THIS IS EXAMPLE CODEAND NEEDS TO BE CHANGED
|
||||
// res << startupmanager.ZProcessNewArgs{
|
||||
// name: '${args.name}'
|
||||
// cmd: '${args.name} server'
|
||||
// reset: reset
|
||||
// env: {
|
||||
// 'HOME': '/root'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return res
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) running_check() !bool {
|
||||
@@ -57,21 +67,20 @@ fn (self &${args.classname}) running_check() !bool {
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) start_pre() ! {
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) start_post() ! {
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) stop_pre() ! {
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn (self &${args.classname}) stop_post() ! {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
@@ -195,7 +195,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
@if args.startupmanager
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
${args.name}_obj.start()!
|
||||
${args.name}_obj.start(reset: reset)!
|
||||
}
|
||||
if other_action.name == "stop"{
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
@@ -203,7 +203,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
if other_action.name == "restart"{
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
${args.name}_obj.restart()!
|
||||
${args.name}_obj.restart(reset: reset)!
|
||||
}
|
||||
if other_action.name == "start_pre"{
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
@@ -273,10 +273,11 @@ pub fn (mut self ${args.classname}) reload() ! {
|
||||
@end
|
||||
|
||||
@if args.startupmanager
|
||||
pub fn (mut self ${args.classname}) start() ! {
|
||||
pub fn (mut self ${args.classname}) start(args StartArgs) ! {
|
||||
@if ! args.singleton
|
||||
switch(self.name)
|
||||
@end
|
||||
|
||||
if self.running()!{
|
||||
return
|
||||
}
|
||||
@@ -289,7 +290,7 @@ pub fn (mut self ${args.classname}) start() ! {
|
||||
|
||||
self.start_pre()!
|
||||
|
||||
for zprocess in self.startupcmd()!{
|
||||
for zprocess in self.startupcmd(args)!{
|
||||
mut sm:=startupmanager_get(zprocess.startuptype)!
|
||||
|
||||
console.print_debug('installer: ${args.name} starting with ??{zprocess.startuptype}...')
|
||||
@@ -314,7 +315,7 @@ pub fn (mut self ${args.classname}) start() ! {
|
||||
pub fn (mut self ${args.classname}) install_start(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
self.install(args)!
|
||||
self.start()!
|
||||
self.start(reset: false)!
|
||||
}
|
||||
|
||||
pub fn (mut self ${args.classname}) stop() ! {
|
||||
@@ -327,10 +328,10 @@ pub fn (mut self ${args.classname}) stop() ! {
|
||||
self.stop_post()!
|
||||
}
|
||||
|
||||
pub fn (mut self ${args.classname}) restart() ! {
|
||||
pub fn (mut self ${args.classname}) restart(args StartArgs) ! {
|
||||
switch(self.name)
|
||||
self.stop()!
|
||||
self.start()!
|
||||
self.start(args)!
|
||||
}
|
||||
|
||||
pub fn (mut self ${args.classname}) running() !bool {
|
||||
|
||||
@@ -71,12 +71,20 @@ fn cmd_generator_execute(cmd Command) ! {
|
||||
// Handle "." as current working directory
|
||||
if path == '.' {
|
||||
path = os.getwd()
|
||||
} else {
|
||||
} else if path != '' {
|
||||
// Expand home directory
|
||||
path = path.replace('~', os.home_dir())
|
||||
|
||||
// Convert relative paths to absolute paths
|
||||
if !os.is_abs_path(path) {
|
||||
path = os.join_path(os.getwd(), path)
|
||||
}
|
||||
|
||||
// Resolve to real path (handles symlinks and normalizes path)
|
||||
path = os.real_path(path)
|
||||
|
||||
// Validate that path exists
|
||||
if path != '' && !os.exists(path) {
|
||||
if !os.exists(path) {
|
||||
return error('Path does not exist: ${path}')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user