Skip to content

Commit 5f509bd

Browse files
resove conflict
1 parent 78ebcae commit 5f509bd

File tree

3 files changed

+47
-66
lines changed

3 files changed

+47
-66
lines changed

tests/acceptance/features/cliCommands/backupConsistency.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@env-config @backup-consistency
1+
@env-config
22
Feature: backup consistency
33
As a user
44
I want to check my data for inconsistencies

tests/ociswrapper/ocis/ocis.go

+45-64
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10-
"ociswrapper/common"
11-
"ociswrapper/log"
12-
"ociswrapper/ocis/config"
1310
"os"
1411
"os/exec"
1512
"strconv"
@@ -18,48 +15,56 @@ import (
1815
"syscall"
1916
"time"
2017

18+
"ociswrapper/common"
19+
"ociswrapper/log"
20+
"ociswrapper/ocis/config"
21+
2122
"github.com/creack/pty"
2223
)
2324

2425
var cmd *exec.Cmd
2526
var retryCount = 0
2627
var stopSignal = false
2728
var EnvConfigs = []string{}
28-
var runningCommands = make(map[string]int) // Maps unique IDs to PIDs
29+
var runningServices = make(map[string]int)
2930

3031
func Start(envMap []string) {
31-
StartService("", envMap)
32+
StartService("", envMap)
3233
}
3334

