fix: improve package management and screen status
- Fix issues in package installation and removal across different platforms (Ubuntu, macOS, Alpine, Arch). - Improve error handling and add sudo support where necessary. - Enhance screen status check to accurately reflect process activity. - Address minor bugs in `db.v`, `done.v`, and `net_test.v`. - Correct minor inconsistencies in package names.
This commit is contained in:
@@ -47,35 +47,39 @@ pub enum ScreenStatus {
|
||||
|
||||
// Method to check the status of a screen process
|
||||
pub fn (self Screen) status() !ScreenStatus {
|
||||
panic('implement')
|
||||
// // Command to list screen sessions
|
||||
// cmd := 'screen -ls'
|
||||
// response := osal.execute_silent(cmd)!
|
||||
// Command to list screen sessions
|
||||
cmd := 'screen -ls'
|
||||
response := osal.execute_silent(cmd)!
|
||||
|
||||
// // Check if the screen session exists
|
||||
// if !response.contains(self.name) {
|
||||
// return .inactive
|
||||
// }
|
||||
// Check if the screen session exists by looking for the session name in the output
|
||||
if !response.contains(self.name) {
|
||||
return .inactive
|
||||
}
|
||||
|
||||
// // Command to send a dummy command to the screen session and check response
|
||||
// cmd_check := 'screen -S ${self.name} -X eval "stuff \\"\\003\\"; sleep 0.1; stuff \\"ps\\n\\""'
|
||||
// osal.execute_silent(cmd_check)!
|
||||
// Command to send a dummy command to the screen session and check response
|
||||
cmd_check := "screen -S ${self.name} -X eval \"stuff \\\"\\003\\\"; sleep 0.1; stuff \\\"ps\\n\\\"\""
|
||||
osal.execute_silent(cmd_check)!
|
||||
|
||||
// // Check if the process is running in the screen session
|
||||
// cmd_ps := 'screen -S ${self.name} -X hardcopy -h /tmp/screen_output; cat /tmp/screen_output | grep "${self.name}"'
|
||||
// ps_response := osal.execute_silent(cmd_ps)!
|
||||
// Command to check if there is an active process in the screen session
|
||||
cmd_ps := 'screen -S ${self.name} -X hardcopy -h /tmp/screen_output; cat /tmp/screen_output'
|
||||
ps_response := osal.execute_silent(cmd_ps)!
|
||||
|
||||
// return parse_screen_process_status(ps_response)
|
||||
// Parse the response and determine if there's an active process
|
||||
return parse_screen_process_status(ps_response)
|
||||
}
|
||||
|
||||
// Function to parse screen process status output
|
||||
// Function to parse the screen process status output
|
||||
fn parse_screen_process_status(output string) ScreenStatus {
|
||||
lines := output.split_into_lines()
|
||||
|
||||
// Check the output for active processes
|
||||
for line in lines {
|
||||
if line.contains('SCREEN') || line.contains('PID') {
|
||||
return .active
|
||||
}
|
||||
}
|
||||
|
||||
// If no active process is found, return inactive
|
||||
return .inactive
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn testsuite_begin() ! {
|
||||
|
||||
pub fn test_screen_status() ! {
|
||||
mut screen_factory := new()!
|
||||
mut screen := screen_factory.add(name: 'testservice', cmd: 'redis-server')!
|
||||
mut screen := screen_factory.add(name: 'testservice', cmd: 'redis-server --port 1234')!
|
||||
status := screen.status()!
|
||||
// assert status == .active
|
||||
assert status == .active
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user