3435
func Stop() (bool, string) {
35-
log.Println(fmt.Sprintf("Stop ocis check cmd %s\n", cmd))
3636
log.Println("Stopping oCIS server...")
3737
stopSignal = true
3838

39-
for listservice, pid := range runningCommands {
40-
log.Println(fmt.Sprintf("Services running before terminating: %s with process and id: %v\n", listservice, pid))
41-
process, err := os.FindProcess(pid)
42-
err = process.Signal(syscall.SIGINT)
43-
if err != nil {
44-
if !strings.HasSuffix(err.Error(), "process already finished") {
45-
log.Fatalln(err)
46-
} else {
47-
return true, "oCIS server is already stopped"
48-
}
49-
}
50-
process.Wait()
39+
for listservice, pid := range runningServices {
40+
process, err := os.FindProcess(pid)
41+
if err != nil {
42+
log.Println(fmt.Sprintf("Error finding process for service %s: %v", listservice, err))
43+
continue
44+
}
45+
pKillError := process.Signal(syscall.SIGINT)
46+
if pKillError != nil {
47+
if !strings.HasSuffix(pKillError.Error(), "process already finished") {
48+
log.Fatalln(pKillError)
49+
} else {
50+
return true, "oCIS server is already stopped"
51+
}
52+
}
53+
_, waitErr := process.Wait()
54+
if waitErr != nil {
55+
log.Println(fmt.Sprintf("Error waiting for process to exit: %v\n", waitErr))
56+
}
57+
delete(runningServices, "ocis")
5158
}
5259

53-
cmd = nil
5460
success, message := waitUntilCompleteShutdown()
61+
62+
cmd = nil
5563
return success, message
5664
}
5765

5866
func Restart(envMap []string) (bool, string) {
59-
log.Println(fmt.Sprintf("Restarting ocis check cmd %s\n", cmd))
60-
log.Println(fmt.Sprintf("Restaring ocis with rollback os environ %s\n", envMap))
61-
log.Println(fmt.Sprintf("OS environment: %s\n", os.Environ()))
62-
go Stop()
67+
Stop()
6368

6469
log.Println("Restarting oCIS server...")
6570
common.Wg.Add(1)
@@ -69,8 +74,8 @@ func Restart(envMap []string) (bool, string) {
6974
}
7075

7176
func IsOcisRunning() bool {
72-
if runningCommands["ocis"] > 0 {
73-
return true
77+
if runningServices["ocis"] > 0 {
78+
return true
7479
}
7580
return false
7681
}
@@ -136,7 +141,6 @@ func WaitForConnection() (bool, string) {
136141
}
137142

138143
func waitUntilCompleteShutdown() (bool, string) {
139-
log.Println("Process found. Waiting... waitUntilCompleteShutdown")
140144
timeout := 30 * time.Second
141145
startTime := time.Now()
142146

@@ -207,11 +211,9 @@ func StartService(service string, envMap []string) {
207211
cmdArgs := []string{"server"} // Default command args
208212

209213
if service != "" {
210-
// Directly append service if provided
211214
cmdArgs = append([]string{service}, cmdArgs...)
212215
}
213216

214-
// wait for the log scanner to finish
215217
var wg sync.WaitGroup
216218
wg.Add(2)
217219

@@ -220,18 +222,12 @@ func StartService(service string, envMap []string) {
220222
defer common.Wg.Done()
221223
}
222224

223-
// Initialize the command
224225
cmd = exec.Command(config.Get("bin"), cmdArgs...)
225226

226-
// Use the provided envMap if not empty, otherwise use EnvConfigs
227227
if len(envMap) == 0 {
228228
cmd.Env = append(os.Environ(), EnvConfigs...)
229-
log.Println(fmt.Sprintf("OS environment variables while running ocis service: %s\n", cmd.Env))
230-
log.Println(fmt.Sprintf("OS environment: %s\n", os.Environ()))
231229
} else {
232230
cmd.Env = append(os.Environ(), envMap...)
233-
log.Println(fmt.Sprintf("OS environment variables while running ocis service: %s\n", cmd.Env))
234-
log.Println(fmt.Sprintf("OS environment: %s\n", os.Environ()))
235231
}
236232

237233
logs, err := cmd.StderrPipe()
@@ -243,9 +239,6 @@ func StartService(service string, envMap []string) {
243239
log.Panic(err)
244240
}
245241

246-
// log.Println(fmt.Sprintf("command env used to start service %s\n", cmd.Env))
247-
// log.Println(fmt.Sprintf("command used to start service %s\n", cmd))
248-
249242
err = cmd.Start()
250243

251244
if err != nil {
@@ -256,17 +249,14 @@ func StartService(service string, envMap []string) {
256249
outputScanner := bufio.NewScanner(output)
257250
outChan := make(chan string)
258251

259-
// If service is an empty string, set the PID for "ocis"
260252
if service == "" {
261-
runningCommands["ocis"] = cmd.Process.Pid
253+
runningServices["ocis"] = cmd.Process.Pid
262254
} else {
263-
runningCommands[service] = cmd.Process.Pid
255+
runningServices[service] = cmd.Process.Pid
264256
}
265257

266-
log.Println("Started oCIS processes:")
267-
for listservice, pid := range runningCommands {
258+
for listservice, pid := range runningServices {
268259
log.Println(fmt.Sprintf("Service started: %s with process and id: %v\n", listservice, pid))
269-
270260
}
271261

272262
// Read the logs when the 'ocis server' command is running
@@ -316,45 +306,36 @@ func StartService(service string, envMap []string) {
316306
}
317307
}
318308
}
319-
320-
log.Println(fmt.Sprintf(" ---- ocis start service ending line---- %s\n", cmd))
321309
wg.Wait()
322310
close(outChan)
323311
}
324312

325313
// Stop oCIS service or a specific service by its unique identifier
326314
func StopService(service string) (bool, string) {
327-
for listservice, pid := range runningCommands {
328-
log.Println(fmt.Sprintf("Services running before terminating: %s with process and id: %v\n", listservice, pid))
329-
}
330-
331-
pid, exists := runningCommands[service]
332-
log.Println(fmt.Sprintf("Services process id to terminate: %s\n", pid))
315+
pid, exists := runningServices[service]
333316
if !exists {
334317
return false, fmt.Sprintf("Service %s is not running", service)
335318
}
336319

337320
// Find the process by PID and send SIGINT to stop it
338321
process, err := os.FindProcess(pid)
339-
log.Println(fmt.Sprintf("Found process to terminate in os: %s\n", pid))
340-
341322
if err != nil {
342-
log.Println(fmt.Sprintf("Failed to find process: %v", err))
343323
return false, fmt.Sprintf("Failed to find process with ID %d", pid)
344324
}
345325

346-
err = process.Signal(syscall.SIGINT)
347-
log.Println("Process terminated using signal")
348-
if err != nil {
349-
log.Println(fmt.Sprintf("Failed to send signal: %v", err))
326+
pterr := process.Signal(syscall.SIGINT)
327+
if pterr != nil {
350328
return false, fmt.Sprintf("Failed to stop service with PID %d", pid)
351329
}
330+
352331
time.Sleep(30 * time.Second)
353-
process.Wait()
354-
log.Println("Process terminating process.wait")
355-
delete(runningCommands, service)
356-
for listservice, pid := range runningCommands {
357-
log.Println(fmt.Sprintf("Service list after deleteing %s service. list contain service: %s with process and id: %v\n", service, listservice, pid))
358-
}
332+
_, waitErr := process.Wait()
333+
if waitErr != nil {
334+
log.Println(fmt.Sprintf("Error waiting for process to exit: %v\n", waitErr))
335+
}
336+
337+
log.Println(fmt.Sprintf("Service %s process %v terminated", service, pid))
338+
delete(runningServices, service)
339+
359340
return true, fmt.Sprintf("Service %s stopped successfully", service)
360341
}

tests/ociswrapper/wrapper/handlers/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func RollbackHandler(res http.ResponseWriter, req *http.Request) {
115115

116116
var message string
117117
ocis.EnvConfigs = []string{}
118-
log.Printf(fmt.Sprintf("os Environ when rollback %s", os.Environ))
118+
119119
success, _ := ocis.Restart(ocis.EnvConfigs)
120120
if success {
121121
message = "oCIS configuration rolled back successfully"

0 commit comments

Comments
 (0)